Skip to content

Commit

Permalink
post image png an jpg
Browse files Browse the repository at this point in the history
  • Loading branch information
HTSagara committed Aug 9, 2024
1 parent dc57462 commit ed4472e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/model/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ class Fragment {
static isSupportedType(value) {
// TODO
const { type } = contentType.parse(value);
return ['text/plain', 'text/markdown', 'text/html', 'application/json'].includes(type);
return [
'text/plain',
'text/markdown',
'text/html',
'application/json',
'image/png',
'image/jpeg',
].includes(type);
}

// /**
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,38 @@ describe('POST /v1/fragments', () => {

expect(res.status).toBe(201);
});

// tests/routes/api/post.test.js

describe('POST /v1/fragments', () => {
// ... existing tests ...

test('should create a PNG image fragment', async () => {
const response = await request(app)
.post('/v1/fragments')
.set('Content-Type', 'image/png')
.auth('user1@email.com', 'password1')
.set('Content-Type', 'text/plain')
.send(Buffer.from('...')); // Use a real PNG binary data or a mock image

expect(response.status).toBe(201);
expect(response.headers['location']).toMatch(/\/v1\/fragments\/\w+/);
expect(response.body.status).toBe('ok');
expect(response.body.fragment).toHaveProperty('id');
});

test('should create a JPEG image fragment', async () => {
const response = await request(app)
.post('/v1/fragments')
.set('Content-Type', 'image/jpeg')
.auth('user1@email.com', 'password1')
.set('Content-Type', 'text/plain')
.send(Buffer.from('...')); // Use a real JPEG binary data or a mock image

expect(response.status).toBe(201);
expect(response.headers['location']).toMatch(/\/v1\/fragments\/\w+/);
expect(response.body.status).toBe('ok');
expect(response.body.fragment).toHaveProperty('id');
});
});
});

0 comments on commit ed4472e

Please sign in to comment.