components/email/test
Type Aliases
SentEmail
type SentEmail = object;
One email that the stub recorded.
Properties
| Property | Type |
|---|---|
from | string |
html? | string |
subject? | string |
text? | string |
to | string[] |
Variables
default
default: object;
Type Declaration
modules
modules: Record<string, () => Promise<unknown>>;
registerEmail
registerEmail: (t, name) => void;
Register the email component with a convex-test instance.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
t | TestConvex<SchemaDefinition<GenericSchema, boolean>> | undefined | The test convex instance, e.g. from calling convexTest. |
name | string | "authEmail" | The name of the component, as registered in convex.config.ts. |
Returns
void
schema
schema: SchemaDefinition<{
challenges: TableDefinition<VObject<{
browserSecretHash: string;
email: string;
emailCodeHash: string;
expiresAt: number;
purpose: | {
kind: "changeEmail";
userId: string;
}
| {
kind: "addEmail";
userId: string;
}
| {
kind: "signUp";
userId: string;
}
| {
kind: "custom";
purpose: string;
userId?: string;
};
}, {
browserSecretHash: VString<string, "required">;
email: VString<string, "required">;
emailCodeHash: VString<string, "required">;
expiresAt: VFloat64<number, "required">;
purpose: VUnion<
| {
kind: "changeEmail";
userId: string;
}
| {
kind: "addEmail";
userId: string;
}
| {
kind: "signUp";
userId: string;
}
| {
kind: "custom";
purpose: string;
userId?: string;
}, [VObject<{
kind: "changeEmail";
userId: string;
}, {
kind: VLiteral<..., ...>;
userId: VString<..., ...>;
}, "required", "kind" | "userId">, VObject<{
kind: "addEmail";
userId: string;
}, {
kind: VLiteral<..., ...>;
userId: VString<..., ...>;
}, "required", "kind" | "userId">, VObject<{
kind: "signUp";
userId: string;
}, {
kind: VLiteral<..., ...>;
userId: VString<..., ...>;
}, "required", "kind" | "userId">, VObject<{
kind: "custom";
purpose: string;
userId?: ... | ...;
}, {
kind: VLiteral<..., ...>;
purpose: VString<..., ...>;
userId: VString<..., ...>;
}, "required", "kind" | "userId" | "purpose">], "required", "kind" | "userId" | "purpose">;
}, "required",
| "email"
| "purpose"
| "emailCodeHash"
| "browserSecretHash"
| "expiresAt"
| "purpose.kind"
| "purpose.userId"
| "purpose.purpose">, {
by_browserSecretHash: ["browserSecretHash", "_creationTime"];
by_expiresAt: ["expiresAt", "_creationTime"];
by_purpose_userId: ["purpose.userId", "_creationTime"];
}, {
}, {
}>;
verifiedEmails: TableDefinition<VObject<{
email: string;
isPrimary: boolean;
normalizedEmail: string;
userId: string;
}, {
email: VString<string, "required">;
isPrimary: VBoolean<boolean, "required">;
normalizedEmail: VString<string, "required">;
userId: VString<string, "required">;
}, "required", "userId" | "email" | "normalizedEmail" | "isPrimary">, {
by_normalizedEmail: ["normalizedEmail", "_creationTime"];
by_userId: ["userId", "_creationTime"];
by_userId_isPrimary: ["userId", "isPrimary", "_creationTime"];
}, {
}, {
}>;
}, true>;
Functions
registerEmail()
function registerEmail(t, name?): void;
Register the email component with a convex-test instance.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
t | TestConvex<SchemaDefinition<GenericSchema, boolean>> | undefined | The test convex instance, e.g. from calling convexTest. |
name | string | "authEmail" | The name of the component, as registered in convex.config.ts. |
Returns
void
registerResendStub()
function registerResendStub(t, name?): void;
Register a stub of the @convex-dev/resend component with a
convex-test instance.
The stub records each email in its emails table instead of sending
it. Tests read the table with sentEmails to make assertions
about the sent emails.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
t | T | undefined | The test convex instance, e.g. from calling convexTest. |
name | string | "resend" | The name of the component, as registered in convex.config.ts. |
Returns
void
sentEmails()
function sentEmails(t, name?): Promise<SentEmail[]>;
The emails that the stub recorded, oldest first.
convex-test exposes runInComponent at runtime but does not declare
it, hence the cast.
Parameters
| Parameter | Type | Default value |
|---|---|---|
t | T | undefined |
name | string | "resend" |
Returns
Promise<SentEmail[]>
stubEmailSender()
function stubEmailSender(t, name?): Promise<{
apiKey: string;
from: string;
initialBackoffMs: number;
kind: "resend";
retryAttempts: number;
sendEmailHandle: string;
}>;
A sender config that points at the stub, for the start mutations of
the email component. Register the stub first.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
t | T | undefined | The test convex instance. |
name | string | "resend" | The name the stub was registered with. |
Returns
Promise<{
apiKey: string;
from: string;
initialBackoffMs: number;
kind: "resend";
retryAttempts: number;
sendEmailHandle: string;
}>