Skip to content

Commit

Permalink
add confirmed_at to memberships (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
langalex authored Jul 23, 2024
1 parent a5040a9 commit 6ea82f7
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cobot-zapier",
"version": "2.2.2",
"version": "2.2.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
67 changes: 66 additions & 1 deletion src/test/triggers/triggerMembershipConfirmed.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
import { createAppTester } from "zapier-platform-core";
import * as nock from "nock";
import App from "../../index";
import { prepareMocksForWebhookSubscribeTest } from "../utils/prepareMocksForWebhookSubscribeTest";
import {
prepareBundle,
prepareMocksForWebhookSubscribeTest,
} from "../utils/prepareMocksForWebhookSubscribeTest";
import triggerMembershipConfirmed from "../../triggers/triggerMembershipConfirmed";
import { HookTrigger } from "../../types/trigger";
import { MembershipApiResponse } from "../../types/api-responses";
import { MembershipOutput } from "../../types/outputs";
import trigger from "../../triggers/triggerMembershipConfirmed";

const appTester = createAppTester(App);
nock.disableNetConnect();

const membershipResponse: MembershipApiResponse = {
id: "003b37a3-f205-5d9e-9caf-c4ca612075d4",
name: "Sam Duncan",
email: "[email protected]",
phone: null,
address: {
company: "Acme inc",
name: "Sam Duncan",
full_address: "982 Ruguw Terrace",
},
payment_method: {
name: "Credit Card",
},
plan: {
name: "Full Time",
},
customer_number: "123",
confirmed_at: "2012/04/12 12:00:00 +0000",
};

const membershipOutput: MembershipOutput = {
id: "003b37a3-f205-5d9e-9caf-c4ca612075d4",
name: "Sam Duncan",
company: "Acme inc",
email: "[email protected]",
customer_number: "123",
plan_name: "Full Time",
payment_method_name: "Credit Card",
confirmed_at: "2012-04-12",
};

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

describe("triggerMembershipConfirmed", () => {
Expand All @@ -27,4 +64,32 @@ describe("triggerMembershipConfirmed", () => {
}
`);
});

it("lists recent memberships", async () => {
const bundle = prepareBundle();
const api1Scope = nock("https://trial.cobot.me");
api1Scope.get("/api/memberships").reply(200, [membershipResponse]);

const listMemberships = trigger.operation.performList;

const results = await appTester(listMemberships as any, bundle as any);
expect(nock.isDone()).toBe(true);
expect(results).toStrictEqual([membershipOutput]);
});

it("triggers on membership confirmed", async () => {
const bundle = prepareBundle({
url: "https://trial.cobot.me/api/memberships/m1",
});
const api1Scope = nock("https://trial.cobot.me");
api1Scope.get("/api/memberships/m1").reply(200, membershipResponse);
const results = await appTester(
triggerMembershipConfirmed.operation.perform as any,
bundle as any,
);

expect(nock.isDone()).toBe(true);

expect(results).toStrictEqual([membershipOutput]);
});
});
4 changes: 1 addition & 3 deletions src/types/api-responses.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export type MembershipApiResponse = {
name: string;
email: string | null;
phone: string | null;
picture: string;
address: {
company: string | null;
name: string | null;
Expand All @@ -179,8 +178,7 @@ export type MembershipApiResponse = {
payment_method: {
name: string;
} | null;
starts_at: string;
canceled_at: string | null;
confirmed_at: string | null;
};

type ResourceApiResponse = {
Expand Down
1 change: 1 addition & 0 deletions src/types/outputs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type MembershipOutput = {
customer_number: string | null;
plan_name: string;
payment_method_name: string | null;
confirmed_at: string | null;
};

export type InvoiceMembershipOutput = {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/api-to-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export function apiResponseToMembershipOutput(
customer_number: membership.customer_number,
plan_name: membership.plan.name,
payment_method_name: membership.payment_method?.name ?? null,
confirmed_at:
membership.confirmed_at?.replaceAll("/", "-").substring(0, 10) ?? null,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const membershipSample: MembershipOutput = {
customer_number: "123",
plan_name: "Full Time",
payment_method_name: "Credit Card",
confirmed_at: "2012-04-12",
};

export const invoiceSample: InvoiceOutput = {
Expand Down

0 comments on commit 6ea82f7

Please sign in to comment.