34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { server, http, HttpResponse } from './test-setup'
|
|
import { loginWithPassword } from '@/api/auth'
|
|
import { sendInvitation } from '@/api/invitations'
|
|
import { setHouseholdSlugProvider } from '@/api/client'
|
|
|
|
describe('invitations api (send invite)', () => {
|
|
it('posts email with Authorization and X-Household-Slug', async () => {
|
|
// Simulate auth token
|
|
server.use(
|
|
http.post('*/api/v1/auth/login', () =>
|
|
HttpResponse.json({ accessToken: 'tokABC', tokenType: 'bearer', user: { id: 4, email: 'x@y', displayName: 'X' } })
|
|
)
|
|
)
|
|
await loginWithPassword('x@y', 'pw')
|
|
|
|
// Provide a household slug for header injection
|
|
setHouseholdSlugProvider(() => 'the-smiths')
|
|
|
|
server.use(
|
|
http.post('*/api/v1/invitations', async ({ request }) => {
|
|
const body = await request.json()
|
|
expect(body).toEqual({ email: 'invite@example.com' })
|
|
const auth = request.headers.get('authorization')
|
|
expect(auth?.toLowerCase()).toBe('bearer tokabc')
|
|
const slug = request.headers.get('x-household-slug')
|
|
expect(slug).toBe('the-smiths')
|
|
return HttpResponse.json({}, { status: 204 })
|
|
})
|
|
)
|
|
|
|
await expect(sendInvitation('invite@example.com')).resolves.toBeUndefined()
|
|
})
|
|
})
|