-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
5d6dbaa
commit a06d937
Showing
4 changed files
with
96 additions
and
7 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,63 @@ | ||
import { | ||
cleanUpApplicants, | ||
cleanUpWebhooks, | ||
createApplicant, | ||
repeatRequestUntilTaskOutputChanges, | ||
createWorkflowRunWithCustomInputs, | ||
onfido, | ||
sleep | ||
} from "../test-helpers"; | ||
|
||
import { WorkflowRunBuilder } from "onfido-node"; | ||
|
||
afterAll(() => { | ||
return Promise.all([cleanUpApplicants(), cleanUpWebhooks()]); | ||
}); | ||
|
||
it("downloads a signed document file", async () => { | ||
function sleep(milliseconds) { | ||
const date = Date.now(); | ||
let currentDate = null; | ||
do { | ||
currentDate = Date.now(); | ||
} while (currentDate - date < milliseconds); | ||
} | ||
const applicant = (await createApplicant()).data; | ||
|
||
const workflowRunBuilder: WorkflowRunBuilder = { | ||
applicant_id: applicant.id, | ||
workflow_id: "8b74614f-9e7f-42fd-852a-5f2bcc852587", | ||
custom_data: { | ||
country_of_operation: "GBR", | ||
document_date_of_expiry: "2022-01-01", | ||
document_issuing_country: "FRA", | ||
document_issuing_date: "2022-01-01", | ||
document_number: "Example string", | ||
document_to_sign_url: | ||
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", | ||
document_type: "driving_licence" | ||
} | ||
}; | ||
|
||
const workflowRun = await createWorkflowRunWithCustomInputs( | ||
workflowRunBuilder | ||
); | ||
const taskId = (await onfido.listTasks(workflowRun.data.id)).data[0].id; | ||
|
||
const output = ( | ||
await repeatRequestUntilTaskOutputChanges( | ||
"findTask", | ||
[workflowRun.data.id, taskId], | ||
10, | ||
3000 | ||
) | ||
)["output"]; | ||
|
||
const fileId = output["properties"]["signed_documents"][0]["id"]; | ||
|
||
const file = await onfido.downloadQesDocument(workflowRun.data.id, fileId); | ||
|
||
expect(file.status).toEqual(200); | ||
expect(file.headers["content-type"]).toEqual("application/pdf"); | ||
expect(file.data.buffer.slice(0, 5)).toEqual("%PDF-"); | ||
}); |
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ export const exampleApplicant: Applicant = { | |
href: "/v3.6/applicants/123-abc", | ||
first_name: "Test", | ||
last_name: "Applicant", | ||
email: null, | ||
email: "[email protected]", | ||
dob: null, | ||
id_numbers: [], | ||
address: { | ||
|
@@ -34,7 +34,7 @@ export const exampleApplicant: Applicant = { | |
line2: null, | ||
line3: null | ||
}, | ||
phone_number: null, | ||
phone_number: "351911111111", | ||
location: { | ||
ip_address: "127.0.0.1", | ||
country_of_residence: "GBR" | ||
|
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 |
---|---|---|
|
@@ -57,6 +57,8 @@ export async function createApplicant(overrideProperties = {}) { | |
ip_address: "127.0.0.1", | ||
country_of_residence: "GBR" | ||
}, | ||
email: "[email protected]", | ||
phone_number: "351911111111", | ||
...overrideProperties | ||
}); | ||
} | ||
|
@@ -101,7 +103,11 @@ export async function uploadLivePhoto( | |
) { | ||
let buffer = readFileSync("test/media/sample_photo.png"); | ||
|
||
return onfido.uploadLivePhoto(applicant.id, new FileTransfer(buffer, "sample_photo.png"), advancedValidation); | ||
return onfido.uploadLivePhoto( | ||
applicant.id, | ||
new FileTransfer(buffer, "sample_photo.png"), | ||
advancedValidation | ||
); | ||
} | ||
|
||
export async function uploadIdPhoto(applicant: Applicant) { | ||
|
@@ -273,6 +279,27 @@ export async function repeatRequestUntilStatusChanges( | |
return instance; | ||
} | ||
|
||
export async function repeatRequestUntilTaskOutputChanges( | ||
fn: string, | ||
params: any[], | ||
maxRetries = 10, | ||
sleepTime = 1000 | ||
): Promise<any> { | ||
let instance = (await onfido[fn](...params)).data; | ||
let iteration = 0; | ||
|
||
while (instance["output"] === null) { | ||
if (iteration >= maxRetries) { | ||
throw new Error("Task output did not change in time"); | ||
} | ||
iteration += 1; | ||
await sleep(sleepTime); | ||
|
||
instance = (await onfido[fn](...params)).data; | ||
} | ||
return instance; | ||
} | ||
|
||
export async function repeatRequestUntilHttpCodeChanges( | ||
fn: string, | ||
params: any[], | ||
|