32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
|
|
import { describe, it, expect } from 'vitest'
|
||
|
|
import { server, http, HttpResponse } from './test-setup'
|
||
|
|
import { loginWithPassword } from '@/api/auth'
|
||
|
|
import { acceptInvitation } from '@/api/invitations'
|
||
|
|
|
||
|
|
describe('invitations api', () => {
|
||
|
|
it('acceptInvitation posts token and returns household slug', async () => {
|
||
|
|
// simulate login so Authorization header is present
|
||
|
|
server.use(
|
||
|
|
http.post('*/api/v1/auth/login', () =>
|
||
|
|
HttpResponse.json({ accessToken: 'tok123', tokenType: 'bearer', user: { id: 9, email: 'u@e', displayName: 'U' } })
|
||
|
|
)
|
||
|
|
)
|
||
|
|
await loginWithPassword('u@e', 'pw')
|
||
|
|
|
||
|
|
server.use(
|
||
|
|
http.post('*/api/v1/invitations/accept', async ({ request }) => {
|
||
|
|
const body = await request.json()
|
||
|
|
expect(body).toEqual({ token: 'abc' })
|
||
|
|
const auth = request.headers.get('authorization')
|
||
|
|
expect(auth?.toLowerCase()).toBe('bearer tok123')
|
||
|
|
return HttpResponse.json({ household: { id: 1, name: 'Smiths', slug: 'the-smiths' } })
|
||
|
|
})
|
||
|
|
)
|
||
|
|
|
||
|
|
const result = await acceptInvitation('abc')
|
||
|
|
expect(result.slug).toBe('the-smiths')
|
||
|
|
expect(result.name).toBe('Smiths')
|
||
|
|
expect(result.id).toBe(1)
|
||
|
|
})
|
||
|
|
})
|