Skip to main content

test

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<{
accounts: TableDefinition<VObject<{
provider: string;
providerAccountId: string;
userId: string;
}, {
provider: VString<string, "required">;
providerAccountId: VString<string, "required">;
userId: VString<string, "required">;
}, "required", "userId" | "provider" | "providerAccountId">, {
by_provider_account: ["provider", "providerAccountId", "_creationTime"];
by_user: ["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<{
accountId: Id<"accounts">;
userId: string;
}, {
accountId: VId<Id<"accounts">, "required">;
userId: VString<string, "required">;
}, "required", "userId" | "accountId">, {
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;