The mobile GDPR export screen (app/backup/export.tsx) called backupService.exportData -> POST /compliance/export-data, an endpoint that never existed on the backend and always 404'd silently (same bug class as the web buttons fixed in 842be56e). Added requestDataExport/getDataExportStatus to backupService.ts and a new utils/dataExportFlow.ts (mirroring web/utils/dataExportFlow.ts) that drives the real async pipeline at /api/v1/data-export (request -> poll status -> download), confirmed live via backend/src/routes/dataExport.ts. Downloads the ready file to local storage with expo-file-system (already a dependency) and hands it to expo-sharing (newly added; no suitable dependency for file sharing already existed) so the user can save or share it via the OS share sheet. Collapsed the screen's fake JSON/CSV format picker to the one format the backend actually produces (JSON) and surfaces every failure (request, poll timeout, download, share) as a visible alert instead of failing silently. Added unit tests for the service calls and the export flow, plus a screen-level test for the button wiring and error paths. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
141 lines
3.7 KiB
JavaScript
141 lines
3.7 KiB
JavaScript
import '@testing-library/jest-native/extend-expect';
|
|
|
|
// Mock AsyncStorage
|
|
jest.mock('@react-native-async-storage/async-storage', () =>
|
|
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
|
|
);
|
|
|
|
// Mock expo-router
|
|
jest.mock('expo-router', () => ({
|
|
useRouter: () => ({
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
back: jest.fn(),
|
|
}),
|
|
useLocalSearchParams: () => ({}),
|
|
useSegments: () => [],
|
|
usePathname: () => '/',
|
|
Link: 'Link',
|
|
Stack: {
|
|
Screen: 'Screen',
|
|
},
|
|
}));
|
|
|
|
// Mock expo-image
|
|
jest.mock('expo-image', () => ({
|
|
Image: 'Image',
|
|
ImageSource: {},
|
|
}));
|
|
|
|
// Mock expo-constants
|
|
jest.mock('expo-constants', () => ({
|
|
__esModule: true,
|
|
default: {
|
|
expoConfig: {
|
|
extra: {},
|
|
},
|
|
easConfig: {},
|
|
},
|
|
}));
|
|
|
|
// Mock expo-sharing (used to let the user save/share a downloaded file)
|
|
jest.mock('expo-sharing', () => ({
|
|
isAvailableAsync: jest.fn(() => Promise.resolve(true)),
|
|
shareAsync: jest.fn(() => Promise.resolve()),
|
|
}));
|
|
|
|
// Mock expo-file-system legacy API (used for downloading the GDPR export to
|
|
// local app storage before handing it to expo-sharing)
|
|
jest.mock('expo-file-system/legacy', () => ({
|
|
cacheDirectory: 'file:///mock-cache/',
|
|
downloadAsync: jest.fn(() =>
|
|
Promise.resolve({ uri: 'file:///mock-cache/mock-export.json', status: 200 })
|
|
),
|
|
getInfoAsync: jest.fn(() => Promise.resolve({ exists: false, isDirectory: false })),
|
|
readDirectoryAsync: jest.fn(() => Promise.resolve([])),
|
|
deleteAsync: jest.fn(() => Promise.resolve()),
|
|
}));
|
|
|
|
// Mock expo-notifications
|
|
jest.mock('expo-notifications', () => ({
|
|
setNotificationHandler: jest.fn(),
|
|
getPermissionsAsync: jest.fn(() => Promise.resolve({ status: 'granted' })),
|
|
requestPermissionsAsync: jest.fn(() => Promise.resolve({ status: 'granted' })),
|
|
getExpoPushTokenAsync: jest.fn(() => Promise.resolve({ data: 'ExponentPushToken[test]' })),
|
|
setNotificationChannelAsync: jest.fn(() => Promise.resolve()),
|
|
addNotificationReceivedListener: jest.fn(() => ({ remove: jest.fn() })),
|
|
addNotificationResponseReceivedListener: jest.fn(() => ({ remove: jest.fn() })),
|
|
cancelAllScheduledNotificationsAsync: jest.fn(() => Promise.resolve()),
|
|
setBadgeCountAsync: jest.fn(() => Promise.resolve()),
|
|
AndroidImportance: {
|
|
MAX: 'max',
|
|
},
|
|
}));
|
|
|
|
// Mock expo-device
|
|
jest.mock('expo-device', () => ({
|
|
isDevice: false,
|
|
deviceName: 'Test Device',
|
|
brand: 'Test',
|
|
modelName: 'Device',
|
|
}));
|
|
|
|
// Mock expo-clipboard
|
|
jest.mock('expo-clipboard', () => ({
|
|
setStringAsync: jest.fn(() => Promise.resolve()),
|
|
}));
|
|
|
|
// Mock expo-video
|
|
jest.mock('expo-video', () => ({
|
|
VideoView: 'VideoView',
|
|
useVideoPlayer: jest.fn(() => ({
|
|
play: jest.fn(),
|
|
pause: jest.fn(),
|
|
loop: false,
|
|
muted: false,
|
|
})),
|
|
}));
|
|
|
|
// Mock expo-image-picker
|
|
jest.mock('expo-image-picker', () => ({
|
|
requestMediaLibraryPermissionsAsync: jest.fn(() =>
|
|
Promise.resolve({ status: 'granted' })
|
|
),
|
|
launchImageLibraryAsync: jest.fn(() =>
|
|
Promise.resolve({
|
|
canceled: false,
|
|
assets: [{ uri: 'file://test-image.jpg' }],
|
|
})
|
|
),
|
|
}));
|
|
|
|
// Mock @react-native-community/netinfo
|
|
jest.mock('@react-native-community/netinfo', () => ({
|
|
fetch: jest.fn(() => Promise.resolve({ isConnected: true })),
|
|
addEventListener: jest.fn(() => jest.fn()),
|
|
}));
|
|
|
|
// Mock expo-haptics
|
|
jest.mock('expo-haptics', () => ({
|
|
ImpactFeedbackStyle: {
|
|
Light: 'light',
|
|
Medium: 'medium',
|
|
Heavy: 'heavy',
|
|
},
|
|
NotificationFeedbackType: {
|
|
Success: 'success',
|
|
Warning: 'warning',
|
|
Error: 'error',
|
|
},
|
|
impactAsync: jest.fn(() => Promise.resolve()),
|
|
notificationAsync: jest.fn(() => Promise.resolve()),
|
|
selectionAsync: jest.fn(() => Promise.resolve()),
|
|
}));
|
|
|
|
// Silence console warnings in tests
|
|
global.console = {
|
|
...console,
|
|
warn: jest.fn(),
|
|
error: jest.fn(),
|
|
};
|