Skip to content

Commit

Permalink
refactor update and delete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRodriguez committed Sep 18, 2023
1 parent c3d18fb commit 9b50217
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/api/marketplace/reply/__test__/replyApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ describe('Marketplace Reply API', () => {

const expectedResponse = expect.objectContaining(updates);

const postMock = jest
.spyOn(marketplaceClient, 'post')
const patchMock = jest
.spyOn(marketplaceClient, 'patch')
.mockResolvedValueOnce({ data: { originalReply, ...updates } });

const response = await replyApi.update(originalReply.timestamp, updates);

expect(response).toEqual(expectedResponse);
expect(postMock).toHaveBeenCalledWith(
`/api/bot/reply/${originalReply.timestamp}`,
expect(patchMock).toHaveBeenCalledWith(
`/api/reply/timestamp/${originalReply.timestamp}`,
updates
);
});
Expand All @@ -120,8 +120,8 @@ describe('Marketplace Reply API', () => {

const expectedErrorMessage = 'Bad Request';

const postMock = jest
.spyOn(marketplaceClient, 'post')
const patchMock = jest
.spyOn(marketplaceClient, 'patch')
.mockRejectedValueOnce(
new AxiosError(
undefined,
Expand All @@ -143,8 +143,8 @@ describe('Marketplace Reply API', () => {
await expect(
replyApi.update(originalReply.timestamp, updates)
).rejects.toThrowError(expectedErrorMessage);
expect(postMock).toHaveBeenCalledWith(
`/api/bot/reply/${originalReply.timestamp}`,
expect(patchMock).toHaveBeenCalledWith(
`/api/reply/timestamp/${originalReply.timestamp}`,
updates
);
});
Expand All @@ -160,7 +160,9 @@ describe('Marketplace Reply API', () => {

await replyApi.remove(timestamp);

expect(deleteMock).toHaveBeenCalledWith(`/api/bot/reply/${timestamp}`);
expect(deleteMock).toHaveBeenCalledWith(
`/api/reply/timestamp/${timestamp}`
);
});

it('should throw an error when deleting a reply fails', async () => {
Expand Down Expand Up @@ -191,7 +193,9 @@ describe('Marketplace Reply API', () => {
await expect(replyApi.remove(timestamp)).rejects.toThrowError(
expectedErrorMessage
);
expect(deleteMock).toHaveBeenCalledWith(`/api/bot/reply/${timestamp}`);
expect(deleteMock).toHaveBeenCalledWith(
`/api/reply/timestamp/${timestamp}`
);
});
});
});

0 comments on commit 9b50217

Please sign in to comment.