feat: enhance import session handling by adding session UUID to commitImport function

This commit is contained in:
Wikid82
2025-11-22 15:58:12 -05:00
parent 185121d9f0
commit 8a60325464
6 changed files with 16 additions and 5 deletions

View File

@@ -27,8 +27,8 @@ export const getImportPreview = async (): Promise<ImportPreview> => {
return data;
};
export const commitImport = async (resolutions: Record<string, string>): Promise<void> => {
await client.post('/import/commit', { resolutions });
export const commitImport = async (sessionUUID: string, resolutions: Record<string, string>): Promise<void> => {
await client.post('/import/commit', { session_uuid: sessionUUID, resolutions });
};
export const cancelImport = async (): Promise<void> => {

View File

@@ -63,6 +63,11 @@ const mockNotifications: api.Notification[] = [
describe('NotificationCenter', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(api.checkUpdates).mockResolvedValue({
available: false,
latest_version: '0.0.0',
changelog_url: '',
})
})
afterEach(() => {

View File

@@ -143,7 +143,7 @@ describe('useImport', () => {
await result.current.commit({ 'test.com': 'skip' })
})
expect(api.commitImport).toHaveBeenCalledWith({ 'test.com': 'skip' })
expect(api.commitImport).toHaveBeenCalledWith('session-2', { 'test.com': 'skip' })
await waitFor(() => {
expect(result.current.session).toBeNull()

View File

@@ -43,7 +43,11 @@ export function useImport() {
});
const commitMutation = useMutation({
mutationFn: (resolutions: Record<string, string>) => commitImport(resolutions),
mutationFn: (resolutions: Record<string, string>) => {
const sessionId = statusQuery.data?.session?.id;
if (!sessionId) throw new Error("No active session");
return commitImport(sessionId, resolutions);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
queryClient.invalidateQueries({ queryKey: ['import-preview'] });