npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codepunter-labs/mock-brevo

v0.2.0

Published

Mock SDK for Brevo API

Readme

@codepunter-labs/mock-brevo

Mock SDK for Brevo API (formerly Sendinblue). Provides fully-typed mock implementations for testing transactional email sending, templates, contacts, and webhooks without making real API calls.

npm version GitHub

Installation

npm install @codepunter-labs/mock-brevo

Features

  • Email Sending: Send transactional emails with HTML, text, or templates
  • Templates: Create, update, list, and delete email templates
  • Contacts: Manage contacts with attributes and lists
  • Webhooks: Create and manage webhooks for email events
  • Type-safe: Full TypeScript support with accurate API types
  • Test Framework Agnostic: Works with Jest, Vitest, and other spy-based frameworks

Repository

  • GitHub: https://github.com/DERRICK-TORKORNOO/mock-sdks/tree/main/packages/mock-brevo
  • Source Code: src/
  • Tests: tests/

Usage

Basic Setup

import { vi } from 'vitest';
import { createMockBrevo } from '@codepunter-labs/mock-brevo';

const brevo = createMockBrevo({ spy: vi.fn });

Using with Jest

import { createMockBrevo } from '@codepunter-labs/mock-brevo';

const brevo = createMockBrevo({ spy: jest.fn });

Example: Send Email

// Default behavior - returns realistic mock data
const result = await brevo.sendEmail({
  sender: { email: '[email protected]', name: 'Sender' },
  to: [{ email: '[email protected]', name: 'Recipient' }],
  subject: 'Test Email',
  htmlContent: '<p>Hello World</p>'
});

Example: Send Email with Template

const result = await brevo.sendEmail({
  sender: { email: '[email protected]' },
  to: [{ email: '[email protected]' }],
  templateId: 1,
  params: { name: 'John', order: 12345 }
});

Example: Create Template

const result = await brevo.createTemplate({
  name: 'Welcome Email',
  subject: 'Welcome',
  htmlContent: '<h1>Welcome {{name}}</h1>'
});

Example: Create Contact

const result = await brevo.createContact({
  email: '[email protected]',
  attributes: { FIRSTNAME: 'John', LASTNAME: 'Doe' },
  listIds: [1]
});

Example: Override Mock Response

import { makeSendEmailResponse } from '@codepunter-labs/mock-brevo';

brevo.sendEmail.mockResolvedValue({
  code: 200,
  message: 'success',
  data: makeSendEmailResponse({ messageId: '<[email protected]>' })
});

Example: Error Simulation

import { MockErrors } from '@codepunter-labs/mock-core';

brevo.sendEmail.mockRejectedValue(
  MockErrors.badRequest('Invalid email address')
);

API Reference

MockBrevo

  • sendEmail(request) - Send transactional email
  • createTemplate(request) - Create email template
  • updateTemplate(request) - Update email template
  • getTemplate(templateId) - Get template details
  • listTemplates() - List all templates
  • deleteTemplate(templateId) - Delete template
  • createContact(request) - Create contact
  • updateContact(request) - Update contact
  • getContact(email) - Get contact details
  • listContacts() - List all contacts
  • deleteContact(email) - Delete contact
  • createWebhook(request) - Create webhook
  • updateWebhook(request) - Update webhook
  • getWebhook(id) - Get webhook details
  • listWebhooks() - List all webhooks
  • deleteWebhook(id) - Delete webhook

Fixture Factories

  • makeEmailAddress(email, name?) - Create email address
  • makeSendEmailResponse(options?) - Create send email response
  • makeTemplate(options?) - Create template
  • makeContact(options?) - Create contact
  • makeWebhook(options?) - Create webhook

Testing Patterns

Test Success Path

test('should send email successfully', async () => {
  const brevo = createMockBrevo({ spy: vi.fn });
  
  const result = await brevo.sendEmail(request);
  
  expect(result.code).toBe(200);
  expect(result.data.messageId).toBeDefined();
});

Test Error Handling

test('should handle invalid email address error', async () => {
  const brevo = createMockBrevo({ spy: vi.fn });
  
  brevo.sendEmail.mockRejectedValue(
    BrevoErrors.invalidEmail()
  );
  
  await expect(brevo.sendEmail(request)).rejects.toMatchObject({ message: /Invalid email/ });
});

Test with Custom Data

test('should use custom message ID', async () => {
  const brevo = createMockBrevo({ spy: vi.fn });
  
  brevo.sendEmail.mockResolvedValue({
    code: 200,
    message: 'success',
    data: makeSendEmailResponse({ messageId: '<[email protected]>' })
  });
  
  const result = await brevo.sendEmail(request);
  expect(result.data.messageId).toBe('<[email protected]>');
});

License

MIT