This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new addFiles and addLinks methods (#47)
* chore: refactor module internals II * Unit tests for model items * Unit tests for item actions * Better text for adding files * Refactor duplicated code * Use snapshot for error check
- Loading branch information
1 parent
b9ffa54
commit cde6562
Showing
52 changed files
with
1,190 additions
and
388 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createWTClient function should throw and error when no API KEY is provided 1`] = `[Error: No API Key provided]`; |
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Authorize method should throw an error if request fails 1`] = `[Error: The authorization call failed and no usable JWT could be found there. Please check your API Key.]`; |
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
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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Add files action should create an add items request 1`] = ` | ||
Array [ | ||
RemoteFile { | ||
"content_identifier": "file", | ||
"id": "random-hash", | ||
"local_identifier": "delightful-cat", | ||
"meta": Object { | ||
"multipart_parts": 3, | ||
"multipart_upload_id": "some.random-id--", | ||
}, | ||
"name": "kittie.gif", | ||
"size": 195906, | ||
"transfer": RemoteTransfer { | ||
"items": Array [ | ||
[Circular], | ||
], | ||
}, | ||
}, | ||
] | ||
`; |
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Add items action should create an add items request 1`] = ` | ||
Array [ | ||
RemoteFile { | ||
"content_identifier": "file", | ||
"id": "random-hash", | ||
"local_identifier": "delightful-cat", | ||
"meta": Object { | ||
"multipart_parts": 3, | ||
"multipart_upload_id": "some.random-id--", | ||
}, | ||
"name": "kittie.gif", | ||
"size": 195906, | ||
}, | ||
RemoteLink { | ||
"content_identifier": "web_content", | ||
"id": "random-hash", | ||
"meta": Object { | ||
"title": "WeTransfer", | ||
}, | ||
}, | ||
] | ||
`; |
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,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Add links action should create an add items request 1`] = ` | ||
Array [ | ||
RemoteLink { | ||
"content_identifier": "web_content", | ||
"id": "random-hash", | ||
"meta": Object { | ||
"title": "WeTransfer", | ||
}, | ||
"transfer": RemoteTransfer { | ||
"items": Array [ | ||
[Circular], | ||
], | ||
}, | ||
}, | ||
] | ||
`; |
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Send items action should throw an error if items are not provided 1`] = `[Error: There was an error when adding items to the transfer.]`; |
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Upload file action should throw an error if request fails 1`] = `[Error: There was an error when uploading kittie.gif.]`; |
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,46 @@ | ||
const addFilesAction = require('../../../src/items/actions/add-files'); | ||
const { futureFile, RemoteFile } = require('../../../src/items/models'); | ||
const { RemoteTransfer } = require('../../../src/transfer/models'); | ||
|
||
describe('Add files action', () => { | ||
let addFiles = null; | ||
let sendItems = null; | ||
let transfer = null; | ||
beforeEach(() => { | ||
sendItems = jest.fn().mockReturnValue([ | ||
{ | ||
id: 'random-hash', | ||
content_identifier: 'file', | ||
local_identifier: 'delightful-cat', | ||
meta: { | ||
multipart_parts: 3, | ||
multipart_upload_id: 'some.random-id--' | ||
}, | ||
name: 'kittie.gif', | ||
size: 195906, | ||
upload_id: 'more.random-ids--', | ||
upload_expires_at: 1520410633 | ||
} | ||
]); | ||
|
||
addFiles = addFilesAction({ | ||
sendItems, | ||
futureFile, | ||
RemoteFile | ||
}); | ||
|
||
transfer = new RemoteTransfer(); | ||
}); | ||
|
||
it('should create an add items request', async () => { | ||
const linkFiles = await addFiles(transfer, [ | ||
{ | ||
url: 'https://wetransfer.com', | ||
meta: { | ||
title: 'WeTransfer' | ||
} | ||
} | ||
]); | ||
expect(linkFiles).toMatchSnapshot(); | ||
}); | ||
}); |
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,55 @@ | ||
const addItemsAction = require('../../../src/items/actions/add-items'); | ||
const { | ||
normalizeItem, | ||
normalizeResponseItem | ||
} = require('../../../src/items/models'); | ||
|
||
describe('Add items action', () => { | ||
let addItems = null; | ||
let sendItems = null; | ||
beforeEach(() => { | ||
sendItems = jest.fn().mockReturnValue([ | ||
{ | ||
id: 'random-hash', | ||
content_identifier: 'file', | ||
local_identifier: 'delightful-cat', | ||
meta: { | ||
multipart_parts: 3, | ||
multipart_upload_id: 'some.random-id--' | ||
}, | ||
name: 'kittie.gif', | ||
size: 195906, | ||
upload_id: 'more.random-ids--', | ||
upload_expires_at: 1520410633 | ||
}, | ||
{ | ||
id: 'random-hash', | ||
content_identifier: 'web_content', | ||
meta: { | ||
title: 'WeTransfer' | ||
}, | ||
url: 'https://wetransfer.com' | ||
} | ||
]); | ||
|
||
addItems = addItemsAction({ | ||
sendItems, | ||
normalizeItem, | ||
normalizeResponseItem | ||
}); | ||
}); | ||
|
||
it('should create an add items request', async () => { | ||
const items = await addItems('transfer-id', [ | ||
{ | ||
local_identifier: 'wetransfer.com', | ||
content_identifier: 'web_content', | ||
url: 'https://wetransfer.com', | ||
meta: { | ||
title: 'WeTransfer' | ||
} | ||
} | ||
]); | ||
expect(items).toMatchSnapshot(); | ||
}); | ||
}); |
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,41 @@ | ||
const addLinksAction = require('../../../src/items/actions/add-links'); | ||
const { futureLink, RemoteLink } = require('../../../src/items/models'); | ||
const { RemoteTransfer } = require('../../../src/transfer/models'); | ||
|
||
describe('Add links action', () => { | ||
let addLinks = null; | ||
let sendItems = null; | ||
let transfer = null; | ||
beforeEach(() => { | ||
sendItems = jest.fn().mockReturnValue([ | ||
{ | ||
id: 'random-hash', | ||
content_identifier: 'web_content', | ||
meta: { | ||
title: 'WeTransfer' | ||
}, | ||
url: 'https://wetransfer.com' | ||
} | ||
]); | ||
|
||
addLinks = addLinksAction({ | ||
sendItems, | ||
futureLink, | ||
RemoteLink | ||
}); | ||
|
||
transfer = new RemoteTransfer(); | ||
}); | ||
|
||
it('should create an add items request', async () => { | ||
const linkItems = await addLinks(transfer, [ | ||
{ | ||
url: 'https://wetransfer.com', | ||
meta: { | ||
title: 'WeTransfer' | ||
} | ||
} | ||
]); | ||
expect(linkItems).toMatchSnapshot(); | ||
}); | ||
}); |
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,26 @@ | ||
const routes = require('../../../src/config/routes'); | ||
const sendItemsAction = require('../../../src/items/actions/send-items'); | ||
|
||
describe('Send items action', () => { | ||
let sendItems = null; | ||
const mocks = {}; | ||
beforeEach(() => { | ||
mocks.request = { send: jest.fn() }; | ||
mocks.request.send.mockReturnValue(() => | ||
Promise.reject(new Error('Network error.')) | ||
); | ||
|
||
sendItems = sendItemsAction({ | ||
routes, | ||
request: mocks.request | ||
}); | ||
}); | ||
|
||
it('should throw an error if items are not provided', async () => { | ||
try { | ||
await sendItems(); | ||
} catch (error) { | ||
expect(error).toMatchSnapshot(); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.