Skip to content

Commit

Permalink
chore(formatter): keep prettier happy
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscocastanho-onfido committed Jul 16, 2024
1 parent 088fb55 commit e39e406
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 59 deletions.
7 changes: 3 additions & 4 deletions test/file-transfer.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { FileTransfer } from "onfido-node";
import { createReadStream, readFileSync } from "fs";


it("create a file transfer from a string and filename", () => {
const fileTransfer = new FileTransfer("PAYLOAD", "test-file.jpg")
const fileTransfer = new FileTransfer("PAYLOAD", "test-file.jpg");

expect(fileTransfer.filename).toEqual("test-file.jpg");
expect(fileTransfer.buffer.toString()).toEqual("PAYLOAD");
});

it("create a file transfer from a buffer and filename", () => {
let buffer = readFileSync("test/media/sample_photo.png");
const fileTransfer = new FileTransfer(buffer, "filename.png")
const fileTransfer = new FileTransfer(buffer, "filename.png");

expect(fileTransfer.filename).toEqual("filename.png");
expect(fileTransfer.buffer.slice(1, 4).toString()).toEqual("PNG");
});

it("create a file transfer from a file path", () => {
const fileTransfer = new FileTransfer("test/media/sample_photo.png")
const fileTransfer = new FileTransfer("test/media/sample_photo.png");

expect(fileTransfer.filename).toEqual("test/media/sample_photo.png");
expect(fileTransfer.buffer.slice(1, 4).toString()).toEqual("PNG");
Expand Down
109 changes: 55 additions & 54 deletions test/resources/qualified-electronic-signature.test.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
import {
cleanUpApplicants,
cleanUpWebhooks,
createApplicant,
repeatRequestUntilTaskOutputChanges,
createWorkflowRunWithCustomInputs,
onfido,
sleep
cleanUpApplicants,
cleanUpWebhooks,
createApplicant,
repeatRequestUntilTaskOutputChanges,
createWorkflowRunWithCustomInputs,
onfido,
sleep
} from "../test-helpers";

import {
WorkflowRunBuilder
} from "onfido-node";
import { WorkflowRunBuilder } from "onfido-node";

afterAll(() => {
return Promise.all([cleanUpApplicants(), cleanUpWebhooks()]);
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-");
});
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-");
});
6 changes: 5 additions & 1 deletion test/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,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) {
Expand Down

0 comments on commit e39e406

Please sign in to comment.