Skip to content

Commit

Permalink
chore: nocontent test
Browse files Browse the repository at this point in the history
  • Loading branch information
ekremney committed Dec 14, 2023
1 parent 20e98fa commit 257bb2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/spacecat-shared-utils/src/http-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export function ok(body) {
return createResponse(body, 200);
}

export function noContent(body) {
return createResponse(body, 204);
export function noContent(headers) {
return createResponse('', 204, headers);
}

export function badRequest(message) {
Expand Down
12 changes: 11 additions & 1 deletion packages/spacecat-shared-utils/test/http-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/* eslint-env mocha */
import { expect } from 'chai';
import {
ok, badRequest, notFound, internalServerError,
ok, badRequest, notFound, internalServerError, noContent,
} from '../src/http-utils.js';

describe('http-utils', () => {
Expand All @@ -25,6 +25,16 @@ describe('http-utils', () => {
expect(respJson).to.eql(body);
});

it('ok should return a 204 response with JSON body', async () => {
const headers = { key: 'value' };
const response = noContent(headers);
expect(response.status).to.equal(204);
expect(response.headers.get('content-type')).to.equal('application/json; charset=utf-8');
expect(response.headers.get('key')).to.equal('value');
const respJson = await response.json();
expect(respJson).to.eql('');
});

it('badRequest should return a 400 response with JSON body', async () => {
const response = badRequest('Bad Request');
expect(response.status).to.equal(400);
Expand Down

0 comments on commit 257bb2e

Please sign in to comment.