Skip to content

Commit

Permalink
fix: Mock interaction type definitions (#387)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
leelaprasadv authored Dec 6, 2024
1 parent 99bb112 commit 94d6d14
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/exports/mock.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,15 +37,15 @@ export interface InteractionResponse {
onCall?: OnCall;
}

export interface OnCall {
[key: number]: Omit<InteractionResponseBase, 'onCall'> & { status: number };
}

export interface RandomDelay {
min: number;
max: number;
}

export interface OnCall {
[key: number]: InteractionResponse
}

export interface InteractionExpectations {
disable?: boolean;
exercised?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions test/component/expects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions test/component/non.crud.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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'));
});

});
2 changes: 1 addition & 1 deletion test/component/response.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 94d6d14

Please sign in to comment.