-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration test for gateway module
- Loading branch information
1 parent
073a701
commit bef82ab
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import * as request from 'supertest'; | ||
import { AppModule as PostsModule } from '../graphql-federation/posts-service/federation-posts.module'; | ||
import { AppModule as UsersModule } from '../graphql-federation/users-service/federation-users.module'; | ||
import { AppModule as GatewayModule } from '../graphql-federation/gateway/gateway.module'; | ||
|
||
describe('GraphQL', () => { | ||
let postsApp: INestApplication; | ||
let usersApp: INestApplication; | ||
let gatewayApp: INestApplication; | ||
|
||
beforeEach(async () => { | ||
const usersModule = await Test.createTestingModule({ | ||
imports: [UsersModule], | ||
}).compile(); | ||
|
||
usersApp = usersModule.createNestApplication(); | ||
await usersApp.listenAsync(3001); | ||
|
||
const postsModule = await Test.createTestingModule({ | ||
imports: [PostsModule], | ||
}).compile(); | ||
|
||
postsApp = postsModule.createNestApplication(); | ||
await postsApp.listenAsync(3002); | ||
|
||
const gatewayModule = await Test.createTestingModule({ | ||
imports: [GatewayModule], | ||
}).compile(); | ||
|
||
gatewayApp = gatewayModule.createNestApplication(); | ||
await gatewayApp.init(); | ||
}); | ||
|
||
it(`should run lookup across boundaries`, () => { | ||
return request(gatewayApp.getHttpServer()) | ||
.post('/graphql') | ||
.send({ | ||
operationName: null, | ||
variables: {}, | ||
query: ` | ||
{ | ||
getPosts { | ||
id, | ||
title, | ||
body, | ||
user { | ||
id, | ||
name, | ||
} | ||
} | ||
}`, | ||
}) | ||
.expect(200, { | ||
data: { | ||
getPosts: [ | ||
{ | ||
id: '1', | ||
title: 'Hello world', | ||
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
user: { | ||
id: '5', | ||
name: 'GraphQL', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it(`should run reverse lookup across boundaries`, () => { | ||
return request(gatewayApp.getHttpServer()) | ||
.post('/graphql') | ||
.send({ | ||
operationName: null, | ||
variables: {}, | ||
query: ` | ||
{ | ||
getUser(id: "5") { | ||
id, | ||
name, | ||
posts { | ||
id, | ||
title, | ||
body, | ||
} | ||
} | ||
}`, | ||
}) | ||
.expect(200, { | ||
data: { | ||
getUser: { | ||
id: '5', | ||
name: 'GraphQL', | ||
posts: [ | ||
{ | ||
id: '1', | ||
title: 'Hello world', | ||
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await postsApp.close(); | ||
await usersApp.close(); | ||
await gatewayApp.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { GraphQLGatewayModule } from '../../../lib/graphql-gateway.module'; | ||
import { join } from 'path'; | ||
|
||
@Module({ | ||
imports: [ | ||
GraphQLGatewayModule.forRoot({ | ||
serviceList: [ | ||
{ name: 'users', url: 'http://localhost:3001/graphql' }, | ||
{ name: 'posts', url: 'http://localhost:3002/graphql' }, | ||
], | ||
}), | ||
], | ||
}) | ||
export class AppModule {} |