From 01a35026ea4d83b1463b231c79ec60b507f876c1 Mon Sep 17 00:00:00 2001 From: Ray Vincent Date: Wed, 27 Sep 2023 09:47:32 -0700 Subject: [PATCH] Clean up unit tests --- test/common/app.common.ts | 1 - test/headers.spec.ts | 37 ++++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/test/common/app.common.ts b/test/common/app.common.ts index 9503237e..523948e8 100644 --- a/test/common/app.common.ts +++ b/test/common/app.common.ts @@ -123,7 +123,6 @@ export function routes(app) { res.json({ ...req.body, contentType: req.headers['content-type'], - accept: req.headers['accept'], id: 'new-id', }); }); diff --git a/test/headers.spec.ts b/test/headers.spec.ts index 5598f048..7c3ec860 100644 --- a/test/headers.spec.ts +++ b/test/headers.spec.ts @@ -71,8 +71,8 @@ describe(packageJson.name, () => { }) .expect(200)); - it('should succeed in sending a content-type: "application/json; version=1"', async () => - request(app) + it('should succeed in sending a content-type: "application/json; version=1" in multiple ways', async () =>{ + await request(app) .post(`${app.basePath}/pets_content_types`) .set('Content-Type', 'application/json; version=1') .set('Accept', 'application/json') @@ -83,9 +83,22 @@ describe(packageJson.name, () => { .expect(200) .expect((res) => { expect(res.body.contentType).to.equal('application/json; version=1') - }) - ); + }); + await request(app) + .post(`${app.basePath}/pets_content_types`) + .set('Content-Type', 'application/json;version=1') + .set('Accept', 'application/json') + .send({ + name: 'myPet', + tag: 'cat', + }) + .expect(200) + .expect((res) => { + expect(res.body.contentType).to.equal('application/json;version=1') + }); + }); + it('should throw a 415 error for unsupported "application/json; version=2" content type', async () => request(app) .post(`${app.basePath}/pets_content_types`) @@ -97,8 +110,8 @@ describe(packageJson.name, () => { }) .expect(415)); - it('should succeed in sending a content-type: "application/json;version=1', async () => - request(app) + it('should throw a 415 error for a path/method which has previously succeeded using different request body content types', async () => { + await request(app) .post(`${app.basePath}/pets_content_types`) .set('Content-Type', 'application/json;version=1') .set('Accept', 'application/json') @@ -109,11 +122,9 @@ describe(packageJson.name, () => { .expect(200) .expect((res) => { expect(res.body.contentType).to.equal('application/json;version=1') - }) - ); - - it('should throw a 415 error for a path/method that\'s already been cached', async () => - request(app) + }); + + await request(app) .post(`${app.basePath}/pets_content_types`) .set('Content-Type', 'application/json; version=3') .set('Accept', 'application/json') @@ -121,7 +132,7 @@ describe(packageJson.name, () => { name: 'myPet', tag: 'cat', }) - .expect(415)); - + .expect(415); + }); }); });