Skip to content

Commit

Permalink
test: allow usage of CYPRESS_BASE_URL to run tests on deployed webapps
Browse files Browse the repository at this point in the history
  • Loading branch information
csm-thu committed Jan 24, 2025
1 parent ebaa8d8 commit 338546a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 8 additions & 2 deletions cypress/commons/actions/generic/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ function login(options) {
if (auth.USE_API_KEY) return;

cy.getAllLocalStorage().then((localStorage) => {
expect(localStorage[BASE_URL].authProvider).not.to.eq(undefined);
expect(localStorage[BASE_URL].authAccessToken).not.to.eq(undefined);
// Can't use `Cypress.config('baseUrl')` below, because when deployed, the webapp base URL can include
// a subpath after the domain name (e.g. "/cosmotech-webapp/brewery"), that is not present in the local
// storage key
// Use location.host instead of hostname to also get the port number (e.g. localhost:3000), it is
// necessary when the webapp runs locally
const baseUrl = `${window.location.protocol}//${window.location.host}`;
expect(localStorage[baseUrl].authProvider).not.to.eq(undefined);
expect(localStorage[baseUrl].authAccessToken).not.to.eq(undefined);
});
},
}
Expand Down
3 changes: 1 addition & 2 deletions cypress/commons/constants/generic/TestConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export { ORGANIZATION_ID } from '../../../../src/config/GlobalConfiguration';
export const URL_ROOT = 'https://dev.api.cosmotech.com';
export const AUTH_QUERY_URL =
'https://login.microsoftonline.com/e413b834-8be8-4822-a370-be619545cb49/oauth2/v2.0/token';
export const LOCAL_WEBAPP_URL = 'http://localhost:3000';
export const URL_POWERBI = `${LOCAL_WEBAPP_URL}/api/get-embed-info`;
export const GET_EMBED_INFO_ENDPOINT = '/api/get-embed-info';

export const PAGE_NAME = {
SCENARIO: '/scenario',
Expand Down
12 changes: 10 additions & 2 deletions cypress/commons/utils/apiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
SCENARIO_EXAMPLE,
SCENARIO_RUN_EXAMPLE,
} from '../../fixtures/stubbing/default';
import { API_ENDPOINT, API_REGEX, AUTH_QUERY_URL, URL_POWERBI, URL_ROOT } from '../constants/generic/TestConstants';
import {
API_ENDPOINT,
API_REGEX,
AUTH_QUERY_URL,
GET_EMBED_INFO_ENDPOINT,
URL_ROOT,
} from '../constants/generic/TestConstants';
import { stub } from '../services/stubbing';
import { authUtils } from './authUtils';
import { fileUtils } from './fileUtils';
Expand Down Expand Up @@ -745,7 +751,9 @@ const interceptGetSolution = (solutionId) => {
const interceptPowerBIAzureFunction = () => {
if (authUtils.USE_API_KEY) return;
const alias = forgeAlias('reqPowerBI');
cy.intercept('POST', URL_POWERBI, { statusCode: 200 }).as(alias);
const baseUrl = Cypress.config('baseUrl');
const interceptUrl = `${baseUrl}${GET_EMBED_INFO_ENDPOINT}`;
cy.intercept('POST', interceptUrl, { statusCode: 200 }).as(alias);
return alias;
};

Expand Down

0 comments on commit 338546a

Please sign in to comment.