77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import { SqliteStorage } from '../src/index.js';
|
|
import { cleanupDir, createDbPath, createTempDir } from './helpers.js';
|
|
|
|
describe('SqliteStorage', () => {
|
|
it('creates, updates, and completes jobs', () => {
|
|
const dir = createTempDir();
|
|
const storage = new SqliteStorage<{ url: string }>(createDbPath(dir));
|
|
|
|
try {
|
|
const job = storage.createJob(
|
|
'job-1',
|
|
{ url: 'https://example.com' },
|
|
[
|
|
{
|
|
name: 'download',
|
|
status: 'pending',
|
|
progress: 0,
|
|
message: null,
|
|
startedAt: null,
|
|
completedAt: null,
|
|
error: null,
|
|
},
|
|
],
|
|
{},
|
|
3,
|
|
);
|
|
|
|
expect(job.status).toBe('pending');
|
|
expect(storage.claimPendingJob(job.id)).toBe(true);
|
|
|
|
const inProgress = storage.saveProgress(
|
|
job.id,
|
|
'download',
|
|
[
|
|
{
|
|
name: 'download',
|
|
status: 'active',
|
|
progress: 50,
|
|
message: 'halfway',
|
|
startedAt: new Date().toISOString(),
|
|
completedAt: null,
|
|
error: null,
|
|
},
|
|
],
|
|
50,
|
|
'halfway',
|
|
);
|
|
|
|
expect(inProgress.status).toBe('active');
|
|
expect(inProgress.progress).toBe(50);
|
|
|
|
const completed = storage.completeJob(
|
|
job.id,
|
|
[
|
|
{
|
|
name: 'download',
|
|
status: 'completed',
|
|
progress: 100,
|
|
message: null,
|
|
startedAt: new Date().toISOString(),
|
|
completedAt: new Date().toISOString(),
|
|
error: null,
|
|
},
|
|
],
|
|
{ download: { filePath: '/tmp/file' } },
|
|
);
|
|
|
|
expect(completed.status).toBe('completed');
|
|
expect(completed.progress).toBe(100);
|
|
expect(completed.phaseResults.download).toEqual({ filePath: '/tmp/file' });
|
|
} finally {
|
|
storage.close();
|
|
cleanupDir(dir);
|
|
}
|
|
});
|
|
});
|