diff --git a/test/resources/exampleOpenApiFiles/valid/bugRecreationTemplate/openapi.yml b/test/resources/exampleOpenApiFiles/valid/bugRecreationTemplate/openapi.yml new file mode 100644 index 0000000..e5c01c1 --- /dev/null +++ b/test/resources/exampleOpenApiFiles/valid/bugRecreationTemplate/openapi.yml @@ -0,0 +1,24 @@ +openapi: 3.0.0 +info: + title: Example OpenApi 3 spec + description: Has various paths with responses to use in testing + version: 0.1.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + allOf: + - type: object + properties: + expectedProperty1: + type: string + - type: object + properties: + expectedProperty2: + type: string + # additionalProperties: false # Uncommenting this line exposes the bug diff --git a/test/unit/bug-recreation-template.test.js b/test/unit/bug-recreation-template.test.js new file mode 100644 index 0000000..0c72824 --- /dev/null +++ b/test/unit/bug-recreation-template.test.js @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright 2019 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ + +const chai = require('chai'); +const path = require('path'); + +const chaiResponseValidator = require('../..'); + +const dirContainingApiSpec = path.resolve('test/resources/exampleOpenApiFiles/valid/bugRecreationTemplate'); +const { expect } = chai; + +describe('Recreate bug (issue #46)', function () { + + before(function () { + const pathToApiSpec = path.join(dirContainingApiSpec, 'openapi.yml'); + chai.use(chaiResponseValidator(pathToApiSpec)); + }); + + const res = { + status: 200, + req: { + method: 'GET', + path: '/test', + }, + body: { + expectedProperty1: 'foo', + expectedProperty2: 'bar', + }, + }; + + it('passes', function () { + expect(res).to.satisfyApiSpec; + }); + + it('fails when using .not', function () { + const assertion = () => expect(res).to.not.satisfyApiSpec; + expect(assertion).to.throw(); + }); +});