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
| 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 { GetPaymentMethodConfiguration } 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 waitUntilInactive = (id: string) => |
| 18 | GetPaymentMethodConfiguration({ configuration: id }).pipe( |
| 19 | Effect.map((configuration) => |
| 20 | configuration.active ? ("active" as const) : ("inactive" as const), |
| 21 | ), |
| 22 | Effect.catchIf(isMissing, () => Effect.succeed("inactive" as const)), |
| 23 | Effect.repeat({ |
| 24 | schedule: Schedule.spaced("1 second"), |
| 25 | until: (status) => status === "inactive", |
| 26 | times: 10, |
| 27 | }), |
| 28 | ); |
| 29 | |
| 30 | test.provider( |
| 31 | "create, update, and deactivate a payment method configuration", |
| 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.PaymentMethodConfiguration("Checkout", { |
| 39 | name: "Alchemy Checkout PMC", |
| 40 | card: { displayPreference: { preference: "on" } }, |
| 41 | link: { displayPreference: { preference: "off" } }, |
| 42 | }); |
| 43 | }), |
| 44 | ); |
| 45 | |
| 46 | expect(created.id).toMatch(/^pmc_/); |
| 47 | expect(created.name).toEqual("Alchemy Checkout PMC"); |
| 48 | expect(created.active).toEqual(true); |
| 49 | expect(created.isDefault).toEqual(false); |
| 50 | expect(created.card?.displayPreference.preference).toEqual("on"); |
| 51 | expect(created.link?.displayPreference.preference).toEqual("off"); |
| 52 | expect(created.livemode).toEqual(false); |
| 53 | |
| 54 | const fetched = yield* GetPaymentMethodConfiguration({ |
| 55 | configuration: created.id, |
| 56 | }); |
| 57 | expect(fetched.id).toEqual(created.id); |
| 58 | expect(fetched.name).toEqual("Alchemy Checkout PMC"); |
| 59 | expect(fetched.active).toEqual(true); |
| 60 | expect(fetched.is_default).toEqual(false); |
| 61 | expect(fetched.card?.display_preference.preference).toEqual("on"); |
| 62 | expect(fetched.link?.display_preference.preference).toEqual("off"); |
| 63 | |
| 64 | const updated = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | return yield* Stripe.PaymentMethodConfiguration("Checkout", { |
| 67 | name: "Alchemy Checkout PMC Updated", |
| 68 | card: { displayPreference: { preference: "on" } }, |
| 69 | link: { displayPreference: { preference: "on" } }, |
| 70 | }); |
| 71 | }), |
| 72 | ); |
| 73 | |
| 74 | expect(updated.id).toEqual(created.id); |
| 75 | expect(updated.name).toEqual("Alchemy Checkout PMC Updated"); |
| 76 | expect(updated.active).toEqual(true); |
| 77 | expect(updated.isDefault).toEqual(false); |
| 78 | expect(updated.card?.displayPreference.preference).toEqual("on"); |
| 79 | expect(updated.link?.displayPreference.preference).toEqual("on"); |
| 80 | |
| 81 | const refetched = yield* GetPaymentMethodConfiguration({ |
| 82 | configuration: updated.id, |
| 83 | }); |
| 84 | expect(refetched.id).toEqual(updated.id); |
| 85 | expect(refetched.name).toEqual("Alchemy Checkout PMC Updated"); |
| 86 | expect(refetched.card?.display_preference.preference).toEqual("on"); |
| 87 | expect(refetched.link?.display_preference.preference).toEqual("on"); |
| 88 | expect(refetched.active).toEqual(true); |
| 89 | |
| 90 | yield* stack.destroy(); |
| 91 | |
| 92 | const inactive = yield* waitUntilInactive(created.id); |
| 93 | expect(inactive).toEqual("inactive"); |
| 94 | const deactivated = yield* GetPaymentMethodConfiguration({ |
| 95 | configuration: created.id, |
| 96 | }); |
| 97 | expect(deactivated.active).toEqual(false); |
| 98 | }).pipe(logLevel), |
| 99 | { |
| 100 | tags: ["provider:stripe", "provider:stripe:paymentmethodconfiguration", "live"], |
| 101 | timeout: 120_000, |
| 102 | }, |
| 103 | ); |
| 104 | |
| 105 | test.provider( |
| 106 | "list enumerates the deployed payment method configuration", |
| 107 | (stack) => |
| 108 | Effect.gen(function* () { |
| 109 | yield* stack.destroy(); |
| 110 | |
| 111 | const deployed = yield* stack.deploy( |
| 112 | Effect.gen(function* () { |
| 113 | return yield* Stripe.PaymentMethodConfiguration("ListCheckout", { |
| 114 | name: "Alchemy List PMC", |
| 115 | card: { displayPreference: { preference: "on" } }, |
| 116 | }); |
| 117 | }), |
| 118 | ); |
| 119 | |
| 120 | const provider = yield* Provider.findProvider(Stripe.PaymentMethodConfiguration); |
| 121 | const all = yield* provider.list(); |
| 122 | const found = all.find((configuration) => configuration.id === deployed.id); |
| 123 | expect(found).toBeDefined(); |
| 124 | expect(found?.name).toEqual(deployed.name); |
| 125 | expect(found?.isDefault).toEqual(false); |
| 126 | expect(found?.card?.displayPreference.preference).toEqual("on"); |
| 127 | |
| 128 | yield* stack.destroy(); |
| 129 | |
| 130 | const inactive = yield* waitUntilInactive(deployed.id); |
| 131 | expect(inactive).toEqual("inactive"); |
| 132 | |
| 133 | const after = yield* provider.list(); |
| 134 | expect(after.find((configuration) => configuration.id === deployed.id)).toBeUndefined(); |
| 135 | }).pipe(logLevel), |
| 136 | { |
| 137 | tags: ["provider:stripe", "provider:stripe:paymentmethodconfiguration", "live"], |
| 138 | timeout: 120_000, |
| 139 | }, |
| 140 | ); |