import { describe, expect, it } from "vitest"; import { createActor, waitFor } from "xstate"; import { createTestAuthMachine } from "./auth-machine.test-utils"; describe("auth credentials flow", () => { it("email login updates login status", async () => { const actor = createActor(createTestAuthMachine()).start(); actor.send({ type: "AuthEmailLoginSubmitted", email: "user@example.com", password: "12345678", }); await waitFor(actor, (snapshot) => snapshot.matches("idle")); expect(actor.getSnapshot().context).toMatchObject({ loginStatus: "email", hasInitialized: true, }); actor.stop(); }); it("registration completes through the email session", async () => { const actor = createActor(createTestAuthMachine()).start(); actor.send({ type: "AuthEmailRegisterSubmitted", email: "user@example.com", password: "12345678", username: "User", confirmPassword: "12345678", }); await waitFor(actor, (snapshot) => snapshot.matches("idle")); expect(actor.getSnapshot().context.loginStatus).toBe("email"); actor.stop(); }); });