diff --git a/test/management/tests.util.ts b/test/management/tests.util.ts index 2ba06fbf1..837b0657c 100644 --- a/test/management/tests.util.ts +++ b/test/management/tests.util.ts @@ -72,13 +72,17 @@ export function checkRequestInterceptor(operation: Promise, request: nock. export function checkOperation(operation: Promise>, expectedResponse: T): void { it('should test the method', async () => { const result = await operation; - expect(result.data).toEqual(expectedResponse); + expect(result.data).toEqual( + // only compare if the expected response is defined (api returns data), in this case + // expectedResponse is an empty object + result.data ? expectedResponse : undefined + ); }); } export type CheckMethodParams = { operation: Promise>; - expectedResponse: any; + expectedResponse?: T; uri: string | RegExp | { (uri: string): boolean }; method: string; requestBody?: RequestBodyMatcher | any; @@ -102,22 +106,25 @@ export type CheckMethodParams = { * @param {string} params.method - The HTTP method to intercept (e.g., 'GET', 'POST'). * @param {RequestBodyMatcher | any} [params.requestBody] - The optional request body to match. */ -export const checkMethod = ({ +export const checkMethod = >({ operation, - expectedResponse, uri, method, requestBody, -}: CheckMethodParams): void => { + expectedResponse, +}: MethodParams): void => { + // set the expected response to an empty object if it is not provided + const finalExpectedResponse: T = expectedResponse ?? {}; + // nock the API with success scenario let request: nock.Scope = nock(API_URL) .intercept(uri, method, requestBody) - .reply(200, expectedResponse); + .reply(200, finalExpectedResponse as any); // check for various success checks checkForPromise(operation); checkRequestInterceptor(operation, request); - checkOperation(operation, expectedResponse); + checkOperation(operation, finalExpectedResponse); // nock the API with error scenario request = nock(API_URL).intercept(uri, method, requestBody).reply(500);