UNPKG

graphql-validity

Version:

Make business logic validation easy on the graphql side without adding any declarations or modifications to the existing graphql schema.

60 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon = require("sinon"); const profiling_1 = require("../src/profiling"); const koa_middleware_1 = require("../src/koa-middleware"); const mocks_1 = require("./helpers/mocks"); const validation = require("../src/validation"); var chai = require("chai"); var chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); var expect = chai.expect; describe('koa-middleware', () => { let profilingResultHandler = { handler: profiling_1.defaultProfilingResultHandler }; let req; let next; let ctx; let result; let applyValidationFake; let sandbox; beforeEach(() => { req = { __graphQLValidity: undefined }; next = () => { }; ctx = { body: '{}', req }; applyValidationFake = sinon.fake(); const mockValidation = mocks_1.mockModule(validation, { applyValidation: applyValidationFake }); sandbox = sinon.createSandbox(); mockValidation(sandbox); result = koa_middleware_1.default(profilingResultHandler); }); afterEach(() => { sandbox.restore(); }); it('should return wrapper function', () => { expect(result).to.be.an('function'); }); describe('graphQLValidityKoaMiddleware', () => { it('should add validity data to request', () => { expect(req.__graphQLValidity).to.not.be.null; }); it('should call validation function', async () => { await result(ctx, next); expect(applyValidationFake.callCount).to.equal(1); }); it('should not throw exception if output data is not in JSON format', () => { ctx = { body: '', req }; expect(result(ctx, next)).to.eventually.be.fulfilled; }); }); }); //# sourceMappingURL=koa-middleware.js.map