Support multi-source content asset filtering end-to-end
This commit is contained in:
35
frontend/src/hooks/__tests__/useContentAssets.test.ts
Normal file
35
frontend/src/hooks/__tests__/useContentAssets.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import { useContentAssets } from '../useContentAssets';
|
||||
|
||||
const getTokenMock = jest.fn();
|
||||
|
||||
jest.mock('@clerk/clerk-react', () => ({
|
||||
useAuth: () => ({ getToken: getTokenMock }),
|
||||
}));
|
||||
|
||||
describe('useContentAssets', () => {
|
||||
beforeEach(() => {
|
||||
getTokenMock.mockResolvedValue('test-token');
|
||||
global.fetch = jest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ assets: [], total: 0, limit: 100, offset: 0 }),
|
||||
} as Response);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('sends all source_module values as repeated query params', async () => {
|
||||
renderHook(() =>
|
||||
useContentAssets({ source_module: ['blog_writer', 'youtube'], limit: 50, offset: 0 })
|
||||
);
|
||||
|
||||
await waitFor(() => expect(global.fetch).toHaveBeenCalled());
|
||||
|
||||
const calledUrl = (global.fetch as jest.Mock).mock.calls[0][0] as string;
|
||||
const params = new URL(calledUrl).searchParams;
|
||||
|
||||
expect(params.getAll('source_module')).toEqual(['blog_writer', 'youtube']);
|
||||
});
|
||||
});
|
||||
@@ -29,7 +29,7 @@ export interface ContentAsset {
|
||||
|
||||
export interface AssetFilters {
|
||||
asset_type?: 'text' | 'image' | 'video' | 'audio';
|
||||
source_module?: string | string[]; // Support single or multiple source modules
|
||||
source_module?: string | string[]; // Supports single or multiple source modules
|
||||
search?: string;
|
||||
tags?: string[];
|
||||
favorites_only?: boolean;
|
||||
@@ -146,8 +146,10 @@ export const useContentAssets = (filters: AssetFilters = {}) => {
|
||||
if (currentFilters.source_module) {
|
||||
// Handle both string and array cases
|
||||
if (Array.isArray(currentFilters.source_module)) {
|
||||
// For arrays, use the first value (backend doesn't support multiple yet)
|
||||
params.append('source_module', currentFilters.source_module[0]);
|
||||
// Send every selected source module as repeated query params
|
||||
currentFilters.source_module.forEach((module) => {
|
||||
params.append('source_module', module);
|
||||
});
|
||||
} else {
|
||||
params.append('source_module', currentFilters.source_module);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user