create-node-ts-graphql-server/tests/server/index.test.ts
Alejandro Lembke Barrientos e9bc4f091f PR-448199:
Adding Testing with Jest and bin command for npx.
2022-05-25 23:39:38 +00:00

36 lines
1.3 KiB
TypeScript

import server from '../../index';
import supertest from 'supertest';
describe('global server tests', () => {
let request;
beforeEach(() => {
request = supertest(server);
});
test('should return Test data from test Query', async () => {
const bodyResponse = {
data: {
test: { test: 'This is the text response for Test Query from a model' }
}
}
const response = await request.get('/graphql?query=%7B%0A%20%20test%7B%0A%20%20%20%20test%0A%20%20%7D%0A%7D%0A')
.set('Accept', 'application/json')
expect(response.status).toEqual(200);
expect(response.body).toEqual(bodyResponse);
});
test('should return Test data from test Mutation', async () => {
const bodyResponse = {
data: {
testMutation: {
testMutation: 'Simulate to insert some text: test text from a model'
}
}
}
const response = await request.post('/graphql')
.send({"query":"mutation{\n testMutation{\n testMutation(text: \"test text\")\n }\n}\n","variables":null})
.set('Accept', 'application/json')
expect(response.status).toEqual(200);
expect(response.body).toEqual(bodyResponse);
});
});