Skip to content

Commit 2690933

Browse files
committed
test: add more test cases
1 parent 0c45db9 commit 2690933

13 files changed

+502
-31
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
requestBody: {
5+
description: 'a test body',
6+
content: {
7+
'application/json': {
8+
schema: {
9+
allOf: [
10+
{ $ref: '#/components/schemas/Test1' },
11+
{ $ref: '#/components/schemas/Test2'}
12+
],
13+
},
14+
},
15+
},
16+
},
17+
schemas: {
18+
Test1: {
19+
type: 'object',
20+
required: ['foo'],
21+
properties: {
22+
foo: {
23+
type: 'string',
24+
},
25+
},
26+
},
27+
Test2: {
28+
type: 'object',
29+
required: ['boo'],
30+
properties: {
31+
boo: {
32+
type: 'string',
33+
},
34+
},
35+
},
36+
},
37+
},
38+
request: {
39+
body: {
40+
foo: 'hello',
41+
boo: 'world',
42+
},
43+
},
44+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
requestBody: {
5+
description: 'a test body',
6+
content: {
7+
'application/json': {
8+
schema: {
9+
oneOf: [
10+
{ $ref: '#/components/schemas/Test1' },
11+
{ $ref: '#/components/schemas/Test2'}
12+
],
13+
},
14+
},
15+
},
16+
},
17+
schemas: {
18+
Test1: {
19+
type: 'object',
20+
required: ['foo'],
21+
properties: {
22+
foo: {
23+
type: 'string',
24+
},
25+
},
26+
},
27+
Test2: {
28+
type: 'object',
29+
required: ['boo'],
30+
properties: {
31+
boo: {
32+
type: 'string',
33+
},
34+
},
35+
},
36+
},
37+
},
38+
request: {
39+
body: {
40+
boo: 'world',
41+
},
42+
},
43+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
"paths": {
5+
"/pets": {
6+
"patch": {
7+
"requestBody": {
8+
"content": {
9+
"application/json": {
10+
"schema": {
11+
"oneOf": [
12+
{
13+
"$ref": "#/components/schemas/Cat"
14+
},
15+
{
16+
"$ref": "#/components/schemas/Dog"
17+
}
18+
]
19+
}
20+
}
21+
}
22+
},
23+
"responses": {
24+
"200": {
25+
"description": "Updated"
26+
}
27+
}
28+
}
29+
}
30+
},
31+
"schemas": {
32+
"Dog": {
33+
"type": "object",
34+
"properties": {
35+
"bark": {
36+
"type": "boolean"
37+
},
38+
"breed": {
39+
"type": "string",
40+
"enum": [
41+
"Dingo",
42+
"Husky",
43+
"Retriever",
44+
"Shepherd"
45+
]
46+
}
47+
}
48+
},
49+
"Cat": {
50+
"type": "object",
51+
"properties": {
52+
"hunts": {
53+
"type": "boolean"
54+
},
55+
"age": {
56+
"type": "integer"
57+
}
58+
}
59+
}
60+
},
61+
},
62+
request: {
63+
body: {
64+
"bark": true,
65+
"breed": "Dingo"
66+
},
67+
},
68+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
requestBody: {
5+
description: 'a test body',
6+
content: {
7+
'application/json': {
8+
schema: {
9+
type: 'object',
10+
properties: {
11+
foo: {
12+
nullable: true,
13+
allOf: [{ type: 'string' }],
14+
},
15+
},
16+
},
17+
},
18+
},
19+
},
20+
},
21+
request: {
22+
body: {
23+
foo: null,
24+
},
25+
},
26+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
requestBody: {
5+
description: 'a test body',
6+
content: {
7+
'application/json': {
8+
schema: {
9+
type: 'object',
10+
properties: {
11+
foo: {
12+
anyOf: [
13+
{
14+
type: "object",
15+
nullable: true
16+
},
17+
{ type: 'string' },
18+
{ type: 'boolean' }
19+
],
20+
},
21+
},
22+
},
23+
},
24+
},
25+
},
26+
},
27+
request: {
28+
body: {
29+
foo: null,
30+
},
31+
},
32+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
requestBody: {
5+
description: 'a test body',
6+
content: {
7+
'application/json': {
8+
schema: {
9+
type: 'object',
10+
properties: {
11+
foo: {
12+
oneOf: [
13+
{
14+
type: "object",
15+
nullable: true
16+
},
17+
{ type: 'string' },
18+
{ type: 'boolean' }
19+
],
20+
},
21+
},
22+
},
23+
},
24+
},
25+
},
26+
},
27+
request: {
28+
body: {
29+
foo: null,
30+
},
31+
},
32+
};

test/fixtures/fail-a-missing-query-param.js.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
requestBody: {
5+
description: 'a test body',
6+
content: {
7+
'application/json': {
8+
schema: {
9+
allOf: [
10+
{ $ref: '#/components/schemas/Test1' },
11+
{ $ref: '#/components/schemas/Test2'}
12+
],
13+
},
14+
},
15+
},
16+
},
17+
schemas: {
18+
Test1: {
19+
type: 'object',
20+
required: ['foo'],
21+
properties: {
22+
foo: {
23+
type: 'string',
24+
},
25+
},
26+
},
27+
Test2: {
28+
type: 'object',
29+
required: ['boo'],
30+
properties: {
31+
boo: {
32+
type: 'string',
33+
},
34+
},
35+
},
36+
},
37+
},
38+
request: {
39+
body: {
40+
foo: 'hello',
41+
},
42+
},
43+
expectedErrors: [
44+
{"code": "Validation-required", "source": {"pointer": "#/paths/test/post/requestBody/required"}, "status": 400, "title": "must have required property 'boo'"}
45+
]
46+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module.exports = {
2+
validateArgs: {
3+
parameters: [],
4+
requestBody: {
5+
description: 'a test body',
6+
content: {
7+
'application/json': {
8+
schema: {
9+
oneOf: [
10+
{ $ref: '#/components/schemas/Test1' },
11+
{ $ref: '#/components/schemas/Test2'}
12+
],
13+
},
14+
},
15+
},
16+
},
17+
schemas: {
18+
Test1: {
19+
type: 'object',
20+
required: ['foo'],
21+
properties: {
22+
foo: {
23+
type: 'string',
24+
},
25+
},
26+
},
27+
Test2: {
28+
type: 'object',
29+
required: ['boo'],
30+
properties: {
31+
boo: {
32+
type: 'string',
33+
},
34+
},
35+
},
36+
},
37+
},
38+
request: {
39+
body: {
40+
foo: 'hello',
41+
boo: 'world',
42+
},
43+
},
44+
expectedErrors: [
45+
{"code": "Validation-additionalProperties", "source": {"pointer": "#/components/schemas/Test1/additionalProperties"}, "status": 400, "title": "must NOT have additional properties"}, {"code": "Validation-additionalProperties", "source": {"pointer": "#/components/schemas/Test2/additionalProperties"}, "status": 400, "title": "must NOT have additional properties"}, {"code": "Validation-oneOf", "source": {"pointer": "#/oneOf"}, "status": 400, "title": "must match exactly one schema in oneOf"}
46+
]
47+
};

0 commit comments

Comments
 (0)