mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 14:54:23 +08:00
perf(nodes): paginate node lists and fetch details directly (#54)
* perf(nodes): paginate node lists and fetch details directly * fix(nodes): preserve Unicode search and page transition state * fix(nodes): validate search using the UTF-8 byte limit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import { beforeEach, expect, it, vi } from 'vitest';
|
||||
import apiClient from '@/lib/services/core/api-client';
|
||||
import { NodeService } from '@/lib/services/openflare/node.service';
|
||||
|
||||
vi.mock('@/lib/services/core/api-client', () => ({
|
||||
default: { get: vi.fn() },
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(apiClient.get).mockReset();
|
||||
});
|
||||
|
||||
it('keeps legacy arrays and requests bounded pages and individual details separately', async () => {
|
||||
vi.mocked(apiClient.get).mockResolvedValue({
|
||||
data: { error_msg: '', data: [] },
|
||||
} as AxiosResponse);
|
||||
await NodeService.listNodes();
|
||||
expect(apiClient.get).toHaveBeenLastCalledWith(
|
||||
'/api/v1/d/nodes/',
|
||||
expect.objectContaining({ params: undefined }),
|
||||
);
|
||||
await NodeService.listNodePage({
|
||||
page: 2,
|
||||
page_size: 20,
|
||||
status: 'online',
|
||||
node_type: 'tunnel_relay',
|
||||
search: 'edge',
|
||||
});
|
||||
expect(apiClient.get).toHaveBeenLastCalledWith(
|
||||
'/api/v1/d/nodes/page',
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
page: 2,
|
||||
page_size: 20,
|
||||
status: 'online',
|
||||
node_type: 'tunnel_relay',
|
||||
search: 'edge',
|
||||
},
|
||||
}),
|
||||
);
|
||||
await NodeService.getNode(42);
|
||||
expect(apiClient.get).toHaveBeenLastCalledWith(
|
||||
'/api/v1/d/nodes/42',
|
||||
expect.objectContaining({ params: undefined }),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user