t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Stripe/RestrictedApiKey.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

92 lines
2.7 KiB
TypeScript

import * as Stripe from "@/Stripe";
import * as Test from "@/Test/Alchemy";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
import * as Redacted from "effect/Redacted";
import { MinimumLogLevel } from "effect/References";
const { test } = Test.make({ providers: Stripe.providers() });
const logLevel = Effect.provideService(
MinimumLogLevel,
process.env.DEBUG ? "Debug" : "Info",
);
test.provider(
"creates a logical restricted key with default props",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const created = yield* stack.deploy(
Effect.gen(function* () {
const token = yield* Stripe.RestrictedApiKey("HostToken");
yield* token.bind("RetrieveProduct", {
permissions: ["products_read"],
});
return token;
}),
);
expect(created.id).toEqual(expect.any(String));
expect(created.name).toEqual(expect.any(String));
expect(Redacted.isRedacted(created.value)).toEqual(true);
expect(created.permissions).toEqual(["products_read"]);
yield* stack.destroy();
}).pipe(logLevel),
{
tags: ["provider:stripe", "provider:stripe:restrictedapikey", "live"],
timeout: 120_000,
},
);
test.provider(
"creates a logical restricted key and merges bound permissions",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const created = yield* stack.deploy(
Effect.gen(function* () {
const token = yield* Stripe.RestrictedApiKey("HostToken", {
permissions: ["customers_read"],
});
yield* token.bind("RetrieveProduct", {
permissions: ["products_read"],
});
return token;
}),
);
expect(created.id).toEqual(expect.any(String));
expect(created.name).toEqual(expect.any(String));
expect(Redacted.isRedacted(created.value)).toEqual(true);
expect(created.permissions).toEqual(["customers_read", "products_read"]);
const updated = yield* stack.deploy(
Effect.gen(function* () {
const token = yield* Stripe.RestrictedApiKey("HostToken", {
permissions: ["customers_read", "customers_write"],
});
yield* token.bind("RetrieveProduct", {
permissions: ["products_read"],
});
return token;
}),
);
expect(updated.id).toEqual(created.id);
expect(updated.permissions).toEqual([
"customers_read",
"customers_write",
"products_read",
]);
yield* stack.destroy();
}).pipe(logLevel),
{
tags: ["provider:stripe", "provider:stripe:restrictedapikey", "live"],
timeout: 120_000,
},
);