Skip to content

Commit

Permalink
deep copy ref test
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed May 6, 2020
1 parent 6c6d2a9 commit 60c2abd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
34 changes: 34 additions & 0 deletions test/resources/serialized.objects.yaml
Expand Up @@ -38,6 +38,20 @@ paths:
"200":
description: the object

/deep_object_2:
get:
summary: "retrieve a deep object"
operationId: getDeepObject2
parameters:
- in: query
style: deepObject
explode: true
name: settings
schema:
$ref: '#/components/schemas/Deep'
responses:
"200":
description: the object
/tags:
get:
summary: "Retrieve all tags"
Expand Down Expand Up @@ -124,3 +138,23 @@ paths:
application/json:
schema:
type: object

components:
schemas:
Deep:
type: object
properties:
tag_ids:
type: array
items:
type: integer
minimum: 0
minItems: 1
state:
type: string
enum: ["default", "validated", "pending"]
default: "default"
description: "Filter the tags by their validity. The default value ('default') stands for no filtering."
greeting:
type: string
default: "hello"
22 changes: 20 additions & 2 deletions test/serialized.objects.spec.ts
Expand Up @@ -18,7 +18,8 @@ describe(packageJson.name, () => {
.Router()
.get(`/serialisable`, (req, res) => res.json(req.query))
.get(`/tags`, (req, res) => res.json(req.query))
.get(`/deep_object`, (req, res) => res.json(req.query)),
.get(`/deep_object`, (req, res) => res.json(req.query))
.get(`/deep_object_2`, (req, res) => res.json(req.query)),
),
);
});
Expand Down Expand Up @@ -113,6 +114,7 @@ describe(packageJson.name, () => {
.then((r) => {
const expected = {
settings: {
greeting: 'hello',
state: 'validated',
},
};
Expand All @@ -126,13 +128,14 @@ describe(packageJson.name, () => {
.then((r) => {
const expected = {
settings: {
greeting: 'hello',
state: 'validated',
},
};
expect(r.body).to.deep.equals(expected);
}));

it('should explode deepObject query params and use deepObject default values', async () =>
it('should explode deepObject query params with default values', async () =>
request(app)
.get(`${app.basePath}/deep_object?settings[tag_ids][0]=1`)
.expect(200)
Expand All @@ -146,4 +149,19 @@ describe(packageJson.name, () => {
};
expect(r.body).to.deep.equals(expected);
}));

it('should explode deepObject $ref query params with default values', async () =>
request(app)
.get(`${app.basePath}/deep_object_2?settings[tag_ids][0]=1`)
.expect(200)
.then((r) => {
const expected = {
settings: {
tag_ids: [1],
state: 'default',
greeting: 'hello',
},
};
expect(r.body).to.deep.equals(expected);
}));
});

0 comments on commit 60c2abd

Please sign in to comment.