Skip to content

Commit 6416196

Browse files
authored
chore: add template to easily recreate bugs (#47)
1 parent f69436f commit 6416196

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Example OpenApi 3 spec
4+
description: Has various paths with responses to use in testing
5+
version: 0.1.0
6+
paths:
7+
/test:
8+
get:
9+
responses:
10+
'200':
11+
description: OK
12+
content:
13+
application/json:
14+
schema:
15+
allOf:
16+
- type: object
17+
properties:
18+
expectedProperty1:
19+
type: string
20+
- type: object
21+
properties:
22+
expectedProperty2:
23+
type: string
24+
# additionalProperties: false # Uncommenting this line exposes the bug
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright 2019 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
17+
const chai = require('chai');
18+
const path = require('path');
19+
20+
const chaiResponseValidator = require('../..');
21+
22+
const dirContainingApiSpec = path.resolve('test/resources/exampleOpenApiFiles/valid/bugRecreationTemplate');
23+
const { expect } = chai;
24+
25+
describe('Recreate bug (issue #46)', function () {
26+
27+
before(function () {
28+
const pathToApiSpec = path.join(dirContainingApiSpec, 'openapi.yml');
29+
chai.use(chaiResponseValidator(pathToApiSpec));
30+
});
31+
32+
const res = {
33+
status: 200,
34+
req: {
35+
method: 'GET',
36+
path: '/test',
37+
},
38+
body: {
39+
expectedProperty1: 'foo',
40+
expectedProperty2: 'bar',
41+
},
42+
};
43+
44+
it('passes', function () {
45+
expect(res).to.satisfyApiSpec;
46+
});
47+
48+
it('fails when using .not', function () {
49+
const assertion = () => expect(res).to.not.satisfyApiSpec;
50+
expect(assertion).to.throw();
51+
});
52+
});

0 commit comments

Comments
 (0)