Skip to content

Commit fe1705b

Browse files
axshaniilyamerman
andauthored
Tests (#43)
* first test with jest * applications tests * few changes * list returns Card[] * more tests * more tests, for transactions and payments * type * rename test to tests * no need for as Type * createBeneficialOwner * added helpers and better tests * create account and counterparty for better tests * create cards tests * create new account and create new cards * remove dummy test * counterparties tests * createCounterpartyForTest * payments tests * more tests * autorizationRequest tests * rename * merge from main + added CI trigger for tests * Added unit token to env * fix ci value * fix package-lock.json * fix tests * ssn * created test for events * billers test * Trying test on github * lint * added url to secret * env * limit worker + pass statements * lint * try --no-cache * Remove unnecessary params + change job name * Expect failing test (cards list) * Fix "broken" test * ci Co-authored-by: ilyamerman <[email protected]>
1 parent 8d9dc7d commit fe1705b

17 files changed

+8691
-1318
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ jobs:
1111
node-version: 16.x
1212
- run: npm ci
1313
- run: npm run lint
14-
- run: npm run build
14+
- run: npm run build
15+
- run: |
16+
touch .env
17+
echo UNIT_TOKEN=${{ secrets.UNIT_TOKEN }} >> .env
18+
echo UNIT_API_URL=${{ secrets.UNIT_API_URL }} >> .env
19+
- run: npm run test

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
setupFilesAfterEnv: ['./jest.setup.js'],
5+
};

jest.setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
jest.setTimeout(30000);

package-lock.json

Lines changed: 8085 additions & 1316 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "dist/unit.js",
66
"types": "dist/unit.d.ts",
77
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1",
8+
"test": "jest .spec.ts --maxWorkers=1 --no-cache",
99
"build": "tsc",
1010
"lint": "eslint **/*.ts",
1111
"lint-fix": "eslint **/*.ts --fix"
@@ -21,11 +21,14 @@
2121
},
2222
"homepage": "https://github.com/unit-finance/unit-node-sdk#readme",
2323
"devDependencies": {
24+
"@types/jest": "^26.0.24",
2425
"@types/node": "^15.0.2",
2526
"@typescript-eslint/eslint-plugin": "^5.1.0",
2627
"@typescript-eslint/parser": "^5.1.0",
2728
"dotenv": "^10.0.0",
2829
"eslint": "^8.8.0",
30+
"jest": "^27.0.6",
31+
"ts-jest": "^27.0.3",
2932
"typescript": "^4.2.4"
3033
},
3134
"dependencies": {

tests/accounts.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Unit } from "../unit"
2+
import { CreateDepositAccountRequest } from "../types/account"
3+
import { createBusinessApplication, createIndividualApplication } from "./applications.spec"
4+
5+
import dotenv from "dotenv"
6+
dotenv.config()
7+
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
8+
const accountsId: string[] = []
9+
10+
function createAccount(customerId: string) {
11+
const createDepositAccountRequest: CreateDepositAccountRequest = {
12+
type: "depositAccount",
13+
attributes: {
14+
depositProduct: "checking",
15+
tags: {
16+
purpose: "checking"
17+
}
18+
},
19+
relationships: {
20+
customer: {
21+
data: {
22+
type: "customer",
23+
id: customerId
24+
}
25+
}
26+
}
27+
}
28+
29+
return unit.accounts.create(createDepositAccountRequest)
30+
}
31+
32+
export async function createIndividualAccount() {
33+
const customerId = (await createIndividualApplication()).data.relationships.customer?.data.id
34+
return createAccount(customerId ? customerId : "")
35+
}
36+
37+
export async function createBussinessAccount() {
38+
const customerId = (await createBusinessApplication()).data.relationships.customer?.data.id
39+
return createAccount(customerId ? customerId : "")
40+
}
41+
42+
describe("Accounts List", () => {
43+
test("Get Accounts List", async () => {
44+
const res = await unit.accounts.list()
45+
res.data.forEach(element => {
46+
expect(element.type === "batchAccount" || element.type === "depositAccount").toBeTruthy()
47+
accountsId.push(element.id)
48+
})
49+
50+
accountsId.forEach(async id => {
51+
const res = await unit.accounts.get(id)
52+
expect(res.data.type === "depositAccount" || res.data.type === "batchAccount").toBeTruthy()
53+
})
54+
})
55+
})
56+
57+
58+
describe("Create Account", () => {
59+
test("Create Deposit Account", async () => {
60+
const res = await createIndividualAccount()
61+
const account = await unit.accounts.get(res.data.id)
62+
expect(account.data.type === "depositAccount").toBeTruthy()
63+
})
64+
})
65+

