~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0
main
41 lines · 1.4 KB Raw History
// The Email Service binding adapter: core's EmailPort shape mapped onto
// Cloudflare's send_email binding, which requires a From address of its own.

import { describe, expect, it, vi } from 'vitest';
import { createEmailer } from '../src/index.js';

describe('createEmailer', () => {
  it('sends through the binding with the configured From address', async () => {
    const send = vi.fn(async () => {});
    const emailer = createEmailer({ send }, 'no-reply@example.com');
    await emailer.send({
      to: 'alice@example.com',
      subject: 'Confirm your email',
      text: 'Your code is 123456.',
      html: '<p>Your code is 123456.</p>',
    });
    expect(send).toHaveBeenCalledWith({
      to: 'alice@example.com',
      from: 'no-reply@example.com',
      subject: 'Confirm your email',
      text: 'Your code is 123456.',
      html: '<p>Your code is 123456.</p>',
    });
  });

  it('omits html when core sends none', async () => {
    const send = vi.fn(async () => {});
    const emailer = createEmailer({ send }, 'no-reply@example.com');
    await emailer.send({
      to: 'alice@example.com',
      subject: 'Confirm your email',
      text: 'Your code is 123456.',
    });
    expect(send).toHaveBeenCalledWith({
      to: 'alice@example.com',
      from: 'no-reply@example.com',
      subject: 'Confirm your email',
      text: 'Your code is 123456.',
    });
  });
});