From 257bb2ed03ea79e85e601e06efb3dadd5c1295f9 Mon Sep 17 00:00:00 2001 From: ekremney Date: Thu, 14 Dec 2023 10:46:16 +0100 Subject: [PATCH] chore: nocontent test --- packages/spacecat-shared-utils/src/http-utils.js | 4 ++-- .../spacecat-shared-utils/test/http-utils.test.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/spacecat-shared-utils/src/http-utils.js b/packages/spacecat-shared-utils/src/http-utils.js index 5a0dc25a..c6ed9df3 100644 --- a/packages/spacecat-shared-utils/src/http-utils.js +++ b/packages/spacecat-shared-utils/src/http-utils.js @@ -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) { diff --git a/packages/spacecat-shared-utils/test/http-utils.test.js b/packages/spacecat-shared-utils/test/http-utils.test.js index 3450bb98..ff36167a 100644 --- a/packages/spacecat-shared-utils/test/http-utils.test.js +++ b/packages/spacecat-shared-utils/test/http-utils.test.js @@ -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', () => { @@ -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);