|
| 1 | +import nock from "nock"; |
| 2 | +import Client from "../client"; |
| 3 | +import { createClient } from "../__mocks__/base"; |
| 4 | +import { AccountVerificationApi } from "../services/openBanking/accountVerificationApi"; |
| 5 | +import { |
| 6 | + AccountType, |
| 7 | + AccountVerificationCountry, |
| 8 | + AccountVerificationReportResponse, |
| 9 | + AccountVerificationRoutesRequest, |
| 10 | + AccountVerificationRoutesResponse, |
| 11 | + PartyRole, |
| 12 | +} from "../typings/openBanking/models"; |
| 13 | + |
| 14 | +let client: Client; |
| 15 | +let accountVerificationApi: AccountVerificationApi; |
| 16 | +let scope: nock.Scope; |
| 17 | + |
| 18 | +beforeEach((): void => { |
| 19 | + if (!nock.isActive()) { |
| 20 | + nock.activate(); |
| 21 | + } |
| 22 | + client = createClient(); |
| 23 | + scope = nock("https://obgateway-test.adyen.com/obgateway/v1"); |
| 24 | + accountVerificationApi = new AccountVerificationApi(client); |
| 25 | +}); |
| 26 | + |
| 27 | +afterEach(() => { |
| 28 | + nock.cleanAll(); |
| 29 | +}); |
| 30 | + |
| 31 | +describe("Open Banking", (): void => { |
| 32 | + it("should create account verification routes", async (): Promise<void> => { |
| 33 | + const request: AccountVerificationRoutesRequest = { |
| 34 | + country: AccountVerificationCountry.Nl, |
| 35 | + locale: "en-US", |
| 36 | + state: "11a1e60a-18b0-4dda-9258-e0ae29e1e2a3", |
| 37 | + redirectUrl: "https://merchanturl.example.org/redirect/url", |
| 38 | + }; |
| 39 | + |
| 40 | + const mockResponse: AccountVerificationRoutesResponse = { |
| 41 | + routes: [ |
| 42 | + { |
| 43 | + provider: { |
| 44 | + name: "Tink", |
| 45 | + logoURL: "https://obgateway.adyen.com/obgateway/static/provider/images/tink-logo.svg", |
| 46 | + }, |
| 47 | + link: "https://obgateway.adyen.com/obgateway/provider/outgoing/tink/redirect/13ec4802-c987-4f8c-8909-9a75ff567256", |
| 48 | + }, |
| 49 | + ], |
| 50 | + }; |
| 51 | + |
| 52 | + scope.post("/accountVerification/routes") |
| 53 | + .reply(200, mockResponse); |
| 54 | + |
| 55 | + const response = await accountVerificationApi.createAccountVerificationRoutes(request); |
| 56 | + |
| 57 | + expect(response.routes.length).toBe(1); |
| 58 | + expect(response.routes[0].link).toEqual("https://obgateway.adyen.com/obgateway/provider/outgoing/tink/redirect/13ec4802-c987-4f8c-8909-9a75ff567256"); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should get account verification report", async (): Promise<void> => { |
| 62 | + const code = "some_code"; |
| 63 | + const mockResponse: AccountVerificationReportResponse = { |
| 64 | + id: "69ee9452ef824fe092f1417f37535755", |
| 65 | + country: AccountVerificationCountry.Es, |
| 66 | + accounts: [ |
| 67 | + { |
| 68 | + accountId: "ed5080e4f485430290475d246534c8fd", |
| 69 | + accountType: AccountType.Current, |
| 70 | + accountName: "Checking Account 1", |
| 71 | + accountNumber: "ES1376230223254275408743", |
| 72 | + currency: "EUR", |
| 73 | + identifiers: { |
| 74 | + iban: { |
| 75 | + iban: "ES1376230223254275408743", |
| 76 | + bban: "76230223254275408743", |
| 77 | + bic: "BIC001" |
| 78 | + }, |
| 79 | + }, |
| 80 | + parties: [ |
| 81 | + { |
| 82 | + identity: { |
| 83 | + fullLegalName: "Alberta Bobbeth Charleson", |
| 84 | + name: "Alberta Bobbeth Charleson", |
| 85 | + }, |
| 86 | + role: PartyRole.Holder, |
| 87 | + }, |
| 88 | + ], |
| 89 | + bankName: "Tink Demo Bank", |
| 90 | + }, |
| 91 | + ], |
| 92 | + }; |
| 93 | + |
| 94 | + scope.get(`/accountVerification/reports/${code}`) |
| 95 | + .reply(200, mockResponse); |
| 96 | + |
| 97 | + const response = await accountVerificationApi.getAccountVerificationReport(code); |
| 98 | + |
| 99 | + expect(response.id).toEqual("69ee9452ef824fe092f1417f37535755"); |
| 100 | + expect(response.country).toEqual(AccountVerificationCountry.Es); |
| 101 | + expect(response.accounts.length).toBe(1); |
| 102 | + |
| 103 | + }); |
| 104 | +}); |
0 commit comments