Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Mock interaction type definitions #387

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading