From bbbd1600fa684d5b1176d26ce4a12b8d0a8e4dc6 Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Sun, 2 Jun 2024 03:31:18 +0000 Subject: [PATCH] add reponse serializer tests for arrays --- .../resources/response.object.serializer.yaml | 23 ++++++++++++++++++- test/response.object.serializer.spec.ts | 16 +++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/test/resources/response.object.serializer.yaml b/test/resources/response.object.serializer.yaml index 3fa1127b..dce9c369 100644 --- a/test/resources/response.object.serializer.yaml +++ b/test/resources/response.object.serializer.yaml @@ -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: @@ -41,4 +62,4 @@ components: id: type: number created_at: - $ref: "#/components/schemas/Date" \ No newline at end of file + $ref: "#/components/schemas/Date" diff --git a/test/response.object.serializer.spec.ts b/test/response.object.serializer.spec.ts index 42247048..ffffeb6c 100644 --- a/test/response.object.serializer.spec.ts +++ b/test/response.object.serializer.spec.ts @@ -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({ @@ -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'); + })); }); });