2025-11-01 03:11:40 +00:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
|
|
|
|
|
|
vi.mock('@/api/auth', () => {
|
|
|
|
|
return {
|
|
|
|
|
currentUser: vi.fn(async () => null),
|
|
|
|
|
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')
|
2025-11-01 03:41:55 +00:00
|
|
|
const auth = useAuth()
|
|
|
|
|
const { user } = auth
|
2025-11-01 03:11:40 +00:00
|
|
|
expect(user.value).toBeNull()
|
|
|
|
|
// Implemented method should exist
|
2025-11-01 03:41:55 +00:00
|
|
|
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)
|
2025-11-01 03:11:40 +00:00
|
|
|
expect(user.value?.displayName).toBe('New User')
|
|
|
|
|
})
|
|
|
|
|
})
|