Skip to content

Commit

Permalink
Add ECInfo resource
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 committed Jul 7, 2021
1 parent 9569c93 commit 5995997
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { RestAPIOptions } from "./api/RestAPI";
import { ECInfo } from "./resources/ECInfo";
import { WebHookTrigger as PublicWebHookTrigger } from "./resources/WebHooks";
import {
BankAccounts,
Expand Down Expand Up @@ -40,6 +41,7 @@ export default class SDK<WebhookTrigger = PublicWebHookTrigger> extends Payments
public captures: Captures;
public charges: Charges;
public checkoutInfo: CheckoutInfo;
public ecInfo: ECInfo;
public ecFormLinks: ECFormLinks;
public ecForms: ECForms;
public emails: Emails;
Expand All @@ -63,6 +65,7 @@ export default class SDK<WebhookTrigger = PublicWebHookTrigger> extends Payments
this.captures = new Captures(this.api);
this.charges = new Charges(this.api);
this.checkoutInfo = new CheckoutInfo(this.api);
this.ecInfo = new ECInfo(this.api);
this.ecFormLinks = new ECFormLinks(this.api);
this.ecForms = new ECForms(this.api);
this.emails = new Emails(this.api);
Expand Down
34 changes: 34 additions & 0 deletions src/resources/ECInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @module Resources/ECInfo
*/
import { AuthParams, ResponseCallback, SendData } from "../api/RestAPI";

import { CRUDResource } from "./CRUDResource";
import { ECFormLinkItem } from "./ECFormLinks";
import { ECFormItem } from "./ECForms";
import { EmailItem } from "./Emails";

export type ECInfoItem = {
id: string;
jwt: string;

form: ECFormItem;
link: ECFormLinkItem;
email: EmailItem;
};

export type ECInfoGetParams = { secret: string };
export type ResponseECInfo = ECInfoItem;

export class ECInfo extends CRUDResource {
static routeBase = "/checkout/info";

get(
id: string,
data?: SendData<ECInfoGetParams>,
auth?: AuthParams,
callback?: ResponseCallback<ResponseECInfo>
): Promise<ResponseECInfo> {
return this._getRoute()(data, callback, auth, { id });
}
}
16 changes: 16 additions & 0 deletions test/fixtures/ec-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { v4 as uuid } from "uuid";

import { ECInfoItem } from "../../src/resources/ECInfo";

import { generateFixture as generateForm } from "./ec-form";
import { generateFixture as generateLink } from "./ec-form-link";
import { generateFixture as generateEmail } from "./emails";

export const generateFixture = (): ECInfoItem => ({
id: uuid(),
jwt: "myjwt",

form: generateForm(),
link: generateLink(),
email: generateEmail(),
});
48 changes: 48 additions & 0 deletions test/specs/ec-info.specs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { expect } from "chai";
import fetchMock from "fetch-mock";
import { pathToRegexp } from "path-to-regexp";
import { v4 as uuid } from "uuid";

import { RestAPI } from "../../src/api/RestAPI";
import { ECInfo } from "../../src/resources/ECInfo";
import { generateFixture as generateCheckoutInfo } from "../fixtures/ec-info";
import { testEndpoint } from "../utils";

describe("EC Form links", () => {
let api: RestAPI;
let ecInfo: ECInfo;

const recordData = generateCheckoutInfo();
const recordPathMatcher = new RegExp(
`^${testEndpoint}${pathToRegexp("/checkout/info/:id", [], { start: false, end: false }).source}`
);

beforeEach(() => {
api = new RestAPI({ endpoint: testEndpoint });
ecInfo = new ECInfo(api);
});

afterEach(() => {
fetchMock.restore();
});

context("GET /checkout/info/:id", () => {
it("should get response", async () => {
fetchMock.getOnce(
{
url: recordPathMatcher,
query: {
secret: "mysecret",
},
},
{
status: 200,
body: recordData,
headers: { "Content-Type": "application/json" },
}
);

await expect(ecInfo.get(uuid(), { secret: "mysecret" })).to.eventually.eql(recordData);
});
});
});

0 comments on commit 5995997

Please sign in to comment.