Skip to content

Commit db057ff

Browse files
committed
test(capital): add test coverage for Capital API services
Added tests for GrantAccountsApi, GrantOffersApi, and GrantsApi. Also exported CapitalAPI and capital typings. Disclaimer: this content was generated with Gemini using a human-generated .patch from the Java API.
1 parent f285333 commit db057ff

File tree

5 files changed

+424
-0
lines changed

5 files changed

+424
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import nock from "nock";
2+
import Client from "../client";
3+
import { createClient } from "../__mocks__/base";
4+
import { CapitalAPI } from "../services";
5+
6+
let client: Client;
7+
let capitalApi: CapitalAPI;
8+
let scope: nock.Scope;
9+
10+
beforeEach((): void => {
11+
if (!nock.isActive()) {
12+
nock.activate();
13+
}
14+
client = createClient();
15+
scope = nock("https://balanceplatform-api-test.adyen.com/capital/v1");
16+
capitalApi = new CapitalAPI(client);
17+
});
18+
19+
afterEach(() => {
20+
nock.cleanAll();
21+
});
22+
23+
describe("GrantAccountsApi", (): void => {
24+
it("should get grant account", async (): Promise<void> => {
25+
scope.get("/grantAccounts/CG00000000000000000000001")
26+
.reply(200, {
27+
"id": "CG00000000000000000000001",
28+
"fundingBalanceAccountId": "BA00000000000000000000001",
29+
"limits": [
30+
{
31+
"amount": {
32+
"currency": "EUR",
33+
"value": 100000
34+
}
35+
}
36+
],
37+
"balances": [
38+
{
39+
"currency": "EUR",
40+
"principal": 10000,
41+
"fee": 1000,
42+
"total": 11000
43+
}
44+
]
45+
});
46+
47+
const response = await capitalApi.GrantAccountsApi.getGrantAccountInformation("CG00000000000000000000001");
48+
49+
expect(response.id).toBe("CG00000000000000000000001");
50+
expect(response.fundingBalanceAccountId).toBe("BA00000000000000000000001");
51+
expect(response.limits?.length).toBe(1);
52+
expect(response.balances?.length).toBe(1);
53+
});
54+
});
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import nock from "nock";
2+
import Client from "../client";
3+
import { createClient } from "../__mocks__/base";
4+
import { CapitalAPI } from "../services";
5+
6+
let client: Client;
7+
let capitalApi: CapitalAPI;
8+
let scope: nock.Scope;
9+
10+
beforeEach((): void => {
11+
if (!nock.isActive()) {
12+
nock.activate();
13+
}
14+
client = createClient();
15+
scope = nock("https://balanceplatform-api-test.adyen.com/capital/v1");
16+
capitalApi = new CapitalAPI(client);
17+
});
18+
19+
afterEach(() => {
20+
nock.cleanAll();
21+
});
22+
23+
describe("GrantOffersApi", (): void => {
24+
it("should get all grant offers with query param", async (): Promise<void> => {
25+
scope.get("/grantOffers")
26+
.query({ accountHolderId: "AH00000000000000000000001" })
27+
.reply(200, {
28+
"grantOffers": [
29+
{
30+
"id": "GO00000000000000000000001",
31+
"amount": {
32+
"currency": "EUR",
33+
"value": 10000
34+
},
35+
"fee": {
36+
"currency": "EUR",
37+
"value": 100
38+
},
39+
"repayment": {
40+
"currency": "EUR",
41+
"value": 10100
42+
}
43+
}
44+
]
45+
});
46+
47+
const response = await capitalApi.GrantOffersApi.getAllGrantOffers("AH00000000000000000000001");
48+
49+
expect(response.grantOffers?.length).toBe(1);
50+
expect(response.grantOffers?.[0].id).toBe("GO00000000000000000000001");
51+
});
52+
53+
it("should get all grant offers without query param", async (): Promise<void> => {
54+
scope.get("/grantOffers")
55+
.reply(200, {
56+
"grantOffers": [
57+
{
58+
"id": "GO00000000000000000000001",
59+
"amount": {
60+
"currency": "EUR",
61+
"value": 10000
62+
},
63+
"fee": {
64+
"currency": "EUR",
65+
"value": 100
66+
},
67+
"repayment": {
68+
"currency": "EUR",
69+
"value": 10100
70+
}
71+
}
72+
]
73+
});
74+
75+
const response = await capitalApi.GrantOffersApi.getAllGrantOffers();
76+
77+
expect(response.grantOffers?.length).toBe(1);
78+
expect(response.grantOffers?.[0].id).toBe("GO00000000000000000000001");
79+
});
80+
81+
it("should get grant offer", async (): Promise<void> => {
82+
scope.get("/grantOffers/GO00000000000000000000001")
83+
.reply(200, {
84+
"id": "GO00000000000000000000001",
85+
"accountHolderId": "AH00000000000000000000001",
86+
"contractType": "cashAdvance",
87+
"amount": {
88+
"currency": "EUR",
89+
"value": 10000
90+
},
91+
"fee": {
92+
"amount": {
93+
"currency": "EUR",
94+
"value": 1000
95+
},
96+
"aprBasisPoints": 1200
97+
},
98+
"repayment": {
99+
"basisPoints": 1000,
100+
"term": {
101+
"estimatedDays": 180,
102+
"maximumDays": 365
103+
},
104+
"threshold": {
105+
"amount": {
106+
"currency": "EUR",
107+
"value": 1000
108+
}
109+
}
110+
},
111+
"startsAt": "2024-01-01T00:00:00Z",
112+
"expiresAt": "2024-01-31T23:59:59Z"
113+
});
114+
115+
const response = await capitalApi.GrantOffersApi.getGrantOffer("GO00000000000000000000001");
116+
117+
expect(response.id).toBe("GO00000000000000000000001");
118+
expect(response.accountHolderId).toBe("AH00000000000000000000001");
119+
expect(response.amount?.value).toBe(10000);
120+
});
121+
});

0 commit comments

Comments
 (0)