tests/applications.spec.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
3+
import { Unit } from "../unit"
4+
import { CreateBusinessApplicationRequest, CreateIndividualApplicationRequest } from "../types/application"
5+
import { createAddress, createPhone, createOfficer, createFullName, createBusinessContact, createBeneficialOwner } from "../helpers"
6+
7+
import dotenv from "dotenv"
8+
dotenv.config()
9+
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
10+
11+
export function createIndividualApplication() {
12+
const createndividualApplication: CreateIndividualApplicationRequest = {
13+
type: "individualApplication",
14+
attributes: {
15+
ssn: "721074426",
16+
fullName: createFullName("Richard","Hendricks"),
17+
dateOfBirth: "2001-08-10",
18+
address: createAddress("20 Ingram St",null,"Forest Hills","CA","11375","US"),
19+
20+
phone: createPhone("1","5555555555")
21+
}
22+
}
23+
24+
return unit.applications.create(createndividualApplication)
25+
}
26+
27+
export function createBusinessApplication() {
28+
const businessApplication: CreateBusinessApplicationRequest = {
29+
type: "businessApplication",
30+
attributes: {
31+
name: "Acme Inc.",
32+
address: createAddress("1600 Pennsylvania Avenue Northwest", null, "Washington", "CA", "20500", "US"),
33+
phone: createPhone("1", "9294723497"),
34+
stateOfIncorporation: "CA",
35+
entityType: "Corporation",
36+
ein: "123456789",
37+
officer: createOfficer(null, createFullName("Jone", "Doe"), null, "123456789", null, null, "2012-05-05",
38+
createAddress("950 Allerton Street", null, "Redwood City", "CA", "94063", "US"), createPhone("1", "2025550108"), "[email protected]"),
39+
contact: createBusinessContact(createFullName("Jone", "Doe"), "[email protected]", createPhone("1", "2025550108")),
40+
beneficialOwners: [
41+
createBeneficialOwner(null,createFullName("James","Smith"),"574567625",null,null,"2012-04-05",
42+
createAddress("650 Allerton Street",null,"Redwood City","CA","94063","US"),createPhone("1","2025550127"),"[email protected]",null),
43+
createBeneficialOwner(null,createFullName("Richard","Hendricks"),"574572795",null,null,"2012-04-03",
44+
createAddress("470 Allerton Street",null,"Redwood City","CA","94063","US"),createPhone("1","2025550158"),"[email protected]",null)
45+
]
46+
}
47+
}
48+
49+
return unit.applications.create(businessApplication)
50+
}
51+
52+
describe("Create Application", () => {
53+
test("Create Individual Application", async () => {
54+
55+
const createRes = await createIndividualApplication()
56+
const res = await unit.applications.get(createRes.data.id)
57+
expect(res.data.type).toBe("individualApplication")
58+
})
59+
60+
test("Create Business Application", async () => {
61+
const createRes = await createBusinessApplication()
62+
const res = await unit.applications.get(createRes.data.id)
63+
expect(res.data.type).toBe("businessApplication")
64+
})
65+
})
66+
67+
describe("Applications", () => {
68+
test("Get List of Applications", async () => {
69+
const res = await unit.applications.list()
70+
expect(res.data).toBeInstanceOf(Array)
71+
})
72+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Unit } from "../unit"
2+
3+
import dotenv from "dotenv"
4+
dotenv.config()
5+
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
6+
const authorizationRequestsId: string[] = []
7+
8+
describe("AuthorizationRequests List", () => {
9+
test("Get AuthorizationRequests List", async () => {
10+
const res = await unit.authorizationRequests.list()
11+
res.data.forEach(element => {
12+
expect(element.type === "purchaseAuthorizationRequest").toBeTruthy()
13+
authorizationRequestsId.push(element.id)
14+
})
15+
})
16+
})
17+
18+
describe("Get AuthorizationRequest Test", () => {
19+
test("get authorizationRequest event", async () => {
20+
authorizationRequestsId.forEach(async id => {
21+
const res = await unit.authorizationRequests.get(id)
22+
expect(res.data.type === "purchaseAuthorizationRequest").toBeTruthy()
23+
})
24+
})
25+
})

tests/billPays.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Unit } from "../unit"
2+
3+
import dotenv from "dotenv"
4+
dotenv.config()
5+
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
6+
7+
describe("Bill Pays List", () => {
8+
test("Get Billers List", async () => {
9+
const res = await unit.billPays.get({name: "Electric"})
10+
res.data.forEach(element => {
11+
expect(element.type === "biller").toBeTruthy()
12+
})
13+
})
14+
})

