test(integration): add integration test setup and url tests #2019
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Integration tests are important. With the new external API feature coming up, it would be especially helpful to have greater assurances about the behaviour of the backend as a whole, and be able to catch and prevent regressions before they happen.
Right now, our backend is covered by unit tests; however, they make use of extensive mocking and do not test the real aggregate behaviour of the backend system. Our E2E tests help to cover for this somewhat, but they cannot be used to test our internal or upcoming external APIs directly; plus, they're expensive to run and cannot be used to comprehensively test edge cases and failure behaviours.
Solution
Set up integration tests in
/test/integration/
. These are written and run using the Jest framework.As a start, a few integration tests have been added to test the internal API URL functionalities in
Urls.test.ts
:To run the integration tests, run
npm run test:integration
.Configuration
integration-[0-9a-z]{10}@open.gov.sg
docker-compose
to finish spinning up the local environment before running integration testsHandling the database
docker-compose.yml
) for integration testsOther notes
I find it very sad to have to attachauthCookie
to every request, but I simply couldn't figure out how to make auth work automatically withcross-fetch
on the backend even after wrestling with it for hours. Maybeaxios
would be better?authCookie
for each test case, it makes sense to attach it to every request. But the difficulty with usingcross-fetch
still stands :'(Deploy Notes
ci.yml
has been modified to include integration tests. Deployment to Elastic Beanstalk and Lambda will happen only if the integration tests pass (alongside CI and other Jest tests).New dev dependencies:
form-data
: used in integration tests to createFormData
objects for creating file links