Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: Run linter over tests
run: |
npm install prettier
npx prettier -c test/**/*.ts
run: npx prettier -c test/**/*.ts
- name: Run integration tests with NPM
if: ${{ matrix.node-version == '18.x' &&
github.repository_owner == 'onfido' &&
(github.event_name == 'pull_request' || github.event_name == 'release') }}
(github.event_name == 'pull_request' ||
github.event_name == 'release' ||
github.event_name == 'workflow_dispatch') }}
run: npm test -- -i
env:
ONFIDO_API_TOKEN: ${{ secrets.ONFIDO_API_TOKEN }}
Expand Down
16 changes: 9 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@faker-js/faker": "^8.4.1",
"@types/jest": "^26.0.15",
"jest": "^26.6.3",
"prettier": "^1.18.2",
"prettier": "^3.6.2",
"ts-jest": "^26.4.4",
"dotenv": "^16.4.5",
"@types/node": "12.11.5 - 12.20.42",
Expand Down
12 changes: 6 additions & 6 deletions test/classic-webhook-event-verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
WebhookEventVerifier,
WebhookEventType,
WebhookEventResourceType,
WebhookEventObjectStatus
WebhookEventObjectStatus,
} from "onfido-node";

const webhookToken = "_ABC123abc123ABC123abc123ABC123_";
Expand All @@ -19,9 +19,9 @@ const expectedEvent = {
id: "check-123",
href: "https://api.onfido.com/v3/checks/check-123",
status: WebhookEventObjectStatus.Complete,
completed_at_iso8601: "2020-01-01T00:00:00Z"
}
}
completed_at_iso8601: "2020-01-01T00:00:00Z",
},
},
};

it("returns the event if the signature is valid", () => {
Expand All @@ -41,7 +41,7 @@ it("allows passing the body as a buffer", () => {

expect(event).toEqual(expectedEvent);
expect(event.payload.object.href).toEqual(
"https://api.onfido.com/v3/checks/check-123"
"https://api.onfido.com/v3/checks/check-123",
);

// Test alternative way to access fields (it also works for additional properties)
Expand All @@ -53,6 +53,6 @@ it("throws an error if the signature is invalid", () => {
"b0082d7481f9f0a2907583dbe1f344d6d4c0d9989df2fd804f98479f60cd760e";

expect(() => verifier.readPayload(rawEvent, signature)).toThrow(
OnfidoInvalidSignatureError
OnfidoInvalidSignatureError,
);
});
20 changes: 10 additions & 10 deletions test/onfido.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@ import { Configuration, DefaultApi, Region } from "onfido-node";

it("sets the authorization header from the given token", () => {
expect(new Configuration({ apiToken: "api_token" }).apiKey).toBe(
"Token token=api_token"
"Token token=api_token",
);
});

it("contains a user agent header", () => {
expect(
new Configuration({ apiToken: "api_token" }).baseOptions.headers[
"User-Agent"
]
],
).toMatch(/^onfido-node\/\d+\.\d+\.\d+$/);
});

it("allows setting the EU region", () => {
expect(
new Configuration({ apiToken: "token", region: Region.EU }).basePath
new Configuration({ apiToken: "token", region: Region.EU }).basePath,
).toBe("https://api.eu.onfido.com/v3.6");
});

it("allows setting the US region", () => {
expect(
new Configuration({ apiToken: "token", region: Region.US }).basePath
new Configuration({ apiToken: "token", region: Region.US }).basePath,
).toBe("https://api.us.onfido.com/v3.6");
});

it("allows setting the CA region", () => {
expect(
new Configuration({ apiToken: "token", region: Region.CA }).basePath
new Configuration({ apiToken: "token", region: Region.CA }).basePath,
).toBe("https://api.ca.onfido.com/v3.6");
});

it("use EU region if region was not provided", () => {
expect(new Configuration({ apiToken: "token" }).basePath).toBe(
"https://api.eu.onfido.com/v3.6"
"https://api.eu.onfido.com/v3.6",
);
});

it("throws an error for unknown regions", () => {
expect(
() => new Configuration({ apiToken: "token", region: "abc" as any })
() => new Configuration({ apiToken: "token", region: "abc" as any }),
).toThrow("Unknown or missing region 'abc'");
});

it("throws an error if no api token is provided", () => {
expect(() => new Configuration()).toThrow("No apiToken provided");
expect(() => new Configuration({ apiToken: "" })).toThrow(
"No apiToken provided"
"No apiToken provided",
);
});

Expand All @@ -56,8 +56,8 @@ it("allows changing the default timeout", () => {
apiToken: "token",
region: Region.EU,
baseOptions: {
timeout: 123
}
timeout: 123,
},
});

expect(onfido.baseOptions.timeout).toBe(123);
Expand Down
10 changes: 5 additions & 5 deletions test/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { AxiosError } from "axios";

const onfido_bad_token = new DefaultApi(
new Configuration({
apiToken: "bad-token" // Use an invalid token
})
apiToken: "bad-token", // Use an invalid token
}),
);

