Skip to main content

test

For AI agents: see llms.txt for the complete documentation index. Markdown versions are available by adding .md to a page URL or requesting Accept: text/markdown.

Variables​

default​

default: object;

Type Declaration​

modules​
modules: Record<string, () => Promise<unknown>>;
registerCore​
registerCore: (t, name) => void;

Register the component with the test convex instance.

Parameters​
ParameterTypeDefault valueDescription
tTestConvex<SchemaDefinition<GenericSchema, boolean>>undefinedThe test convex instance, e.g. from calling convexTest.
namestring"auth"The name of the component, as registered in convex.config.ts.
Returns​

void

schema​
schema: SchemaDefinition<
{
createdUserIds: TableDefinition<
VObject<
{
userId: string;
},
{
userId: VString<string, "required">;
},
"required",
"userId"
>,
{
by_userId: ["userId", "_creationTime"];
},
{},
{}
>;
refreshTokens: TableDefinition<
VObject<
{
hash: string;
retiredAt?: number;
sessionId: Id<"sessions">;
state: "issued" | "redeemed" | "spent" | "dropped";
},
{
hash: VString<string, "required">;
retiredAt: VFloat64<number | undefined, "optional">;
sessionId: VId<Id<"sessions">, "required">;
state: VUnion<
"issued" | "redeemed" | "spent" | "dropped",
[
VLiteral<"issued", "required">,
VLiteral<"redeemed", "required">,
VLiteral<"spent", "required">,
VLiteral<"dropped", "required">,
],
"required",
never
>;
},
"required",
"state" | "hash" | "sessionId" | "retiredAt"
>,
{
by_hash: ["hash", "_creationTime"];
by_session_state: ["sessionId", "state", "retiredAt", "_creationTime"];
},
{},
{}
>;
sessions: TableDefinition<
VObject<
{
component: string;
userId: string;
},
{
component: VString<string, "required">;
userId: VString<string, "required">;
},
"required",
"userId" | "component"
>,
{
by_user: ["userId", "_creationTime"];
},
{},
{}
>;
},
true
>;
sessionIdentity​
sessionIdentity: (tokens) => object;

The identity Convex derives from the access token of a sign-in, for t.withIdentity. The token's subject is the session id, and the core looks the user up through the session, so a test signs in for real and calls as that session:

const result = await t.mutation(api.auth.signUpWithUsernamePassword, {
username: "alice",
password: "correct horse battery staple",
});
if (result.status !== "complete") throw new Error("sign-up failed");
const alice = t.withIdentity(sessionIdentity(result.tokens));
Parameters​
ParameterType
tokens{ accessToken: string; }
tokens.accessTokenstring
Returns​

object

subject​
subject: string;

Functions​

registerCore()​

function registerCore(t, name?): void;

Register the component with the test convex instance.

Parameters​

ParameterTypeDefault valueDescription
tTestConvex<SchemaDefinition<GenericSchema, boolean>>undefinedThe test convex instance, e.g. from calling convexTest.
namestring"auth"The name of the component, as registered in convex.config.ts.

Returns​

void


sessionIdentity()​

function sessionIdentity(tokens): object;

The identity Convex derives from the access token of a sign-in, for t.withIdentity. The token's subject is the session id, and the core looks the user up through the session, so a test signs in for real and calls as that session:

const result = await t.mutation(api.auth.signUpWithUsernamePassword, {
username: "alice",
password: "correct horse battery staple",
});
if (result.status !== "complete") throw new Error("sign-up failed");
const alice = t.withIdentity(sessionIdentity(result.tokens));

Parameters​

ParameterType
tokens{ accessToken: string; }
tokens.accessTokenstring

Returns​

object

subject​
subject: string;