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

refactor: Reply API endpoints #61

Merged
merged 2 commits into from
Sep 18, 2023
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
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}`
);
});
});
});
6 changes: 3 additions & 3 deletions src/api/marketplace/reply/replyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const update = async (
updates: IUpdateReplyDto
): Promise<IReplyResponse> => {
try {
const { data } = await marketplaceClient.post<IReplyResponse>(
`/api/bot/reply/${timestamp}`,
const { data } = await marketplaceClient.patch<IReplyResponse>(
`/api/reply/timestamp/${timestamp}`,
updates
);
return data;
Expand All @@ -53,7 +53,7 @@ export const update = async (

export const remove = async (timestamp: string): Promise<void> => {
try {
await marketplaceClient.delete(`/api/bot/reply/${timestamp}`);
await marketplaceClient.delete(`/api/reply/timestamp/${timestamp}`);
} catch (error) {
if (axios.isAxiosError(error)) {
console.error('[replyApi Error: Remove]', error.response);
Expand Down