|
| 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