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
54 changes: 54 additions & 0 deletions src/__tests__/grantAccountsApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import nock from "nock";
import Client from "../client";
import { createClient } from "../__mocks__/base";
import { CapitalAPI } from "../services";

let client: Client;
let capitalApi: CapitalAPI;
let scope: nock.Scope;

beforeEach((): void => {
if (!nock.isActive()) {
nock.activate();
}
client = createClient();
scope = nock("https://balanceplatform-api-test.adyen.com/capital/v1");
capitalApi = new CapitalAPI(client);
});

afterEach(() => {
nock.cleanAll();
});

describe("GrantAccountsApi", (): void => {
it("should get grant account", async (): Promise<void> => {
scope.get("/grantAccounts/CG00000000000000000000001")
.reply(200, {
"id": "CG00000000000000000000001",
"fundingBalanceAccountId": "BA00000000000000000000001",
"limits": [
{
"amount": {
"currency": "EUR",
"value": 100000
}
}
],
"balances": [
{
"currency": "EUR",
"principal": 10000,
"fee": 1000,
"total": 11000
}
]
});

const response = await capitalApi.GrantAccountsApi.getGrantAccountInformation("CG00000000000000000000001");

expect(response.id).toBe("CG00000000000000000000001");
expect(response.fundingBalanceAccountId).toBe("BA00000000000000000000001");
expect(response.limits?.length).toBe(1);
expect(response.balances?.length).toBe(1);
});
});
121 changes: 121 additions & 0 deletions src/__tests__/grantOffersApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import nock from "nock";
import Client from "../client";
import { createClient } from "../__mocks__/base";
import { CapitalAPI } from "../services";

let client: Client;
let capitalApi: CapitalAPI;
let scope: nock.Scope;

beforeEach((): void => {
if (!nock.isActive()) {
nock.activate();
}
client = createClient();
scope = nock("https://balanceplatform-api-test.adyen.com/capital/v1");
capitalApi = new CapitalAPI(client);
});

afterEach(() => {
nock.cleanAll();
});

describe("GrantOffersApi", (): void => {
it("should get all grant offers with query param", async (): Promise<void> => {
scope.get("/grantOffers")
.query({ accountHolderId: "AH00000000000000000000001" })
.reply(200, {
"grantOffers": [
{
"id": "GO00000000000000000000001",
"amount": {
"currency": "EUR",
"value": 10000
},
"fee": {
"currency": "EUR",
"value": 100
},
"repayment": {
"currency": "EUR",
"value": 10100
}
}
]
});

const response = await capitalApi.GrantOffersApi.getAllGrantOffers("AH00000000000000000000001");

expect(response.grantOffers?.length).toBe(1);
expect(response.grantOffers?.[0].id).toBe("GO00000000000000000000001");
});

it("should get all grant offers without query param", async (): Promise<void> => {
scope.get("/grantOffers")
.reply(200, {
"grantOffers": [
{
"id": "GO00000000000000000000001",
"amount": {
"currency": "EUR",
"value": 10000
},
"fee": {
"currency": "EUR",
"value": 100
},
"repayment": {
"currency": "EUR",
"value": 10100
}
}
]
});

const response = await capitalApi.GrantOffersApi.getAllGrantOffers();

expect(response.grantOffers?.length).toBe(1);
expect(response.grantOffers?.[0].id).toBe("GO00000000000000000000001");
});

it("should get grant offer", async (): Promise<void> => {
scope.get("/grantOffers/GO00000000000000000000001")
.reply(200, {
"id": "GO00000000000000000000001",
"accountHolderId": "AH00000000000000000000001",
"contractType": "cashAdvance",
"amount": {
"currency": "EUR",
"value": 10000
},
"fee": {
"amount": {
"currency": "EUR",
"value": 1000
},
"aprBasisPoints": 1200
},
"repayment": {
"basisPoints": 1000,
"term": {
"estimatedDays": 180,
"maximumDays": 365
},
"threshold": {
"amount": {
"currency": "EUR",
"value": 1000
}
}
},
"startsAt": "2024-01-01T00:00:00Z",
"expiresAt": "2024-01-31T23:59:59Z"
});

const response = await capitalApi.GrantOffersApi.getGrantOffer("GO00000000000000000000001");

expect(response.id).toBe("GO00000000000000000000001");
expect(response.accountHolderId).toBe("AH00000000000000000000001");
expect(response.amount?.value).toBe(10000);
});
});
Loading