Newer
Older
/**
* @file Ce fichier charge et execute tous les tests sur les resolvers
* @author ofacklam
*/
import { expect } from 'chai';
import fs from 'fs';
import path from 'path';
import { ApolloServer } from 'apollo-server-express';
import { createTestClient } from 'apollo-server-testing';
//TODO : Set up a mock LDAP server (LDAP_URI = ... or TARGET_ENV=testing)
import schema from '../../src/graphql/schema';
import { TestCollection } from './testData';
const dir = path.resolve(__dirname, './data');
describe("GraphQL resolvers", function() {
fs.readdirSync(dir, {withFileTypes:true})
.filter(item => !item.isDirectory())
.forEach(file => {
const testCol : TestCollection = require(path.resolve(dir, file.name)).tests;
describe(testCol.description, function() {
//contruct context and apollo server
const server = new ApolloServer({
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
context: testCol.context
});
const {query} = createTestClient(server);
for (let testSet of testCol.tests) {
describe(testSet.description, function() {
for(let t of testSet.tests) {
it(t.description, async function() {
//silence the console
console.log = function () { };
//query
let res = await query({query: t.query});
//reset console
delete console.log;
let final = {};
final['data'] = res.data;
//if(res.errors !== undefined) final['errors'] = res.errors;
expect(final).to.deep.equal(t.result);
})
}
})
}
})
})
beforeEach(function () {
});
afterEach(function () {
});
})