Skip to content

Commit

Permalink
fix: tests for new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
drodil committed Nov 4, 2024
1 parent 5010ced commit 9466902
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
16 changes: 11 additions & 5 deletions plugins/qeta-common/src/api/QetaClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
});

Expand All @@ -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',
},
});
});

Expand Down
9 changes: 7 additions & 2 deletions plugins/qeta-common/src/api/QetaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ 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));
},
),
);
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));
Expand Down

0 comments on commit 9466902

Please sign in to comment.