munch-ease-frontend/tests/useAuth.createAccount.test.ts

32 lines
1.3 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('@/api/auth', () => {
return {
currentUser: vi.fn(async () => null),
login: vi.fn(async () => ({ id: 1, email: 'legacy@example.com', displayName: 'Legacy' })),
loginWithPassword: vi.fn(async (email: string) => ({ id: 2, email, displayName: email })),
createAccount: vi.fn(async (email: string, displayName: string) => ({ id: 77, email, displayName })),
logout: vi.fn(async () => {}),
handleGoogleLogin: vi.fn(async () => {
throw new Error('handleGoogleLogin not implemented yet')
}),
}
})
describe('useAuth.createAccount', () => {
beforeEach(() => {
vi.resetModules()
})
it('updates user after successful createAccount', async () => {
const { useAuth } = await import('@/composables/useAuth')
const auth = useAuth()
const { user } = auth
expect(user.value).toBeNull()
// Implemented method should exist
expect(typeof (auth as Record<string, unknown>).createAccount).toBe('function')
const newUser = await (auth as unknown as { createAccount: (e: string, d: string, p: string) => Promise<{ id: number; displayName: string }> }).createAccount('new@example.com', 'New User', 'pw')
expect(newUser.id).toBe(77)
expect(user.value?.displayName).toBe('New User')
})
})