Skip to content

Commit

Permalink
Merge branch 'master' into add-workflow-to-auto-pubish-on-npm
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Sep 19, 2023
2 parents 70a57d5 + 591f4b9 commit 4937933
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/pineapple",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
56 changes: 44 additions & 12 deletions test/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,71 @@ describe('upload()', () => {
it('returns an error', async () => {
const formData = new FormData();
formData.append('test', 'test');
const receipt = await upload(formData);
expect(receipt.error.code).toBe(400);
expect(receipt.error.message).toBe('No file submitted');

expect.assertions(1);

await expect(upload(formData)).rejects.toEqual(
expect.objectContaining({
error: expect.objectContaining({
code: 400,
message: 'No file submitted'
})
})
);
});
});

describe('when the file is too big', () => {
it('returns an error', async () => {
const formData = new FormData();
formData.append('file', createReadStream(path.join(__dirname, './fixtures/too-heavy.jpg')));
const receipt = await upload(formData);
expect(receipt.error.code).toBe(400);
expect(receipt.error.message).toBe('File too large');

expect.assertions(1);

await expect(upload(formData)).rejects.toEqual(
expect.objectContaining({
error: expect.objectContaining({
code: 400,
message: 'File too large'
})
})
);
});
});

describe('when the file is not an image', () => {
it('returns an error', async () => {
const formData = new FormData();
formData.append('file', createReadStream(path.join(__dirname, './fixtures/file.json')));
const receipt = await upload(formData);
expect(receipt.error.code).toBe(415);
expect(receipt.error.message).toBe('Unsupported file type');

expect.assertions(1);

await expect(upload(formData)).rejects.toEqual(
expect.objectContaining({
error: expect.objectContaining({
code: 415,
message: 'Unsupported file type'
})
})
);
});
});

describe('on network error', () => {
it('returns an error following the same format as server error', async () => {
const formData = new FormData();
formData.append('file', createReadStream(path.join(__dirname, './fixtures/file.json')));
const receipt = await upload(formData, 'https://pineapple.fyi/not-existing');
expect(receipt.error.code).toBe(404);
expect(receipt.error.message).toBe('Not Found');

expect.assertions(1);

await expect(upload(formData, 'https://pineapple.fyi/not-existing')).rejects.toEqual(
expect.objectContaining({
error: expect.objectContaining({
code: 404,
message: 'Not Found'
})
})
);
});
});
});

0 comments on commit 4937933

Please sign in to comment.