-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(login command): update login command and use it in setup
- Loading branch information
Showing
3 changed files
with
14 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,16 @@ | ||
/* globals before */ | ||
import { LOGIN_ENDPOINT } from '../constants' | ||
|
||
export const enableAutoLogin = () => { | ||
// This will authenticate and set the session cookie | ||
const username = Cypress.env('dhis2_username') | ||
const password = Cypress.env('dhis2_password') | ||
const loginUrl = Cypress.env('dhis2_base_url') | ||
|
||
if (!loginUrl) { | ||
throw new Error( | ||
'No `dhis2_base_url` found. Please make sure to add it to `cypress.env.json`' | ||
) | ||
} | ||
|
||
before(() => { | ||
// Persist this across tests so we don't have to login before each test | ||
Cypress.Cookies.defaults({ | ||
whitelist: 'JSESSIONID', | ||
}) | ||
|
||
cy.request({ | ||
url: `${loginUrl}/${LOGIN_ENDPOINT}`, | ||
method: 'POST', | ||
form: true, | ||
followRedirect: true, | ||
body: { | ||
j_username: username, | ||
j_password: password, | ||
'2fa_code': '', | ||
}, | ||
}) | ||
Cypress.Cookies.defaults({ whitelist: 'JSESSIONID' }) | ||
cy.login() | ||
}) | ||
|
||
beforeEach(() => { | ||
// This ensures the app platform knows which URL to use even if REACT_APP_DHIS2_BASE_URL is undefined | ||
// It also ensures that the value from the cypress env is used instead of REACT_APP_DHIS2_BASE_URL | ||
// This ensures the app platform knows which URL to use even if | ||
// REACT_APP_DHIS2_BASE_URL is undefined It also ensures that the value | ||
// from the cypress env is used instead of REACT_APP_DHIS2_BASE_URL | ||
const loginUrl = Cypress.env('dhis2_base_url') | ||
localStorage.setItem('DHIS2_BASE_URL', loginUrl) | ||
}) | ||
} |