From 94d6d14d522fafdbcce61ebb7bff12b0924b9268 Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:42:06 +0530 Subject: [PATCH] fix: Mock interaction type definitions (#387) * Fix mock interation response type interface when onCall is present * Revert duplicate interface in mock * Add missing cookies attribute to InteractionResponseBase * Fix assertions for changes in node v20.18.1 --- src/exports/mock.d.ts | 16 ++++++++++------ test/component/expects.spec.js | 4 ++-- test/component/non.crud.spec.js | 4 ++-- test/component/response.spec.js | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/exports/mock.d.ts b/src/exports/mock.d.ts index 5508d35..7029536 100644 --- a/src/exports/mock.d.ts +++ b/src/exports/mock.d.ts @@ -22,8 +22,12 @@ export interface InteractionRequest extends CommonInteractionRequest { form?: object; } -export interface InteractionResponse { - status: number; +export type InteractionResponse = ( + { onCall: OnCall; status?: number } // If onCall is present, status is optional + | (InteractionResponseBase & { status: number }) // If onCall is absent, status is required +); + +export interface InteractionResponseBase { headers?: object; cookies?: object; body?: any; @@ -33,15 +37,15 @@ export interface InteractionResponse { onCall?: OnCall; } +export interface OnCall { + [key: number]: Omit & { status: number }; +} + export interface RandomDelay { min: number; max: number; } -export interface OnCall { - [key: number]: InteractionResponse -} - export interface InteractionExpectations { disable?: boolean; exercised?: boolean; diff --git a/test/component/expects.spec.js b/test/component/expects.spec.js index b67bf9c..0699281 100644 --- a/test/component/expects.spec.js +++ b/test/component/expects.spec.js @@ -134,7 +134,7 @@ describe('Expects', () => { } catch (error) { err = error; } - expect(err.message).equals('HTTP status 404 !== 200'); + expect(err.message).to.satisfy(msg => msg.startsWith('HTTP status 404 !== 200')); }); it('failed status code with custom message', async () => { @@ -148,7 +148,7 @@ describe('Expects', () => { } catch (error) { err = error; } - expect(err.message).equals(`${customMessage}\n HTTP status 404 !== 200`); + expect(err.message).to.satisfy(msg => msg.startsWith((`${customMessage}\n HTTP status 404 !== 200`))); }); it('header key not found', async () => { diff --git a/test/component/non.crud.spec.js b/test/component/non.crud.spec.js index c97ff05..078e497 100644 --- a/test/component/non.crud.spec.js +++ b/test/component/non.crud.spec.js @@ -48,7 +48,7 @@ describe('Non CRUD Requests - Numbered Waits', () => { } catch (error) { err = error } - expect(err.message).equals('HTTP status 404 !== 200'); + expect(err.message).to.satisfy(msg => msg.startsWith('HTTP status 404 !== 200')); }); it('should fail when bg interactions are not exercised without any waits', async () => { @@ -161,7 +161,7 @@ describe('Non CRUD Requests - Wait Handlers', () => { } catch (error) { err = error; } - expect(err.message).equals('HTTP status 404 !== 500'); + expect(err.message).to.satisfy(msg => msg.startsWith('HTTP status 404 !== 500')); }); }); \ No newline at end of file diff --git a/test/component/response.spec.js b/test/component/response.spec.js index dafbe16..ab9494c 100644 --- a/test/component/response.spec.js +++ b/test/component/response.spec.js @@ -21,7 +21,7 @@ describe('Response', () => { } catch (error) { err = error; } - expect(err.message).equals('HTTP status 404 !== 200'); + expect(err.message).to.satisfy(msg => msg.startsWith('HTTP status 404 !== 200')); }); it('with default expected response status - override value', async () => {