diff --git a/src/__tests__/grantAccountsApi.spec.ts b/src/__tests__/grantAccountsApi.spec.ts new file mode 100644 index 000000000..8086f1a31 --- /dev/null +++ b/src/__tests__/grantAccountsApi.spec.ts @@ -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 => { + 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); + }); +}); diff --git a/src/__tests__/grantOffersApi.spec.ts b/src/__tests__/grantOffersApi.spec.ts new file mode 100644 index 000000000..51707f2d9 --- /dev/null +++ b/src/__tests__/grantOffersApi.spec.ts @@ -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 => { + 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 => { + 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 => { + 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); + }); +}); diff --git a/src/__tests__/grantsApi.spec.ts b/src/__tests__/grantsApi.spec.ts new file mode 100644 index 000000000..2f70698c0 --- /dev/null +++ b/src/__tests__/grantsApi.spec.ts @@ -0,0 +1,247 @@ +import nock from "nock"; +import Client from "../client"; +import { createClient } from "../__mocks__/base"; +import { CapitalAPI } from "../services"; +import { Types } from ".."; + +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("GrantsApi", (): void => { + it("should get grant", async (): Promise => { + scope.get("/grants/GR00000000000000000000001") + .reply(200, { + "id": "GR00000000000000000000001", + "grantAccountId": "CG00000000000000000000001", + "grantOfferId": "GO00000000000000000000001", + "counterparty": { + "accountHolderId": "AH00000000000000000000001", + "balanceAccountId": "BA00000000000000000000001" + }, + "amount": { + "currency": "EUR", + "value": 10000 + }, + "balances": { + "currency": "EUR", + "principal": 10000, + "fee": 1000, + "total": 11000 + }, + "status": { + "code": "Active" + } + }); + + const response = await capitalApi.GrantsApi.getGrant("GR00000000000000000000001"); + + expect(response.id).toBe("GR00000000000000000000001"); + expect(response.grantAccountId).toBe("CG00000000000000000000001"); + expect(response.status?.code).toBe(Types.capital.Status.CodeEnum.Active); + }); + + it("should get all grants", async (): Promise => { + scope.get("/grants") + .query({ counterpartyAccountHolderId: "AH00000000000000000000001" }) + .reply(200, { + "grants": [ + { + "id": "GR00000000000000000000001", + "grantAccountId": "CG00000000000000000000001", + "grantOfferId": "GO00000000000000000000001", + "counterparty": { + "accountHolderId": "AH00000000000000000000001", + "balanceAccountId": "BA00000000000000000000001" + }, + "amount": { + "currency": "EUR", + "value": 10000 + }, + "balances": { + "currency": "EUR", + "principal": 10000, + "fee": 1000, + "total": 11000 + }, + "status": { + "code": "Active" + } + } + ] + }); + + const response = await capitalApi.GrantsApi.getAllGrants("AH00000000000000000000001"); + + expect(response.grants?.length).toBe(1); + expect(response.grants?.[0].id).toBe("GR00000000000000000000001"); + }); + + it("should request grant", async (): Promise => { + scope.post("/grants") + .reply(200, { + "id": "GR00000000000000000000001", + "grantAccountId": "CG00000000000000000000001", + "grantOfferId": "0000000000000001", + "counterparty": { + "accountHolderId": "AH00000000000000000000001", + "balanceAccountId": "BA00000000000000000000001" + }, + "amount": { + "currency": "EUR", + "value": 1000000 + }, + "fee": { + "amount": { + "value": 120000, + "currency": "EUR" + } + }, + "balances": { + "currency": "EUR", + "fee": 120000, + "principal": 1000000, + "total": 1120000 + }, + "repayment": { + "basisPoints": 1400 + }, + "status": { + "code": "Pending" + } + }); + + const minimalGrantInfo: Types.capital.GrantInfo = { + grantAccountId: "GR00000000000000000000001" + } as Types.capital.GrantInfo; + + const response = await capitalApi.GrantsApi.requestGrant(minimalGrantInfo); + + expect(response.id).toBe("GR00000000000000000000001"); + expect(response.status?.code).toBe(Types.capital.Status.CodeEnum.Pending); + }); + + it("should get grant disbursement", async (): Promise => { + scope.get("/grants/GR00000000000000000000001/disbursements/DI00000000000000000000001") + .reply(200, { + "id": "DI00000000000000000000001", + "grantId": "GR00000000000000000000001", + "accountHolderId": "AH00000000000000000000001", + "balanceAccountId": "BA00000000000000000000001", + "amount": { + "currency": "EUR", + "value": 10000 + }, + "fee": { + "amount": { + "currency": "EUR", + "value": 1000 + } + }, + "balances": { + "currency": "EUR", + "principal": 10000, + "fee": 1000, + "total": 11000 + }, + "repayment": { + "basisPoints": 1000, + "updateDescription": "string" + } + }); + + const response = await capitalApi.GrantsApi.getGrantDisbursement("GR00000000000000000000001", "DI00000000000000000000001"); + + expect(response.id).toBe("DI00000000000000000000001"); + expect(response.grantId).toBe("GR00000000000000000000001"); + }); + + it("should get all grant disbursements", async (): Promise => { + scope.get("/grants/GR00000000000000000000001/disbursements") + .reply(200, { + "disbursements": [ + { + "id": "DI00000000000000000000001", + "grantId": "GR00000000000000000000001", + "accountHolderId": "AH00000000000000000000001", + "balanceAccountId": "BA00000000000000000000001", + "amount": { + "currency": "EUR", + "value": 10000 + }, + "fee": { + "amount": { + "currency": "EUR", + "value": 1000 + } + }, + "balances": { + "currency": "EUR", + "principal": 10000, + "fee": 1000, + "total": 11000 + }, + "repayment": { + "basisPoints": 1000, + "updateDescription": "string" + } + } + ] + }); + + const response = await capitalApi.GrantsApi.getAllGrantDisbursements("GR00000000000000000000001"); + + expect(response.disbursements?.length).toBe(1); + expect(response.disbursements?.[0].id).toBe("DI00000000000000000000001"); + }); + + it("should update grant disbursement", async (): Promise => { + scope.patch("/grants/GR00000000000000000000001/disbursements/DI00000000000000000000001") + .reply(200, { + "id": "DI00000000000000000000001", + "grantId": "GR00000000000000000000001", + "accountHolderId": "AH00000000000000000000001", + "balanceAccountId": "BA00000000000000000000001", + "amount": { + "currency": "EUR", + "value": 10000 + }, + "fee": { + "amount": { + "currency": "EUR", + "value": 1000 + } + }, + "balances": { + "currency": "EUR", + "principal": 10000, + "fee": 1000, + "total": 11000 + }, + "repayment": { + "basisPoints": 1500, + "updateDescription": "string" + } + }); + + const updateRequest: Types.capital.DisbursementInfoUpdate = {}; + + const response = await capitalApi.GrantsApi.updateGrantDisbursement("GR00000000000000000000001", "DI00000000000000000000001", updateRequest); + + expect(response.id).toBe("DI00000000000000000000001"); + expect(response.repayment?.basisPoints).toBe(1500); + }); +}); diff --git a/src/services/index.ts b/src/services/index.ts index 93f6b40e9..e1222379f 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -3,6 +3,7 @@ export { default as BalanceControlAPI } from "./balanceControl"; export { default as BalancePlatformAPI } from "./balancePlatform"; +export { default as CapitalAPI } from "./capital"; export { default as BinLookupAPI } from "./binLookup"; export { default as CheckoutAPI } from "./checkout"; export { default as DataProtectionAPI } from "./dataProtection"; diff --git a/src/typings/index.ts b/src/typings/index.ts index bbd23b760..7c87334f4 100644 --- a/src/typings/index.ts +++ b/src/typings/index.ts @@ -12,6 +12,7 @@ export * as balanceControl from "./balanceControl/models"; export * as balancePlatform from "./balancePlatform/models"; export * as binlookup from "./binLookup/models"; +export * as capital from "./capital/models"; export * as checkout from "./checkout/models"; export * as dataProtection from "./dataProtection/models"; export * as legalEntityManagement from "./legalEntityManagement/models";