-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
137 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ coverage | |
.png | ||
/allure-report | ||
/allure-results | ||
|
||
.envrc |
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,38 @@ | ||
import FormData from 'form-data' | ||
import { readFile } from 'node:fs/promises' | ||
|
||
import { | ||
initiateUpload, | ||
uploadFile, | ||
uploadStatus | ||
} from '~/src/helpers/uploader-fetch' | ||
|
||
async function createPayload(filename) { | ||
const file = await readFile(`./${filename}`) | ||
const payload = new FormData() | ||
payload.append('field1', 'val1') | ||
payload.append('field2', 'val2') | ||
payload.append('file1', file, filename) | ||
return payload | ||
} | ||
|
||
async function findFileDetails(statusUrl) { | ||
const { uploadDetails } = await uploadStatus(statusUrl) | ||
expect(uploadDetails.files).toBeDefined() | ||
expect(uploadDetails.files.length).toEqual(1) | ||
return { | ||
rejectedFiles: uploadDetails.numberOfRejectedFiles, | ||
uploadStatus: uploadDetails.uploadStatus, | ||
fileDetails: uploadDetails?.files[0] | ||
} | ||
} | ||
|
||
async function initiateAndUpload(filename, initiatePayload) { | ||
const { uploadId, uploadUrl, statusUrl } = | ||
await initiateUpload(initiatePayload) | ||
const payload = await createPayload(filename) | ||
const { uploadStatusCode, location } = await uploadFile(uploadUrl, payload) | ||
return { uploadId, uploadStatusCode, statusUrl, location } | ||
} | ||
|
||
export { createPayload, findFileDetails, initiateAndUpload } |
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,45 @@ | ||
import fetch from 'node-fetch' | ||
|
||
import { config } from '~/src/config' | ||
|
||
const uploaderBaseUrl = config.get('uploaderBaseUrl') | ||
|
||
async function initiateUpload(payload) { | ||
return await fetch(`${uploaderBaseUrl}/initiate`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(payload) | ||
}) | ||
.then((response) => response.json()) | ||
.then((body) => { | ||
return { | ||
uploadId: body.uploadId, | ||
uploadUrl: body.uploadAndScanUrl, | ||
statusUrl: body.statusUrl | ||
} | ||
}) | ||
} | ||
async function uploadFile(uploadUrl, payload) { | ||
return await fetch(uploadUrl, { | ||
method: 'POST', | ||
redirect: 'manual', | ||
body: payload | ||
}).then((response) => { | ||
return { | ||
uploadStatusCode: response.status, | ||
location: response.headers.get('location') | ||
} | ||
}) | ||
} | ||
|
||
async function uploadStatus(statusUrl) { | ||
const response = await fetch(statusUrl, { method: 'GET' }) | ||
const payload = await response.json() | ||
return { | ||
uploadDetails: payload | ||
} | ||
} | ||
|
||
export { initiateUpload, uploadFile, uploadStatus } |
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