Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

1.5 KB
Raw Blame
import { expect, test } from 'vitest'
import { i18n } from '../i18n/index.tsx'
import { formErrors, ownerInput } from './NewWorkspace.tsx'

const t = (...args: Parameters<ReturnType<typeof i18n>['t']>) => i18n().t(...args)
const form = { name: 'Riverside Electric', country: 'US', owner: 'me' as const, ownerEmail: '', ownerName: '' }

test('owner Me needs only the business name and its country', () => {
  expect(formErrors(form, t)).toEqual({})
  expect(formErrors({ ...form, name: '  ' }, t).name).toBe(t('shell.newWorkspace.nameMissing'))
})

test('a new workspace never starts without a country', () => {
  expect(formErrors({ ...form, country: '' }, t).country).toBe(t('shell.newWorkspace.countryMissing'))
  expect(formErrors({ ...form, country: 'DE' }, t)).toEqual({})
})

test('owner by email needs a valid address; the name stays optional', () => {
  expect(formErrors({ ...form, owner: 'other' }, t).ownerEmail).toBeTruthy()
  expect(formErrors({ ...form, owner: 'other', ownerEmail: 'not-an-address' }, t).ownerEmail).toBeTruthy()
  expect(formErrors({ ...form, owner: 'other', ownerEmail: '[email protected]' }, t)).toEqual({})
})

test('the owner is sent trimmed, with a name only when one was given', () => {
  expect(ownerInput({ ownerEmail: ' [email protected] ', ownerName: ' ' })).toEqual({
    email: '[email protected]',
  })
  expect(ownerInput({ ownerEmail: '[email protected]', ownerName: ' Ana Ruiz ' })).toEqual({
    email: '[email protected]',
    name: 'Ana Ruiz',
  })
})