From 37a1593f7f495d68c0e86519337dcec3d37c83bc Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:31:37 +0530 Subject: [PATCH 1/4] Fix mock interation response type interface when onCall is present --- src/exports/mock.d.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/exports/mock.d.ts b/src/exports/mock.d.ts index 5508d35..8854596 100644 --- a/src/exports/mock.d.ts +++ b/src/exports/mock.d.ts @@ -22,10 +22,13 @@ 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; file?: string; fixedDelay?: number; @@ -39,7 +42,12 @@ export interface RandomDelay { } export interface OnCall { - [key: number]: InteractionResponse + [key: number]: Omit & { status: number }; +} + +export interface RandomDelay { + min: number; + max: number; } export interface InteractionExpectations { From ae604676da89a6b3535e6ea0ed9c66f2021f6742 Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:34:02 +0530 Subject: [PATCH 2/4] Revert duplicate interface in mock --- src/exports/mock.d.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/exports/mock.d.ts b/src/exports/mock.d.ts index 8854596..a3594a9 100644 --- a/src/exports/mock.d.ts +++ b/src/exports/mock.d.ts @@ -36,11 +36,6 @@ export interface InteractionResponseBase { onCall?: OnCall; } -export interface RandomDelay { - min: number; - max: number; -} - export interface OnCall { [key: number]: Omit & { status: number }; } From 314b213e0054d3d9e6a7184fd56ddd631dc4c3ef Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:35:13 +0530 Subject: [PATCH 3/4] Add missing cookies attribute to InteractionResponseBase --- src/exports/mock.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/exports/mock.d.ts b/src/exports/mock.d.ts index a3594a9..7029536 100644 --- a/src/exports/mock.d.ts +++ b/src/exports/mock.d.ts @@ -29,6 +29,7 @@ export type InteractionResponse = ( export interface InteractionResponseBase { headers?: object; + cookies?: object; body?: any; file?: string; fixedDelay?: number; From 56fd36cc9740e02f206c2a43888efe0b104ce29b Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:33:50 +0530 Subject: [PATCH 4/4] Fix assertions for changes in node v20.18.1 --- test/component/expects.spec.js | 4 ++-- test/component/non.crud.spec.js | 4 ++-- test/component/response.spec.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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 () => {