/** * @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({ schema, 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 () { }); })