import { describe, expect, it } from 'vitest' import { ApiError } from '@/lib/apiError' import { inlineRefusal, refusalToast, userToast } from '@/lib/userRefusal' import { inviteWindow } from '@/lib/users' describe('userToast', () => { it('builds a success toast with the check icon and lazy text', () => { let title = 'first' const build = userToast('id-1', 'success', () => title, 'fixed') const toast = build() expect(toast).toMatchObject({ id: 'id-1', color: 'success', icon: 'i-lucide-circle-check', title: 'first', description: 'fixed', }) title = 'second' expect(toast.title).toBe('second') }) it('builds an error toast with the cross icon', () => { expect(userToast('id-2', 'error', 'Oops', 'Try again')()).toMatchObject({ id: 'id-2', color: 'error', icon: 'i-lucide-circle-x', title: 'Oops', description: 'Try again', }) }) }) describe('refusalToast', () => { it('shows the refusal copy of an inline refusal as an error toast', () => { const refusal = inlineRefusal( new ApiError(403, undefined, 'own_role', { code: 'own_role' }), )! expect(refusalToast('refused-1', refusal)()).toMatchObject({ id: 'refused-1', color: 'error', title: refusal.title, description: refusal.description, }) expect(refusal.title).toBeTruthy() }) }) describe('inviteWindow', () => { const created = '2026-10-01T09:00:00Z' it.each([ ['2026-10-02T09:00:00Z', '1 day'], ['2026-10-04T09:00:00Z', '3 days'], ['2026-10-08T09:00:00Z', '7 days'], ['2026-10-01T09:00:00Z', '1 day'], ])('words an expiry at %s as %s', (expires, wording) => { expect(inviteWindow({ created_at: created, expires_at: expires })).toBe(wording) }) })