diff --git a/packages/spacecat-shared-http-utils/src/index.d.ts b/packages/spacecat-shared-http-utils/src/index.d.ts index d02e8826..7394a608 100644 --- a/packages/spacecat-shared-http-utils/src/index.d.ts +++ b/packages/spacecat-shared-http-utils/src/index.d.ts @@ -15,6 +15,8 @@ export declare function ok(body?: string): Response; export declare function created(body: object): Response; +export declare function accepted(body: object): Response; + export declare function noContent(headers?: object): Response; export declare function badRequest(message?: string, headers?: object): Response; diff --git a/packages/spacecat-shared-http-utils/src/index.js b/packages/spacecat-shared-http-utils/src/index.js index 77520892..302d67aa 100644 --- a/packages/spacecat-shared-http-utils/src/index.js +++ b/packages/spacecat-shared-http-utils/src/index.js @@ -58,6 +58,10 @@ export function created(body) { return createResponse(body, 201); } +export function accepted(body) { + return createResponse(body, 202); +} + export function noContent(headers = {}) { return createResponse('', 204, headers); } diff --git a/packages/spacecat-shared-http-utils/test/index.test.js b/packages/spacecat-shared-http-utils/test/index.test.js index b0c536ed..c5c8c102 100644 --- a/packages/spacecat-shared-http-utils/test/index.test.js +++ b/packages/spacecat-shared-http-utils/test/index.test.js @@ -14,6 +14,7 @@ import { expect } from 'chai'; import { ok, badRequest, notFound, internalServerError, noContent, found, created, createResponse, unauthorized, forbidden, + accepted, } from '../src/index.js'; async function testMethod(response, expectedCode, expectedBody) { @@ -59,6 +60,12 @@ describe('HTTP Response Functions', () => { await testMethod(response, 201, body); }); + it('accepted should return a 202 ACCEPTED response with custom body', async () => { + const body = { status: 'ACCEPTED' }; + const response = await accepted(body); + await testMethod(response, 202, body); + }); + it('noContent should return a 204 No Content response with default headers', async () => { const response = await noContent(); expect(response.status).to.equal(204);