From 9466902917d422496c5d0954bf66547e74dc01e3 Mon Sep 17 00:00:00 2001 From: Heikki Hellgren Date: Mon, 4 Nov 2024 13:05:11 +0200 Subject: [PATCH] fix: tests for new endpoints --- plugins/qeta-common/src/api/QetaClient.test.ts | 16 +++++++++++----- plugins/qeta-common/src/api/QetaClient.ts | 9 +++++++-- .../collators/DefaultQetaCollatorFactory.test.ts | 8 ++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/plugins/qeta-common/src/api/QetaClient.test.ts b/plugins/qeta-common/src/api/QetaClient.test.ts index 6e33c960..6bd65928 100644 --- a/plugins/qeta-common/src/api/QetaClient.test.ts +++ b/plugins/qeta-common/src/api/QetaClient.test.ts @@ -27,8 +27,10 @@ describe('QetaClient', () => { const result = await client.getPosts({}); expect(result).toEqual({ posts: [], total: 0 }); - expect(mockFetch).toHaveBeenCalledWith('http://example.com/posts', { - method: 'GET', + expect(mockFetch).toHaveBeenCalledWith('http://example.com/posts/query', { + method: 'POST', + body: JSON.stringify({}), + headers: { 'Content-Type': 'application/json' }, }); }); @@ -40,9 +42,13 @@ describe('QetaClient', () => { const result = await client.getPosts({}, { token: 'token' }); expect(result).toEqual({ posts: [], total: 0 }); - expect(mockFetch).toHaveBeenCalledWith('http://example.com/posts', { - method: 'GET', - headers: { Authorization: 'Bearer token' }, + expect(mockFetch).toHaveBeenCalledWith('http://example.com/posts/query', { + method: 'POST', + body: JSON.stringify({}), + headers: { + Authorization: 'Bearer token', + 'Content-Type': 'application/json', + }, }); }); diff --git a/plugins/qeta-common/src/api/QetaClient.ts b/plugins/qeta-common/src/api/QetaClient.ts index d426f532..99eb01ca 100644 --- a/plugins/qeta-common/src/api/QetaClient.ts +++ b/plugins/qeta-common/src/api/QetaClient.ts @@ -1215,10 +1215,15 @@ export class QetaClient implements QetaApi { return this.fetchApi.fetch(url, { method: 'GET', + ...reqInit, ...(requestOptions?.token - ? { headers: { Authorization: `Bearer ${requestOptions.token}` } } + ? { + headers: { + Authorization: `Bearer ${requestOptions.token}`, + ...reqInit.headers, + }, + } : undefined), - ...reqInit, }); }; diff --git a/plugins/search-backend-module-qeta/src/collators/DefaultQetaCollatorFactory.test.ts b/plugins/search-backend-module-qeta/src/collators/DefaultQetaCollatorFactory.test.ts index ac9f1470..dad9a39e 100644 --- a/plugins/search-backend-module-qeta/src/collators/DefaultQetaCollatorFactory.test.ts +++ b/plugins/search-backend-module-qeta/src/collators/DefaultQetaCollatorFactory.test.ts @@ -90,8 +90,8 @@ describe('DefaultQetaCollatorFactory', () => { lastRequest = null; worker.use( - rest.get( - 'http://test-backend/api/qeta/posts', + rest.post( + 'http://test-backend/api/qeta/posts/query', (req: any, res: any, ctx: any) => { lastRequest = req; return res(ctx.status(200), ctx.json(mockPosts)); @@ -99,8 +99,8 @@ describe('DefaultQetaCollatorFactory', () => { ), ); worker.use( - rest.get( - 'http://test-backend/api/qeta/collections', + rest.post( + 'http://test-backend/api/qeta/collections/query', (req: any, res: any, ctx: any) => { lastRequest = req; return res(ctx.status(200), ctx.json(mockCollections));