Skip to content

Commit a9abd1c

Browse files
sample(@nestjs) update graphql example, add integration test
1 parent 0c98a65 commit a9abd1c

26 files changed

Lines changed: 4518 additions & 15 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { NestFactory } from '@nestjs/core';
3+
import * as request from 'supertest';
4+
import { AsyncClassApplicationModule } from './../src/async-options-class.module';
5+
6+
describe('GraphQL (async class)', () => {
7+
let app: INestApplication;
8+
9+
beforeEach(async () => {
10+
app = await NestFactory.create(AsyncClassApplicationModule, {
11+
logger: false,
12+
});
13+
await app.init();
14+
});
15+
16+
it(`should return query result`, () => {
17+
return request(app.getHttpServer())
18+
.post('/graphql')
19+
.send({
20+
operationName: null,
21+
variables: {},
22+
query: '{\n getCats {\n id\n }\n}\n',
23+
})
24+
.expect(200, {
25+
data: {
26+
getCats: [
27+
{
28+
id: 1,
29+
},
30+
],
31+
},
32+
});
33+
});
34+
35+
afterEach(async () => {
36+
await app.close();
37+
});
38+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { NestFactory } from '@nestjs/core';
3+
import * as request from 'supertest';
4+
import { AsyncExistingApplicationModule } from './../src/async-options-existing.module';
5+
6+
describe('GraphQL (async existing)', () => {
7+
let app: INestApplication;
8+
9+
beforeEach(async () => {
10+
app = await NestFactory.create(AsyncExistingApplicationModule, {
11+
logger: false,
12+
});
13+
await app.init();
14+
});
15+
16+
it(`should return query result`, () => {
17+
return request(app.getHttpServer())
18+
.post('/graphql')
19+
.send({
20+
operationName: null,
21+
variables: {},
22+
query: '{\n getCats {\n id\n }\n}\n',
23+
})
24+
.expect(200, {
25+
data: {
26+
getCats: [
27+
{
28+
id: 1,
29+
},
30+
],
31+
},
32+
});
33+
});
34+
35+
afterEach(async () => {
36+
await app.close();
37+
});
38+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { NestFactory } from '@nestjs/core';
3+
import * as request from 'supertest';
4+
import { AsyncApplicationModule } from './../src/async-options.module';
5+
6+
describe('GraphQL (async configuration)', () => {
7+
let app: INestApplication;
8+
9+
beforeEach(async () => {
10+
app = await NestFactory.create(AsyncApplicationModule, { logger: false });
11+
await app.init();
12+
});
13+
14+
it(`should return query result`, () => {
15+
return request(app.getHttpServer())
16+
.post('/graphql')
17+
.send({
18+
operationName: null,
19+
variables: {},
20+
query: '{\n getCats {\n id\n }\n}\n',
21+
})
22+
.expect(200, {
23+
data: {
24+
getCats: [
25+
{
26+
id: 1,
27+
},
28+
],
29+
},
30+
});
31+
});
32+
33+
afterEach(async () => {
34+
await app.close();
35+
});
36+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { NestFactory } from '@nestjs/core';
3+
import * as request from 'supertest';
4+
import { ApplicationModule } from './../src/app.module';
5+
6+
describe('GraphQL', () => {
7+
let app: INestApplication;
8+
9+
beforeEach(async () => {
10+
app = await NestFactory.create(ApplicationModule, { logger: false });
11+
await app.init();
12+
});
13+
14+
it(`should return query result`, () => {
15+
return request(app.getHttpServer())
16+
.post('/graphql')
17+
.send({
18+
operationName: null,
19+
variables: {},
20+
query: '{\n getCats {\n id\n }\n}\n',
21+
})
22+
.expect(200, {
23+
data: {
24+
getCats: [
25+
{
26+
id: 1,
27+
},
28+
],
29+
},
30+
});
31+
});
32+
33+
afterEach(async () => {
34+
await app.close();
35+
});
36+
});

0 commit comments

Comments
 (0)