transactional-locales.test.js 1.4 KB
import { describe, expect, it } from 'vitest'

import { render as renderVerifyCode } from '../src/templates/verify-code.js'
import { render as renderWaitlistInvite } from '../src/templates/waitlist-invite.js'

const SITE_LOCALES = ['en', 'zh', 'ja', 'ko', 'es', 'pt']

describe('transactional email locale coverage', () => {
  it.each(SITE_LOCALES)('renders the %s verification code email', locale => {
    const message = renderVerifyCode({ locale, code: '123456', ttlMin: 10 })
    expect(message.subject).toContain('123456')
    expect(message.text).toContain('123456')
    expect(message.html).toContain('123456')
  })

  it.each(SITE_LOCALES)('renders the %s waitlist invitation email', locale => {
    const message = renderWaitlistInvite({
      locale,
      inviteUrl: 'https://voko.world/invite/ABC12345',
    })
    expect(message.text).toContain('https://voko.world/invite/ABC12345')
    expect(message.html).toContain('https://voko.world/invite/ABC12345')
  })

  it('rejects missing and unsupported locales instead of silently using English', () => {
    expect(() => renderVerifyCode({ code: '123456', ttlMin: 10 })).toThrow('unsupported locale: undefined')
    expect(() => renderVerifyCode({ locale: 'id', code: '123456', ttlMin: 10 })).toThrow('unsupported locale: id')
    expect(() => renderWaitlistInvite({ locale: 'id', inviteUrl: 'https://voko.world/invite/ABC12345' })).toThrow('unsupported locale: id')
  })
})