Skip to content

Commit

Permalink
feat: adding env variable for mocked date without UI
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Nov 13, 2020
1 parent 8a8527d commit 06cef93
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
13 changes: 5 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ jobs:
pushd test_helper_schema
SQITCH_TARGET="ciip_portal_dev" sqitch deploy
popd
pushd mocks_schema
SQITCH_TARGET="ciip_portal_dev" sqitch deploy
popd
- run:
name: Create Mailhog server via docker image
command: docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog
Expand All @@ -375,21 +378,15 @@ jobs:
SMTP_CONNECTION_STRING: smtp://@localhost:1025
SENDER_EMAIL: BCCAS <example@cas.com>
ADMIN_EMAIL: GHG Regulator <GHGRegulator@gov.bc.ca>
ENABLE_DB_MOCKS_COOKIES_ONLY: true # Allow cookies to be set by cypress
command: |
source ~/.asdf/asdf.sh
pushd app
NO_MATHJAX=true yarn start & yarn wait-on http://localhost:3004
yarn test:e2e-snapshots
popd
- run:
name: deploy mocks schema
command: |
source ~/.bashrc
pushd mocks_schema
SQITCH_TARGET="ciip_portal_dev" sqitch deploy
popd
- run:
name: run end-to-en tests with mocks
name: run end-to-en tests with mocks environment variable set
environment:
ENABLE_DB_MOCKS: "true"
command: |
Expand Down
1 change: 1 addition & 0 deletions app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ HOST=<host address>

# true if we want the mocks database schema to be deployed, false otherwise
ENABLE_DB_MOCKS=<true or false>
ENABLE_DB_MOCKS_COOKIES_ONLY=<true or false>

# The PostgreSQL role used by the application when run in development mode, with the NO_AUTH option enabled
# defaults to postgres.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('When logged in as a certifier(reporter)', () => {
Cypress.env('TEST_CERTIFIER_USERNAME'),
Cypress.env('TEST_CERTIFIER_PASSWORD')
);
cy.useMockedTime(new Date(2020, 5, 10, 9, 0, 0, 0)); //May 10th at 9am
});

afterEach(() => {
Expand Down
1 change: 1 addition & 0 deletions app/cypress/integration/reporter-certifier-access.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('When logged in as a certifier(reporter)', () => {
Cypress.env('TEST_CERTIFIER_USERNAME'),
Cypress.env('TEST_CERTIFIER_PASSWORD')
);
cy.useMockedTime(new Date(2020, 5, 10, 9, 0, 0, 0)); //May 10th at 9am
});

afterEach(() => {
Expand Down
10 changes: 10 additions & 0 deletions app/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ EOF`)
);
});

Cypress.Commands.add('useMockedTime', (dateTime) => {
cy.setCookie(
'mocks.mocked_timestamp',
Math.round(dateTime.getTime() / 1000).toString()
);
});
Cypress.Commands.add('clearMockedTime', () => {
cy.clearCookie('mocks.mocked_timestamp');
});

Cypress.Commands.add('deployProdData', () => {
cy.exec('pushd ../ && ./.bin/deploy-data.sh -test && popd');
});
Expand Down
8 changes: 6 additions & 2 deletions app/server/helpers/databaseMockPgOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ const generateForwardedCookieOptions = (cookies, fields) => {
}, {});
};

// if the ENABLE_DB_MOCKS env variable is set,
// if the ENABLE_DB_MOCKS or ENABLE_DB_MOCKS_COOKIES_ONLY env variable is set,
// creates the settings object needed for postgres to use the mocks schema by default and the fields to retrieve from the cookies
const generateDatabaseMockOptions = (cookies, fields) => {
if (process.env.ENABLE_DB_MOCKS !== 'true') return {};
if (
process.env.ENABLE_DB_MOCKS !== 'true' &&
process.env.ENABLE_DB_MOCKS_COOKIES_ONLY !== 'true'
)
return {};

return {
...generateForwardedCookieOptions(cookies, fields),
Expand Down

0 comments on commit 06cef93

Please sign in to comment.