-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from adhocteam/cm-wire-frontend-file-upload
Add frontend file upload
- Loading branch information
Showing
13 changed files
with
267 additions
and
84 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
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,15 @@ | ||
import join from 'url-join'; | ||
|
||
const activityReportUrl = join('/', 'api', 'files'); | ||
|
||
export default async function uploadFile(data) { | ||
const res = await fetch(activityReportUrl, { | ||
method: 'POST', | ||
credentials: 'same-origin', | ||
body: data, | ||
}); | ||
if (!res.ok) { | ||
throw new Error(res.statusText); | ||
} | ||
return res; | ||
} |
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,14 @@ | ||
import fetchMock from 'fetch-mock'; | ||
import join from 'url-join'; | ||
import uploadFile from '../File'; | ||
|
||
const activityReportUrl = join('/', 'api', 'files'); | ||
const fakeFile = new File(['testing'], 'test.txt'); | ||
|
||
describe('File fetcher', () => { | ||
it('test that the file gets uploaded', async () => { | ||
fetchMock.mock(activityReportUrl, 200); | ||
const res = await uploadFile(fakeFile); | ||
expect(res.status).toBe(200); | ||
}); | ||
}); |
Oops, something went wrong.