42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { memoryPaymentStore } from "../src/store.ts";
|
|
import { paymentOptionsFromConfig } from "../src/config.ts";
|
|
|
|
test("configuration creates any number of named provider gateways", () => {
|
|
const options = paymentOptionsFromConfig(
|
|
{
|
|
default: "india",
|
|
environment: "test",
|
|
gateways: {
|
|
india: {
|
|
provider: "razorpay",
|
|
keyId: "rzp_test",
|
|
keySecret: "secret",
|
|
webhookSecret: "razorpay-hook",
|
|
},
|
|
global: {
|
|
provider: "stripe",
|
|
secretKey: "sk_test",
|
|
publishableKey: "pk_test",
|
|
webhookSecret: "stripe-hook",
|
|
},
|
|
disabled: false,
|
|
},
|
|
},
|
|
memoryPaymentStore(),
|
|
);
|
|
|
|
expect(options.default).toBe("india");
|
|
expect(options.adapters.map((adapter) => adapter.id)).toEqual(["india", "global"]);
|
|
expect(options.webhookSecrets).toEqual({ india: "razorpay-hook", global: "stripe-hook" });
|
|
});
|
|
|
|
test("configuration rejects a disabled or missing default gateway", () => {
|
|
expect(() =>
|
|
paymentOptionsFromConfig(
|
|
{ default: "missing", gateways: { sandbox: { provider: "sandbox" } } },
|
|
memoryPaymentStore(),
|
|
),
|
|
).toThrow("default gateway 'missing' is not enabled or configured");
|
|
});
|