From c3d18fb78617487456c14e67020d74060ccc448e Mon Sep 17 00:00:00 2001 From: juan ignacio Date: Mon, 18 Sep 2023 10:46:21 -0300 Subject: [PATCH 1/2] refactor update and delete endpoints --- src/api/marketplace/reply/replyApi.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/marketplace/reply/replyApi.ts b/src/api/marketplace/reply/replyApi.ts index 408d313..a176717 100644 --- a/src/api/marketplace/reply/replyApi.ts +++ b/src/api/marketplace/reply/replyApi.ts @@ -33,8 +33,8 @@ export const update = async ( updates: IUpdateReplyDto ): Promise => { try { - const { data } = await marketplaceClient.post( - `/api/bot/reply/${timestamp}`, + const { data } = await marketplaceClient.patch( + `/api/reply/timestamp/${timestamp}`, updates ); return data; @@ -53,7 +53,7 @@ export const update = async ( export const remove = async (timestamp: string): Promise => { 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); From 9b5021715b5d24cd4ccbb465dd22d551d92d5e3e Mon Sep 17 00:00:00 2001 From: juan ignacio Date: Mon, 18 Sep 2023 10:47:14 -0300 Subject: [PATCH 2/2] refactor update and delete tests --- .../reply/__test__/replyApi.spec.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/api/marketplace/reply/__test__/replyApi.spec.ts b/src/api/marketplace/reply/__test__/replyApi.spec.ts index 7d8eccf..ef17533 100644 --- a/src/api/marketplace/reply/__test__/replyApi.spec.ts +++ b/src/api/marketplace/reply/__test__/replyApi.spec.ts @@ -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 ); }); @@ -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, @@ -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 ); }); @@ -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 () => { @@ -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}` + ); }); }); });