Skip to content

Commit

Permalink
fix(commands): Fixed cy.getTenantId reading tenant from undefined (#154)
Browse files Browse the repository at this point in the history
`cy.getTenantId()` threw an error `undefined (reading 'tenant')` after `cy.login()`. This has been related to authorization cookies being found in the environment and is now fixed.

Closes #153
  • Loading branch information
thomaswinkler authored Sep 6, 2024
1 parent 6d68f77 commit 77b8595
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/commands/administration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ Cypress.Commands.add("getTenantId", { prevSubject: "optional" }, (...args) => {
consoleProps: () => consoleProps,
});

if (Cypress.env("C8Y_TENANT") && !auth.tenant) {
if (Cypress.env("C8Y_TENANT") && !auth?.tenant) {
consoleProps.C8Y_TENANT = Cypress.env("C8Y_TENANT");
return cy.wrap<string>(Cypress.env("C8Y_TENANT"));
}
Expand Down
11 changes: 11 additions & 0 deletions test/cypress/e2e/administration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,17 @@ describe("administration", () => {
});
});

it("should not fail for CookieAuth", function () {
cy.setCookie("XSRF-TOKEN", "123");
cy.setCookie("authorization", "213412")

stubEnv({ C8Y_USERNAME: "admin", C8Y_PASSWORD: "mypassword", C8Y_TENANT: "t1234"});
cy.getTenantId().then((id) => {
expect(id).to.eq("t1234");
expect(window.fetchStub.callCount).to.equal(0);
});
});

it("should use tenant id from pact recording when mocking", function () {
stubEnv({ C8Y_PACT_MODE: "mock", C8Y_PLUGIN_LOADED: "true" });
Cypress.c8ypact.current = new C8yDefaultPact(
Expand Down

0 comments on commit 77b8595

Please sign in to comment.