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

32 lines
1.2 KiB
TypeScript
Raw Normal View History

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 { user, createHousehold, fetchHouseholds, ...rest } = useAuth() as any
expect(user.value).toBeNull()
// Implemented method should exist
expect(typeof rest.createAccount).toBe('function')
const newUser = await rest.createAccount('new@example.com', 'New User', 'pw')
expect(newUser.id).toBe(77)
expect(user.value?.displayName).toBe('New User')
})
})