Skip to content

Commit

Permalink
Fix and improve tests after library refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
dvacca-onfido committed Oct 18, 2024
1 parent 10bca87 commit 72e2090
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
8 changes: 5 additions & 3 deletions test/resources/documents.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Applicant, Document } from "onfido-node";
import { Applicant, Document, DocumentTypes } from "onfido-node";

import {
onfido,
Expand Down Expand Up @@ -39,7 +39,7 @@ it("uploads a document", async () => {

it("uploads a document with location", async () => {
document = (
await uploadDocument(applicant, "driving_licence", {
await uploadDocument(applicant, DocumentTypes.DrivingLicence, {
country_of_residence: "FRA"
})
).data;
Expand All @@ -61,7 +61,9 @@ it("finds a document", async () => {
});

it("lists documents", async () => {
const anotherDocument = (await uploadDocument(applicant, "passport")).data;
const anotherDocument = (
await uploadDocument(applicant, DocumentTypes.Passport)
).data;
const documents = (
await onfido.listDocuments(applicant.id)
).data.documents.sort(sortByDocumentType);
Expand Down
2 changes: 1 addition & 1 deletion test/resources/qualified-electronic-signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ it("downloads a signed document file", async () => {
const workflowRun = await createWorkflowRunWithCustomInputs(
workflowRunBuilder
);
const taskId = (await onfido.listTasks(workflowRun.data.id)).data[0].id;
const taskId = (await onfido.listTasks(workflowRun.data.id)).data[1].id;

const output = (
await repeatRequestUntilTaskOutputChanges(
Expand Down
5 changes: 4 additions & 1 deletion test/resources/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ it("finds a task", async () => {
const task = await onfido.findTask(workflowRunId, taskId);

expect(task.data).toEqual(
getExpectedTask(exampleTask, { input: expect.anything(), output: null })
getExpectedTask(exampleTask, {
input: expect.anything(),
output: expect.anything()
})
);
});

Expand Down
16 changes: 13 additions & 3 deletions test/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
MotionCapture,
Report,
WatchlistMonitorReportNameEnum,
WorkflowRunBuilder
WorkflowRunBuilder,
DocumentTypes
} from "onfido-node";

export const onfido = new DefaultApi(
Expand Down Expand Up @@ -91,12 +92,21 @@ export async function cleanUpApplicants() {

export async function uploadDocument(
applicant: Applicant,
documentType = "driving_licence",
documentType: DocumentTypes = DocumentTypes.DrivingLicence,
location?: LocationBuilder
) {
let fileTransfer = new FileTransfer("test/media/sample_driving_licence.png");

return onfido.uploadDocument(documentType, applicant.id, fileTransfer, undefined, undefined, undefined, undefined, location);
return onfido.uploadDocument(
documentType,
applicant.id,
fileTransfer,
undefined,
undefined,
undefined,
undefined,
location
);
}

export async function uploadLivePhoto(
Expand Down
14 changes: 10 additions & 4 deletions test/webhook-event-verifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { OnfidoInvalidSignatureError, WebhookEventVerifier } from "onfido-node";
import {
OnfidoInvalidSignatureError,
WebhookEventVerifier,
WebhookEventType,
WebhookEventResourceType,
WebhookEventObjectStatus
} from "onfido-node";

const webhookToken = "_ABC123abc123ABC123abc123ABC123_";
const verifier = new WebhookEventVerifier(webhookToken);
Expand All @@ -7,12 +13,12 @@ const rawEvent = `{"payload":{"resource_type":"check","action":"check.completed"

const expectedEvent = {
payload: {
action: "check.completed",
resource_type: "check",
action: WebhookEventType.CheckCompleted,
resource_type: WebhookEventResourceType.Check,
object: {
id: "check-123",
href: "https://api.onfido.com/v3/checks/check-123",
status: "complete",
status: WebhookEventObjectStatus.Complete,
completed_at_iso8601: "2020-01-01T00:00:00Z"
}
}
Expand Down

0 comments on commit 72e2090

Please sign in to comment.