Skip to content

Commit

Permalink
Fix: Remove / when calling search endpoint (#5187)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesVautier-io authored Jul 2, 2024
1 parent a209b6d commit 31ff364
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
45 changes: 28 additions & 17 deletions quickwit/quickwit-ui/src/services/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,35 @@ import { SearchRequest } from '../utils/models';
import { Client } from './client';

describe('Client unit test', () => {
it('Should build search URL', () => {
it('Should construct correct search URL', async () => {
// Mocking the fetch function to simulate network requests
const mockFetch = jest.fn(() => Promise.resolve({ ok: true, json: () => Promise.resolve({}) }));
(global as any).fetch = mockFetch; // eslint-disable-line @typescript-eslint/no-explicit-any

const searchRequest: SearchRequest = {
indexId: 'my-new-fresh-index-id',
query: 'severity_error:ERROR',
startTimestamp: 100,
endTimestamp: 200,
maxHits: 20,
sortByField: {
field_name: 'timestamp',
order: 'Desc',
},
aggregation: false,
aggregationConfig: {
metric: null,
term: null,
histogram: null,
},
indexId: 'my-new-fresh-index-id',
query: 'severity_error:ERROR',
startTimestamp: 100,
endTimestamp: 200,
maxHits: 20,
sortByField: {
field_name: 'timestamp',
order: 'Desc',
},
aggregation: false,
aggregationConfig: {
metric: null,
term: null,
histogram: null,
},
};
expect(new Client().buildSearchBody(searchRequest, null)).toBe('{"query":"severity_error:ERROR","max_hits":20,"start_timestamp":100,"end_timestamp":200,"sort_by_field":"+timestamp"}');

const client = new Client();
expect(client.buildSearchBody(searchRequest, null)).toBe('{"query":"severity_error:ERROR","max_hits":20,"start_timestamp":100,"end_timestamp":200,"sort_by_field":"+timestamp"}');

await client.search(searchRequest, null);
const expectedUrl = `${client.apiRoot()}my-new-fresh-index-id/search`;
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(expectedUrl, expect.any(Object));
});
});
2 changes: 1 addition & 1 deletion quickwit/quickwit-ui/src/services/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Client {
if (request.indexId === null || request.indexId === undefined) {
throw Error("Search request must have and index id.")
}
const url = `${this.apiRoot()}/${request.indexId}/search`;
const url = `${this.apiRoot()}${request.indexId}/search`;
const body = this.buildSearchBody(request, timestamp_field);
return this.fetch(url, this.defaultGetRequestParams(), body);
}
Expand Down

0 comments on commit 31ff364

Please sign in to comment.