feat: validate and persist per-file quality in POST /api/jobs
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -67,6 +67,61 @@ describe('POST /api/jobs', () => {
|
||||
expect(job.originalFilename).toBe('photo.png');
|
||||
expect(job.inputMimeType).toBe('image/png');
|
||||
expect(job.inputSizeBytes).toBeGreaterThan(0);
|
||||
expect(job.quality).toBeNull();
|
||||
});
|
||||
|
||||
it('creates a pending job with a quality level for a supported format', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['jpg']))
|
||||
.field('qualities', JSON.stringify([45]))
|
||||
.attach('files', fixturePath, 'photo.png');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].status).toBe('pending');
|
||||
|
||||
const job = await getJobByUuid(pool, response.body.jobs[0].id);
|
||||
expect(job.quality).toBe(45);
|
||||
});
|
||||
|
||||
it('rejects an out-of-range quality without failing the whole batch', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['jpg']))
|
||||
.field('qualities', JSON.stringify([500]))
|
||||
.attach('files', fixturePath, 'photo.png');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
|
||||
});
|
||||
|
||||
it('rejects a quality value for a format that does not support one', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['gif']))
|
||||
.field('qualities', JSON.stringify([50]))
|
||||
.attach('files', fixturePath, 'photo.png');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
|
||||
});
|
||||
|
||||
it('returns 400 when qualities length does not match the number of files', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['jpg']))
|
||||
.field('qualities', JSON.stringify([10, 20]))
|
||||
.attach('files', fixturePath, 'photo.png');
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
});
|
||||
|
||||
it('rejects a file whose content does not match its extension, without failing the whole batch', async () => {
|
||||
|
||||
Reference in New Issue
Block a user