Goal of these integration tests is to ensure that no change breaks an important feature, while keeping manual work for writing tests low.
Non Goals of the tests is to cover each and every feature and ensure that nothing breaks, also we do not want to reach full coverage / test-driven development. We simply don't have capacity for that.
To run integration tests locally, ensure the database url is set correctly to some local database (the database should have the correct schema, i.e. run npm run db:reset
, but the tests should generally be independent of existing database's content), then run the integration tests with npm run integration-tests
.
To write a new integration test, add a new Typescript file to /integration-tests
and import it from index.ts
.
A test consists of the following parts:
- the
test
function gives the test a name and handles errors - with the clients
defaultClient
(unauthenticated user),adminClient
and the clients created withcreateUserClient
one can send requests to GraphQL via the.request
and.requestShallFail
methods - For validation the
assert
module of NodeJS is used - calls to external systems must be mocked with
expectFetch
The result when look like this:
test('Example Test', async () => {
const client = createUserClient();
const response = await client.request(`query { ... }`);
assert.assertEqual(response.value, 'expected');
});
Tests can also build up on results of previous tests, i.e. one can use the account registered in the registration test in the login test:
const accountTest = test('RegisterPupil', async () => {
// ...
return account;
});
test('LoginPupil', async () => {
const account = await accountTest;
// ...
});