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

Fix: Remove / when calling search endpoint #5187

Merged
merged 1 commit into from
Jul 2, 2024
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
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
Loading