Files
graphql-api-js/src/__test__/all.test.ts
T
Arwid ThornströmandGitHub 74796e23a8 P5-7141: basic tests (#1)
* added containers for db and apollo

* connected to test db

* added network again

* Added base for tests
2021-06-17 11:04:22 +02:00

76 lines
2.1 KiB
TypeScript

import fetch from 'isomorphic-fetch';
import { IAllTestContainers, createAllTestContainers } from './containerSetup';
jest.setTimeout(18000_000);
describe('GraphQL Apollo tests', () => {
let allContainers: IAllTestContainers;
beforeAll(async () => {
allContainers = await createAllTestContainers();
});
afterAll(async () => {
await allContainers.stopAll();
});
describe('Setup containers', () => {
it('should have a trivial test', () => {
expect(true).toBe(true);
});
it('should have access to containers', () => {
expect(allContainers).toBeDefined();
});
it('test date on db testcontainer', async () => {
const res = await allContainers.db.raw('select now()');
expect(res.rows[0]['now']).toBeInstanceOf(Date);
});
it('healthcheck on api testcontainer', async () => {
const port = allContainers.apiContainer.getMappedPort(4000);
const response = await fetch(
`http://localhost:${port}/.well-known/apollo/server-health`,
{
method: 'GET',
},
);
const resp = await response.json();
expect(resp.status).toBe('pass');
});
it('should have some basedata', async () => {
const response = await allContainers.db.raw(
`SELECT * FROM locales LIMIT 1;`,
);
expect(response.rows[0].value).toBe('sv_SE');
expect(response.rows[0].name).toBe('Swedish (Sweden)');
});
it('should be connected to test db', async () => {
const port = allContainers.apiContainer.getMappedPort(4000);
const response = await fetch(`http://localhost:${port}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `
{
designer(id: 1) {
id
name
path
}
}`,
}),
});
const resp = await response.json();
const designer = resp.data.designer;
expect(designer.id).toBe('1');
expect(designer.name).toBe('Lorem Ipsumsson');
expect(designer.path).toBe('lorem-ipsumsson');
});
});
});