24 lines
858 B
TypeScript
24 lines
858 B
TypeScript
|
|
import { describe, it, expect } from 'vitest'
|
||
|
|
import { server, http, HttpResponse } from './test-setup'
|
||
|
|
import { useAuth } from '@/composables/useAuth'
|
||
|
|
|
||
|
|
describe('useAuth fetchHouseholds', () => {
|
||
|
|
it('loads households and stores them', async () => {
|
||
|
|
server.use(
|
||
|
|
http.get('*/api/v1/users/me/households', () => {
|
||
|
|
return HttpResponse.json([
|
||
|
|
{ id: 1, name: 'Smiths', slug: 'the-smiths' },
|
||
|
|
{ id: 2, name: 'Johnsons', slug: 'the-johnsons' },
|
||
|
|
])
|
||
|
|
})
|
||
|
|
)
|
||
|
|
const { households, fetchHouseholds, setActiveHousehold, activeHousehold } = useAuth()
|
||
|
|
expect(households.value).toEqual([])
|
||
|
|
const hs = await fetchHouseholds()
|
||
|
|
expect(hs.length).toBe(2)
|
||
|
|
expect(households.value[0].slug).toBe('the-smiths')
|
||
|
|
setActiveHousehold(hs[1])
|
||
|
|
expect(activeHousehold.value?.slug).toBe('the-johnsons')
|
||
|
|
})
|
||
|
|
})
|