mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2025-07-23 04:58:27 -06:00
PR-448199:
Adding Testing with Jest and bin command for npx.
This commit is contained in:
36
tests/server/index.test.ts
Normal file
36
tests/server/index.test.ts
Normal file
@ -0,0 +1,36 @@
|
||||
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);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user