diff --git a/src/test.test.ts b/src/test.test.ts new file mode 100644 index 0000000..2fca0e1 --- /dev/null +++ b/src/test.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it, vi } from "vitest"; +import type { TestConvex } from "convex-test"; +import type { GenericSchema, SchemaDefinition } from "convex/server"; +import r2Test from "./test.js"; + +type TestInstance = TestConvex>; + +function registeredNames(name?: string) { + const registerComponent = vi.fn(); + const t = { registerComponent } as unknown as TestInstance; + if (name === undefined) { + r2Test.register(t); + } else { + r2Test.register(t, name); + } + return registerComponent.mock.calls.map((call) => call[0] as string); +} + +describe("register", () => { + it("registers action-retrier as a child of the r2 component", () => { + const names = registeredNames(); + + expect(names).toContain("r2"); + expect(names).toContain("r2/actionRetrier"); + expect(names).not.toContain("actionRetrier"); + }); + + it("nests action-retrier under a custom component name", () => { + const names = registeredNames("storage"); + + expect(names).toContain("storage"); + expect(names).toContain("storage/actionRetrier"); + expect(names).not.toContain("actionRetrier"); + }); +}); diff --git a/src/test.ts b/src/test.ts index 43a54b4..94d2c32 100644 --- a/src/test.ts +++ b/src/test.ts @@ -17,7 +17,9 @@ export function register( t: TestConvex>, name: string = "r2", ) { - actionRetrier.register(t); - return t.registerComponent(name, schema, modules) as unknown as ComponentApi; + const component = t.registerComponent(name, schema, modules); + // The component installs action-retrier as a child, so it lives at "/actionRetrier". + actionRetrier.register(t, `${name}/actionRetrier`); + return component as unknown as ComponentApi; } export default { register, schema, modules };