78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
import { FileSystem } from 'react-native-file-access'
|
|
import {
|
|
clearQueuedAudioForUser,
|
|
durableQueueTestContract,
|
|
type DurableQueueItem,
|
|
} from '../src/features/recording/durable-processing-queue'
|
|
|
|
const USER_A = '11111111-1111-4111-8111-111111111111'
|
|
const USER_B = '22222222-2222-4222-8222-222222222222'
|
|
|
|
function item(userId: string, suffix: string): DurableQueueItem {
|
|
const path = `${durableQueueTestContract.queueDirectory}/queued-${suffix}.wav`
|
|
return {
|
|
schemaVersion: 1,
|
|
id: suffix,
|
|
userId,
|
|
meetingId: null,
|
|
path,
|
|
uri: `file://${path}`,
|
|
fileName: `${suffix}.wav`,
|
|
mimeType: 'audio/wav',
|
|
sizeBytes: 5,
|
|
durationMs: 100,
|
|
source: 'recording',
|
|
languageCode: 'ko',
|
|
status: 'retry',
|
|
phase: 'uploading',
|
|
attempts: 1,
|
|
uploadedBytes: 0,
|
|
nextAttemptAtMs: 0,
|
|
lastErrorCode: 'offline',
|
|
lastErrorMessage: 'offline',
|
|
createdAtMs: 1,
|
|
updatedAtMs: 1,
|
|
}
|
|
}
|
|
|
|
const mockFileSystem = FileSystem as typeof FileSystem & {
|
|
filesystem: Map<string, string>
|
|
unlink: jest.Mock
|
|
}
|
|
|
|
describe('logout audio privacy cleanup', () => {
|
|
beforeEach(async () => {
|
|
await AsyncStorage.clear()
|
|
mockFileSystem.filesystem.clear()
|
|
mockFileSystem.unlink.mockClear()
|
|
})
|
|
|
|
test('deletes only the signed-out user files and removes their queue rows', async () => {
|
|
const first = item(USER_A, 'aaa111')
|
|
const second = item(USER_B, 'bbb222')
|
|
mockFileSystem.filesystem.set(first.path, 'audio')
|
|
mockFileSystem.filesystem.set(second.path, 'audio')
|
|
await AsyncStorage.setItem(durableQueueTestContract.storageKey, JSON.stringify([first, second]))
|
|
|
|
await clearQueuedAudioForUser(USER_A)
|
|
|
|
expect(mockFileSystem.filesystem.has(first.path)).toBe(false)
|
|
expect(mockFileSystem.filesystem.has(second.path)).toBe(true)
|
|
expect(JSON.parse((await AsyncStorage.getItem(durableQueueTestContract.storageKey)) ?? '[]'))
|
|
.toEqual([second])
|
|
})
|
|
|
|
test('retains a queue row and rejects when the private file cannot be deleted', async () => {
|
|
const first = item(USER_A, 'ccc333')
|
|
mockFileSystem.filesystem.set(first.path, 'audio')
|
|
await AsyncStorage.setItem(durableQueueTestContract.storageKey, JSON.stringify([first]))
|
|
mockFileSystem.unlink.mockRejectedValueOnce(new Error('filesystem busy'))
|
|
|
|
await expect(clearQueuedAudioForUser(USER_A)).rejects.toThrow('filesystem busy')
|
|
|
|
expect(mockFileSystem.filesystem.has(first.path)).toBe(true)
|
|
expect(JSON.parse((await AsyncStorage.getItem(durableQueueTestContract.storageKey)) ?? '[]'))
|
|
.toEqual([first])
|
|
})
|
|
})
|