-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix error not caught by try/catch (#143)
* fix: fix error not caught by try/catch * chore: add e2e tests for upload
- Loading branch information
Showing
9 changed files
with
380 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "Snapshot" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import path from 'path'; | ||
import request from 'supertest'; | ||
|
||
const HOST = `http://localhost:${process.env.PORT || 3003}`; | ||
|
||
describe('GET /upload', () => { | ||
describe('when the image exceed the maximum file size', () => { | ||
it('returns a 400 error', async () => { | ||
const response = await request(HOST) | ||
.post('/upload') | ||
.attach('file', path.join(__dirname, './fixtures/too-heavy.jpg')); | ||
|
||
expect(response.statusCode).toBe(400); | ||
expect(response.body.error.data).toContain('large'); | ||
}); | ||
}); | ||
|
||
describe('when the file is not an image', () => { | ||
it.each([ | ||
['non-image file extension', 'file.json'], | ||
['non-image impersonating image extension', 'json-file.png'] | ||
])('returns a 415 error on %s', async (title, filename) => { | ||
const response = await request(HOST) | ||
.post('/upload') | ||
.attach('file', path.join(__dirname, `./fixtures/${filename}`)); | ||
|
||
expect(response.statusCode).toBe(415); | ||
expect(response.body.error.data).toBe('Unsupported file type'); | ||
}); | ||
}); | ||
|
||
describe('when the file is missing', () => { | ||
it('returns a 400 error', async () => { | ||
const response = await request(HOST).post('/upload'); | ||
|
||
expect(response.statusCode).toBe(400); | ||
expect(response.body.error.data).toBe('no file'); | ||
}); | ||
}); | ||
|
||
describe('when the file is correct', () => { | ||
it('uploads the file and returns a JSO-RPC response with the CID and its provider', async () => { | ||
const response = await request(HOST) | ||
.post('/upload') | ||
.attach('file', path.join(__dirname, './fixtures/valid.png')); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.body.jsonrpc).toBe('2.0'); | ||
expect(response.body.result.cid.length).toBeGreaterThan(10); | ||
expect(['4everland', 'infura', 'fleek', 'pinata']).toContain(response.body.result.provider); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.