feat: wire ICO/HEIC/HEIF converters and iconSize validation into the API
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,18 @@ describe('GET /api/formats', () => {
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body.targets).toEqual([]);
|
||||
});
|
||||
|
||||
it('lists ico as a target for png, and does not list heic/heif as a target for anything', async () => {
|
||||
const icoTargets = await request(app).get('/api/formats').query({ source: 'png' });
|
||||
expect(icoTargets.body.targets).toContain('ico');
|
||||
|
||||
const heicTargets = await request(app).get('/api/formats').query({ source: 'heic' });
|
||||
expect(heicTargets.body.targets).toContain('png');
|
||||
|
||||
const pngTargets = await request(app).get('/api/formats').query({ source: 'png' });
|
||||
expect(pngTargets.body.targets).not.toContain('heic');
|
||||
expect(pngTargets.body.targets).not.toContain('heif');
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/jobs', () => {
|
||||
@@ -112,6 +124,88 @@ describe('POST /api/jobs', () => {
|
||||
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
|
||||
});
|
||||
|
||||
it('creates a pending job with an iconSize for an ico target', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['ico']))
|
||||
.field('iconSizes', JSON.stringify([48]))
|
||||
.attach('files', fixturePath, 'photo.png');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].status).toBe('pending');
|
||||
|
||||
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
|
||||
expect(job.iconSize).toBe(48);
|
||||
});
|
||||
|
||||
it('rejects an iconSize outside the fixed set', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['ico']))
|
||||
.field('iconSizes', JSON.stringify([100]))
|
||||
.attach('files', fixturePath, 'photo.png');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].error).toMatch(/Invalid iconSize/);
|
||||
});
|
||||
|
||||
it('rejects an iconSize for a non-ico target', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['webp']))
|
||||
.field('iconSizes', JSON.stringify([48]))
|
||||
.attach('files', fixturePath, 'photo.png');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].error).toMatch(/Invalid iconSize/);
|
||||
});
|
||||
|
||||
it('rejects a quality value for an ico target', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['ico']))
|
||||
.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('creates a pending job converting a HEIC upload to jpg', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.heic');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['jpg']))
|
||||
.attach('files', fixturePath, 'photo.heic');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].status).toBe('pending');
|
||||
|
||||
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
|
||||
expect(job.sourceFormat).toBe('heic');
|
||||
});
|
||||
|
||||
it('creates a pending job converting a HEIF-declared upload to png', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.heif');
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['png']))
|
||||
.attach('files', fixturePath, 'photo.heif');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].status).toBe('pending');
|
||||
});
|
||||
|
||||
it('returns 400 when qualities length does not match the number of files', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user