Skip to content

Commit

Permalink
tests: add tests for slow and error responses from user and statuspage (
Browse files Browse the repository at this point in the history
  • Loading branch information
ciyer committed Oct 30, 2023
1 parent e4b288b commit 66c4001
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
35 changes: 14 additions & 21 deletions tests/cypress/e2e/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,25 @@ describe("404 page", () => {
});
});

describe("display the maintenance page", () => {
describe("display the home page even when APIs return strange responses", () => {
beforeEach(() => {
new Fixtures(cy).config().versions();
});

it("displays an error when trying to get status page information", () => {
// ! we plan to change this behavior and ignore statuspage info when unavailable #2283
new Fixtures(cy).renkuDown();
new Fixtures(cy)
.config()
.versions()
.statuspageDown()
.userNone(undefined, 1000);
cy.visit("/");
cy.get("h1").should("have.length", 1);
cy.get("h1").contains("RenkuLab Down").should("be.visible");
cy.get(".alert-content")
.contains("Could not retrieve status information")
.should("be.visible");
});

it("displays status page information", () => {
// if the call to get the user fails (e.g., no .userNone() fixture)
// then show the status page
new Fixtures(cy).getStatuspageInfo();
cy.visit("/");
cy.wait("@getStatuspageInfo");
it("displays the home page intro text", () => {
cy.wait("@getUser");
cy.get("h1").should("have.length", 1);
cy.get("h1").contains("RenkuLab Down").should("be.visible");
cy.get("h3").contains("RenkuLab Status").should("be.visible");
cy.get("h4").contains("Scheduled Maintenance Details").should("be.visible");
cy.get("h1")
.first()
.should(
"have.text",
"An open-source knowledge infrastructure for collaborative and reproducible data science"
);
});
});

Expand Down
1 change: 0 additions & 1 deletion tests/cypress/e2e/maintenance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe("display the maintenance page when there is no user response", () => {
});

it("displays an error when trying to get status page information", () => {
// ! we plan to change this behavior and ignore statuspage info when unavailable #2283
new Fixtures(cy).renkuDown().statuspageDown();
cy.visit("/");
cy.get("h1").should("have.length", 1);
Expand Down
12 changes: 10 additions & 2 deletions tests/cypress/support/renkulab-fixtures/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import { FixturesConstructor } from "./fixtures";
function Global<T extends FixturesConstructor>(Parent: T) {
return class NewSessionFixtures extends Parent {
getStatuspageInfo({
name = "getStatuspageInfo",
fixture = "statuspage-operational.json",
name = "getStatuspageInfo",
overrides,
}: {
name?: string;
fixture?: string;
name?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
overrides?: any;
} = {}) {
Expand All @@ -51,6 +51,14 @@ function Global<T extends FixturesConstructor>(Parent: T) {
return this;
}

statuspageDown(name = "getStatuspageInfo") {
cy.intercept("https://*.statuspage.io/api/v2/summary.jsonr", {
statusCode: 500,
body: {},
}).as(name);
return this;
}

config(params?: {
name?: string;
fixture?: string;
Expand Down
6 changes: 5 additions & 1 deletion tests/cypress/support/renkulab-fixtures/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ function User<T extends FixturesConstructor>(Parent: T) {
return this;
}

userNone(names = { user: "getUser", keycloakUser: "getKeycloakUser" }) {
userNone(
names = { user: "getUser", keycloakUser: "getKeycloakUser" },
delay = undefined
) {
cy.intercept("/ui-server/api/user", {
delay: delay,
statusCode: 401,
body: {},
}).as(names.user);
Expand Down

0 comments on commit 66c4001

Please sign in to comment.