diff --git a/README.md b/README.md index 6b8ed335b..29b3f462e 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ These are designed to run against a local environment. The following apps must b `CYPRESS_DATABASE_URL=postgres://postgres:postgres@localhost:5432` `CYPRESS_USER_SERVICE_DB_NAME=gapuserlocaldb` -The package.json includes shorthands to run: +The package.json within admin/applicant includes shorthands to run: - `yarn workspace admin integration:gui` - run individual test cases against browser - `yarn integration` - runs all tests in headless mode @@ -76,6 +76,8 @@ It is recommended that data teardown/setup happens as part of each test run ensu Various tasks have been added to perform tasks before and during test runs. These can be found in `cypress/plugins/index.js` -`wiremock:selectUser` - this will edit the wiremock stub mapping to One login (/userInfo) to return either an applicant, admin or super-admin. This will act as the signed in user to perform the test actions -`db:removeTestUsers` - this will remove test users directly to the database via sql -`db:addTestUsers` - this will add test users directly to the database via sql +`setup:user` + +- this will remove test users directly to the database via sql +- this will add test users directly to the database via sql +- this will edit the wiremock stub mapping to One login (/userInfo) to return either an applicant, admin or super-admin. This will act as the signed in user to perform the test actions diff --git a/packages/admin/cypress/integration/super-admin-dashboard/super-admin-dashboard.spec.js b/packages/admin/cypress/integration/super-admin-dashboard/super-admin-dashboard.spec.js index 9d26d82e7..e426830ad 100644 --- a/packages/admin/cypress/integration/super-admin-dashboard/super-admin-dashboard.spec.js +++ b/packages/admin/cypress/integration/super-admin-dashboard/super-admin-dashboard.spec.js @@ -2,9 +2,7 @@ import { login } from '../../utils/login'; describe('super-admin-dashboard', () => { beforeEach(() => { - cy.task('db:deleteTestUsers'); - cy.task('db:addTestUsers'); - cy.task('wiremock:selectUser', 'superAdmin'); + cy.task('setup:user', 'superAdmin'); login(); }); diff --git a/packages/admin/cypress/plugins/index.js b/packages/admin/cypress/plugins/index.js index 6914cf6ce..bab1c8a5b 100644 --- a/packages/admin/cypress/plugins/index.js +++ b/packages/admin/cypress/plugins/index.js @@ -24,18 +24,10 @@ module.exports = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config on('task', { - 'wiremock:selectUser': (user) => { - createUserInfoStub(user).then(() => { - console.log('User info stub created'); - }); - return null; - }, - 'db:addTestUsers': async () => { - await createTestUsers(); - return null; - }, - 'db:deleteTestUsers': async () => { + 'setup:user': async (user) => { await deleteTestUsers(); + await createTestUsers(); + await createUserInfoStub(user); return null; }, log(message) { diff --git a/packages/admin/cypress/seed/database.js b/packages/admin/cypress/seed/database.js index 6ab513f3c..3e765e8fb 100644 --- a/packages/admin/cypress/seed/database.js +++ b/packages/admin/cypress/seed/database.js @@ -17,7 +17,7 @@ export const runSQL = async (filePath, dbName) => { console.log('SQL script executed successfully.'); } catch (error) { - console.error('Error executing SQL script:', error); + console.error('Error executing SQL script:\n\n', error); } }; diff --git a/packages/admin/cypress/utils/wiremock.js b/packages/admin/cypress/utils/wiremock.js index 41b429914..d59e1c74d 100644 --- a/packages/admin/cypress/utils/wiremock.js +++ b/packages/admin/cypress/utils/wiremock.js @@ -27,8 +27,9 @@ export const createUserInfoStub = async (user) => { }; try { - const response = await axios.get(`${wireMockBaseUrl}/mappings`); - const existingMappings = response.data.mappings; + const { + data: { mappings: existingMappings }, + } = await axios.get(`${wireMockBaseUrl}/mappings`); const existingMapping = existingMappings.find( (mapping) => @@ -50,9 +51,9 @@ export const createUserInfoStub = async (user) => { `${wireMockBaseUrl}/mappings`, userInfoStub ); - console.log('New WireMock mapping created:', createResponse.data); + console.log('New WireMock mapping created:\n\n', createResponse.data); } } catch (error) { - console.error('Error creating/updating WireMock stub:', error.message); + console.error('Error creating/updating WireMock stub:\n\n', error); } };