Skip to content

Commit

Permalink
add reponse serializer tests for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Jun 2, 2024
1 parent 8f7c678 commit bbbd160
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/resources/response.object.serializer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ paths:
id:
type: number

/array-of-date-times:
get:
responses:
200:
description: date-time handler
content:
application/json:
schema:
type: object
properties:
users:
type: array
items:
type: object
properties:
created_at:
type: string
format: date-time
id:
type: number

/date:
get:
responses:
Expand All @@ -41,4 +62,4 @@ components:
id:
type: number
created_at:
$ref: "#/components/schemas/Date"
$ref: "#/components/schemas/Date"
16 changes: 16 additions & 0 deletions test/response.object.serializer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ describe('response serializer', () => {
created_at: date,
});
});
app.get([`${app.basePath}/array-of-date-times`], (req, res) => {
let date = new Date('2020-12-20T07:28:19.213Z');
res.json({
users: [{
id: req.params.id,
created_at: date,
}],
});
});
app.get([`${app.basePath}/date`], (req, res) => {
let date = new Date('2020-12-20T07:28:19.213Z');
res.json({
Expand Down Expand Up @@ -66,5 +75,12 @@ describe('response serializer', () => {
.then((r) => {
expect(r.body.created_at).to.equal('2020-12-20');
}));
it('should validate and serialize date-time in object from array', async () =>
request(app)
.get(`${app.basePath}/array-of-date-times`)
.expect(200)
.then((r) => {
expect(r.body.users[0].created_at).to.equal('2020-12-20T07:28:19.213Z');
}));
});
});

0 comments on commit bbbd160

Please sign in to comment.