28 lines
1.1 KiB
TypeScript
28 lines
1.1 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'
|
|
|
|
describe('invitations api (send invite)', () => {
|
|
it('posts email with Authorization and householdSlug path param', 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')
|
|
|
|
server.use(
|
|
http.post('*/api/v1/households/the-smiths/invitations', async ({ request, requestId, cookies, params }) => {
|
|
const body = await request.json()
|
|
expect(body).toEqual({ email: 'invite@example.com' })
|
|
const auth = request.headers.get('authorization')
|
|
expect(auth?.toLowerCase()).toBe('bearer tokabc')
|
|
return HttpResponse.json({}, { status: 204 })
|
|
})
|
|
)
|
|
|
|
await expect(sendInvitation('the-smiths', 'invite@example.com')).resolves.toBeUndefined()
|
|
})
|
|
})
|