tests/cards.spec.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { createAddress, createFullName, createPhone } from "../helpers"
2+
import { CreateBusinessDebitCardRequest, CreateBusinessVirtualDebitCardRequest, CreateIndividualDebitCardRequest, CreateIndividualVirtualDebitCardRequest, Unit } from "../unit"
3+
import { createBussinessAccount, createIndividualAccount } from "./accounts.spec"
4+
// import { createBusinessApplication } from "./applications.spec"
5+
6+
import dotenv from "dotenv"
7+
dotenv.config()
8+
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
9+
const cardsId: string[] = []
10+
const cardTypes = ["businessDebitCard", "individualDebitCard", "businessVirtualDebitCard", "individualVirtualDebitCard"]
11+
12+
describe("Cards List", () => {
13+
test("Get Cards List", async () => {
14+
const res = await unit.cards.list()
15+
expect(res.data.length).toBeGreaterThan(0)
16+
res.data.forEach(element => {
17+
expect(cardTypes.includes(element.type)).toBeTruthy()
18+
cardsId.push(element.id)
19+
})
20+
})
21+
})
22+
23+
describe("Get Card Test", () => {
24+
test("get each card", async () => {
25+
cardsId.forEach(async id => {
26+
const res = await unit.cards.get(id)
27+
expect(cardTypes.includes(res.data.type)).toBeTruthy()
28+
})
29+
})
30+
})
31+
32+
describe("Create Card", () => {
33+
test("create individual debitcard", async () => {
34+
const createAccountRes = await createIndividualAccount()
35+
const CreateDebitCardRequest: CreateIndividualDebitCardRequest = {
36+
type: "individualDebitCard",
37+
attributes: {
38+
shippingAddress: createAddress("5230 Newell Rd", null, "Palo Alto", "CA", "94303", "US")
39+
},
40+
relationships: {
41+
account: {
42+
data: {
43+
type: "depositAccount",
44+
id: createAccountRes.data.id
45+
}
46+
}
47+
}
48+
}
49+
50+
const createRes = await unit.cards.createDebitCard(CreateDebitCardRequest)
51+
const res = await unit.cards.get(createRes.data.id)
52+
expect(res.data.type === "individualDebitCard").toBeTruthy()
53+
})
54+
55+
test("create individual virtual debitcard", async () => {
56+
const createAccountRes = await createIndividualAccount()
57+
const CreateDebitCardRequest: CreateIndividualVirtualDebitCardRequest = {
58+
type: "individualVirtualDebitCard",
59+
attributes: {},
60+
relationships: {
61+
account: {
62+
data: {
63+
type: "depositAccount",
64+
id: createAccountRes.data.id
65+
}
66+
}
67+
}
68+
}
69+
70+
const createRes = await unit.cards.createDebitCard(CreateDebitCardRequest)
71+
const res = await unit.cards.get(createRes.data.id)
72+
expect(res.data.type === "individualVirtualDebitCard").toBeTruthy()
73+
})
74+
75+
test("create business debitcard", async () => {
76+
const account = await createBussinessAccount()
77+
const CreateDebitCardRequest: CreateBusinessDebitCardRequest = {
78+
type: "businessDebitCard",
79+
attributes: {
80+
fullName: createFullName("Richard","Hendricks"),
81+
ssn: "123456789",
82+
address: createAddress("5230 Newell Rd", null, "Palo Alto", "CA", "94303", "US"),
83+
shippingAddress: createAddress("5230 Newell Rd", null, "Palo Alto", "CA", "94303", "US"),
84+
dateOfBirth: "2001-08-10",
85+
86+
phone: createPhone("1", "5555555555")
87+
},
88+
relationships: {
89+
account: {
90+
data: {
91+
type: "depositAccount",
92+
id: account.data.id
93+
}
94+
}
95+
}
96+
}
97+
98+
const createRes = await unit.cards.createDebitCard(CreateDebitCardRequest)
99+
const res = await unit.cards.get(createRes.data.id)
100+
expect(res.data.type === "businessDebitCard").toBeTruthy()
101+
})
102+
103+
test("create business virtual debitcard", async () => {
104+
const account = await createBussinessAccount()
105+
const CreateDebitCardRequest: CreateBusinessVirtualDebitCardRequest = {
106+
type: "businessVirtualDebitCard",
107+
attributes: {
108+
fullName: createFullName("Richard","Hendricks"),
109+
ssn: "123456789",
110+
address: createAddress("5230 Newell Rd", null, "Palo Alto", "CA", "94303", "US"),
111+
dateOfBirth: "2001-08-10",
112+
113+
phone: createPhone("1", "5555555555")
114+
},
115+
relationships: {
116+
account: {
117+
data: {
118+
type: "depositAccount",
119+
id: account.data.id
120+
}
121+
}
122+
}
123+
}
124+
125+
const createRes = await unit.cards.createDebitCard(CreateDebitCardRequest)
126+
const res = await unit.cards.get(createRes.data.id)
127+
expect(res.data.type === "businessVirtualDebitCard").toBeTruthy()
128+
})
129+
})

0 commit comments

Comments
 (0)