Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

1.5 KB
Raw Blame
import test from 'node:test'
import assert from 'node:assert/strict'
import {
  createCloudflareEmailSender,
  platformEmailReady,
} from '../apps/shared/platform/email.ts'

test('Cloudflare Email Sending uses the structured binding without REST credentials', async () => {
  const messages: unknown[] = []
  const binding = {
    async send(message: unknown) {
      messages.push(message)
      return { messageId: 'local-only' }
    },
  }
  assert.equal(
    platformEmailReady(binding, '[email protected]'),
    true,
  )
  assert.equal(
    platformEmailReady(undefined, '[email protected]'),
    false,
  )
  assert.equal(
    platformEmailReady(binding, '[email protected]\r\nBcc: [email protected]'),
    false,
  )
  await createCloudflareEmailSender(
    binding,
    '[email protected]',
  ).send({ email: '[email protected]', code: '123456', expiresInMinutes: 10 })
  assert.deepEqual(messages, [
    {
      from: '[email protected]',
      to: '[email protected]',
      subject: 'Your ChronoFrame sign-in code',
      text: 'Your ChronoFrame sign-in code is 123456. It expires in 10 minutes. If you did not request this code, you can ignore this email.',
    },
  ])
  await assert.rejects(
    createCloudflareEmailSender(
      {
        async send() {
          throw new Error('provider unavailable')
        },
      },
      '[email protected]',
    ).send({ email: '[email protected]', code: '123456', expiresInMinutes: 10 }),
  )
})