@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 131 lines 4.6 KB
Raw
1 import * as Stripe from "@alchemy.run/stripe";
2 import { isMissingStripeResource } from "@alchemy.run/stripe/missing";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import { GetPaymentMethodDomain } from "@distilled.cloud/stripe/stripe";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8 import { MinimumLogLevel } from "effect/References";
9 import * as Schedule from "effect/Schedule";
10
11 const { test } = Test.make({ providers: Stripe.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const isMissing = isMissingStripeResource;
16
17 const waitUntilDisabled = (id: string) =>
18 GetPaymentMethodDomain({
19 payment_method_domain: id,
20 }).pipe(
21 Effect.map((domain) => (domain.enabled ? ("enabled" as const) : ("disabled" as const))),
22 Effect.catchIf(isMissing, () => Effect.succeed("disabled" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("1 second"),
25 until: (status) => status === "disabled",
26 times: 10,
27 }),
28 );
29
30 test.provider(
31 "create, update, and deactivate a payment method domain",
32 (stack) =>
33 Effect.gen(function* () {
34 yield* stack.destroy();
35
36 const created = yield* stack.deploy(
37 Effect.gen(function* () {
38 return yield* Stripe.PaymentMethodDomain("Checkout", {
39 domainName: "alchemy-pmd-lifecycle.example.com",
40 });
41 }),
42 );
43
44 expect(created.id).toMatch(/^pmd_/);
45 expect(created.domainName).toEqual("alchemy-pmd-lifecycle.example.com");
46 expect(created.enabled).toEqual(true);
47 expect(created.applePay.status).toEqual(expect.any(String));
48 expect(created.googlePay.status).toEqual(expect.any(String));
49 expect(created.link.status).toEqual(expect.any(String));
50 expect(created.paypal.status).toEqual(expect.any(String));
51 expect(created.amazonPay.status).toEqual(expect.any(String));
52 expect(created.klarna.status).toEqual(expect.any(String));
53 expect(created.created).toEqual(expect.any(Number));
54 expect(created.livemode).toEqual(false);
55
56 const fetched = yield* GetPaymentMethodDomain({
57 payment_method_domain: created.id,
58 });
59 expect(fetched.id).toEqual(created.id);
60 expect(fetched.domain_name).toEqual("alchemy-pmd-lifecycle.example.com");
61 expect(fetched.enabled).toEqual(true);
62
63 const updated = yield* stack.deploy(
64 Effect.gen(function* () {
65 return yield* Stripe.PaymentMethodDomain("Checkout", {
66 domainName: "alchemy-pmd-lifecycle.example.com",
67 enabled: false,
68 });
69 }),
70 );
71
72 expect(updated.id).toEqual(created.id);
73 expect(updated.domainName).toEqual("alchemy-pmd-lifecycle.example.com");
74 expect(updated.enabled).toEqual(false);
75
76 const refetched = yield* GetPaymentMethodDomain({
77 payment_method_domain: updated.id,
78 });
79 expect(refetched.id).toEqual(updated.id);
80 expect(refetched.domain_name).toEqual("alchemy-pmd-lifecycle.example.com");
81 expect(refetched.enabled).toEqual(false);
82
83 yield* stack.destroy();
84
85 const disabled = yield* waitUntilDisabled(created.id);
86 expect(disabled).toEqual("disabled");
87 const deactivated = yield* GetPaymentMethodDomain({
88 payment_method_domain: created.id,
89 });
90 expect(deactivated.enabled).toEqual(false);
91 }).pipe(logLevel),
92 {
93 tags: ["provider:stripe", "provider:stripe:paymentmethoddomain", "live"],
94 timeout: 120_000,
95 },
96 );
97
98 test.provider(
99 "list enumerates the deployed payment method domain",
100 (stack) =>
101 Effect.gen(function* () {
102 yield* stack.destroy();
103
104 const deployed = yield* stack.deploy(
105 Effect.gen(function* () {
106 return yield* Stripe.PaymentMethodDomain("ListCheckout", {
107 domainName: "alchemy-pmd-list.example.com",
108 });
109 }),
110 );
111
112 const provider = yield* Provider.findProvider(Stripe.PaymentMethodDomain);
113 const all = yield* provider.list();
114 const found = all.find((domain) => domain.id === deployed.id);
115 expect(found).toBeDefined();
116 expect(found?.domainName).toEqual(deployed.domainName);
117 expect(found?.enabled).toEqual(true);
118
119 yield* stack.destroy();
120
121 const disabled = yield* waitUntilDisabled(deployed.id);
122 expect(disabled).toEqual("disabled");
123
124 const after = yield* provider.list();
125 expect(after.find((domain) => domain.id === deployed.id)).toBeUndefined();
126 }).pipe(logLevel),
127 {
128 tags: ["provider:stripe", "provider:stripe:paymentmethoddomain", "live"],
129 timeout: 120_000,
130 },
131 );