Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/services/exportImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('exportImport', () => {
mockGetAllAsync.mockClear();
});

it('rejects backups that are not valid JSON', async () => {
await expect(importAllData('not json')).rejects.toThrow('not valid JSON');
});

it('rejects backups that are missing required data', async () => {
await expect(importAllData('{}')).rejects.toThrow('missing required data');
});
Expand Down
7 changes: 6 additions & 1 deletion src/services/exportImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export async function exportAllData(): Promise<string> {
}

export async function importAllData(json: string) {
const parsed = JSON.parse(json) as Partial<JobOpsBackup>;
let parsed: Partial<JobOpsBackup>;
try {
parsed = JSON.parse(json) as Partial<JobOpsBackup>;
} catch {
throw new Error('This backup is not valid JSON.');
}
if (!Array.isArray(parsed.applications) || !Array.isArray(parsed.resume_versions) || !Array.isArray(parsed.status_history) || !Array.isArray(parsed.reminders)) {
throw new Error('This backup is missing required data.');
}
Expand Down
Loading