Skip to content

Commit

Permalink
Clean up unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rayvincent2 committed Sep 27, 2023
1 parent 7250470 commit 01a3502
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
1 change: 0 additions & 1 deletion test/common/app.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export function routes(app) {
res.json({
...req.body,
contentType: req.headers['content-type'],
accept: req.headers['accept'],
id: 'new-id',
});
});
Expand Down
37 changes: 24 additions & 13 deletions test/headers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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`)
Expand All @@ -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')
Expand All @@ -109,19 +122,17 @@ 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')
.send({
name: 'myPet',
tag: 'cat',
})
.expect(415));

.expect(415);
});
});
});

0 comments on commit 01a3502

Please sign in to comment.