describe("error handling", () => {
Expand All @@ -16,12 +16,12 @@ describe("error handling", () => {
last_name: "Applicant",
address: {
postcode: "AB12 3AB",
country: "GBR"
country: "GBR",
},
location: {
ip_address: "127.0.0.1",
country_of_residence: "GBR"
}
country_of_residence: "GBR",
},
});
fail(); // We should never be here
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions test/resources/addresses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const exampleAddress: Address = {
building_name: "",
street: "RAWSON CLOSE",
sub_street: "",
town: "SHEFFIELD"
town: "SHEFFIELD",
};

const exampleAddress2 = {
...exampleAddress,
building_number: "18"
building_number: "18",
};

it("allows picking addresses", async () => {
const addresses = await onfido.findAddresses("S2 2DF");

expect(addresses.data.addresses).toEqual(
expect.arrayContaining([exampleAddress, exampleAddress2])
expect.arrayContaining([exampleAddress, exampleAddress2]),
);
});
17 changes: 8 additions & 9 deletions test/resources/advanced-electronic-signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createApplicant,
repeatRequestUntilTaskOutputChanges,
createWorkflowRunWithCustomInputs,
onfido
onfido,
} from "../test-helpers";

import { WorkflowRunBuilder } from "onfido-node";
Expand All @@ -22,21 +22,20 @@ it("downloads a signed document file", async () => {
custom_data: {
doc_result: "clear",
face_result: "clear",
transaction_id: "995bf84c-d708-4977-8b88-d4b66bebdaf6"
}
transaction_id: "995bf84c-d708-4977-8b88-d4b66bebdaf6",
},
};

const workflowRun = await createWorkflowRunWithCustomInputs(
workflowRunBuilder
);
const workflowRun =
await createWorkflowRunWithCustomInputs(workflowRunBuilder);
const taskId = (await onfido.listTasks(workflowRun.data.id)).data[1].id;

const output = (
await repeatRequestUntilTaskOutputChanges(
"findTask",
[workflowRun.data.id, taskId],
10,
3000
3000,
)
)["output"];

Expand All @@ -46,11 +45,11 @@ it("downloads a signed document file", async () => {

const signedDocument = await onfido.downloadAesDocument(
workflowRun.data.id,
signedDocumentFileId
signedDocumentFileId,
);
const receiptDocument = await onfido.downloadAesDocument(
workflowRun.data.id,
receiptDocumentFileId
receiptDocumentFileId,
);

expect(signedDocument.status).toEqual(200);
Expand Down
36 changes: 18 additions & 18 deletions test/resources/applicants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
getExpectedObject,
createApplicant,
cleanUpApplicants,
sortByApplicantfirst_name
sortByApplicantfirst_name,
} from "../test-helpers";
import { exampleApplicant } from "../test-examples";
import { AxiosError, isAxiosError } from "axios";

function getExpectedApplicant(exampleApplicant: Applicant) {
return getExpectedObject(exampleApplicant, {
sandbox: true
sandbox: true,
});
}

Expand All @@ -38,50 +38,50 @@ it("finds an applicant", async () => {
const lookupApplicant = await onfido.findApplicant(applicant.id);

expect(lookupApplicant.data).toMatchObject(
getExpectedApplicant(exampleApplicant)
getExpectedApplicant(exampleApplicant),
);
});

it("updates an applicant", async () => {
const modifiedApplicant = { ...exampleApplicant, first_name: "Test2" };

const updatedApplicant = await onfido.updateApplicant(applicant.id, {
first_name: "Test2"
first_name: "Test2",
});

expect(updatedApplicant.data).toMatchObject(
getExpectedApplicant(modifiedApplicant)
getExpectedApplicant(modifiedApplicant),
);
});

it("lists an applicant's consents", async () => {
const consents = [
{
name: ApplicantConsentName.PrivacyNoticesRead,
granted: true
granted: true,
},
{
name: ApplicantConsentName.SsnVerification,
granted: true
granted: true,
},
{
name: ApplicantConsentName.PhoneNumberVerification,
granted: true
}
granted: true,
},
];
const applicant = await createApplicant({
first_name: "Sir Consents",
consents: consents
consents: consents,
});

const consentsList = await onfido.findApplicantConsents(applicant.data.id);

// sorting to ensure the order is consistent
const actualConsentsSorted = consentsList.data.sort((a, b) =>
a.name.localeCompare(b.name)
a.name.localeCompare(b.name),
);
const expectedConsentsSorted = consents.sort((a, b) =>
a.name.localeCompare(b.name)
a.name.localeCompare(b.name),
);

expectedConsentsSorted.forEach((expected, index) => {
Expand All @@ -108,18 +108,18 @@ it("lists applicants", async () => {
consents: [
{
name: ApplicantConsentName.PrivacyNoticesRead,
granted: true
}
]
granted: true,
},
],
});

const applicants = await onfido.listApplicants(1, 20, false);

expect(applicants.data.applicants.sort(sortByApplicantfirst_name)).toEqual(
expect.arrayContaining([
getExpectedApplicant(anotherApplicant),
getExpectedApplicant(exampleApplicant)
])
getExpectedApplicant(exampleApplicant),
]),
);
});

Expand All @@ -134,7 +134,7 @@ it("finds a non existent applicant", async () => {
const error_details = error.response?.data.error;
expect(isAxiosError(error)).toBe(true);
expect(error_details.message).toBe(
"Could not find the following resource: Applicant with id=invalid-applicant-id"
"Could not find the following resource: Applicant with id=invalid-applicant-id",
);
expect(error_details.type).toBe("resource_not_found");
}
Expand Down
Loading