2021-07-25 13:21:57 +00:00
|
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
|
|
|
import GraphqlQueryService from '.';
|
|
|
|
|
|
|
|
|
|
describe('GraphqlQueryService', () => {
|
|
|
|
|
let service: GraphqlQueryService;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
|
|
|
providers: [GraphqlQueryService],
|
|
|
|
|
}).compile();
|
|
|
|
|
|
|
|
|
|
service = module.get<GraphqlQueryService>(GraphqlQueryService);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should query graphql datasources', async () => {
|
|
|
|
|
const sourceOptions = {
|
|
|
|
|
url: 'https://api.spacex.land/graphql/',
|
|
|
|
|
headers: [],
|
2021-09-21 13:48:28 +00:00
|
|
|
url_params: [],
|
|
|
|
|
};
|
2021-07-25 13:21:57 +00:00
|
|
|
|
2021-09-21 13:48:28 +00:00
|
|
|
const queryOptions = { query: '{ launchesPast(limit: 10) { mission_name } }' };
|
2021-07-25 13:21:57 +00:00
|
|
|
|
|
|
|
|
const result = await service.run(sourceOptions, queryOptions, 'no-datasource-id');
|
2021-09-21 13:48:28 +00:00
|
|
|
|
2021-07-25 13:21:57 +00:00
|
|
|
expect(result.data['data']['launchesPast'].length).toBe(10);
|
|
|
|
|
});
|
2021-09-21 13:48:28 +00:00
|
|
|
});
|