Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/client/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, expect, test } from "vitest";
import { StripeSubscriptions, registerRoutes } from "./index.js";
import { components } from "./setup.test.js";

describe("StripeSubscriptions client", () => {
test("should create Stripe client with component", async () => {
const client = new StripeSubscriptions(components.stripe);
expect(client).toBeDefined();
expect(client.component).toBeDefined();
});

test("should accept STRIPE_SECRET_KEY option", async () => {
const client = new StripeSubscriptions(components.stripe, {
STRIPE_SECRET_KEY: "sk_test_123",
});
expect(client).toBeDefined();
// The apiKey getter should return the provided key
expect(client.apiKey).toBe("sk_test_123");
});

test("should throw error when accessing apiKey without key set", async () => {
// Clear the environment variable temporarily
const originalKey = process.env.STRIPE_SECRET_KEY;
delete process.env.STRIPE_SECRET_KEY;

const client = new StripeSubscriptions(components.stripe);

expect(() => client.apiKey).toThrow(
"STRIPE_SECRET_KEY environment variable is not set"
);

// Restore the environment variable
if (originalKey) {
process.env.STRIPE_SECRET_KEY = originalKey;
}
});
});

describe("registerRoutes", () => {
test("registerRoutes function should be exported", () => {
expect(typeof registerRoutes).toBe("function");
});
});
25 changes: 25 additions & 0 deletions src/client/setup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference types="vite/client" />
import { test } from "vitest";
import { convexTest } from "convex-test";
import {
componentsGeneric,
defineSchema,
type GenericSchema,
type SchemaDefinition,
} from "convex/server";
import type { ComponentApi } from "../component/_generated/component.js";

const modules = import.meta.glob("./**/*.*s");

export function initConvexTest<
Schema extends SchemaDefinition<GenericSchema, boolean>,
>(schema?: Schema) {
const t = convexTest(schema ?? defineSchema({}), modules);
return t;
}

export const components = componentsGeneric() as unknown as {
stripe: ComponentApi;
};

test("setup", () => {});
Loading
Loading