@codepunter-labs/mock-zeptomail
v0.2.0
Published
Mock SDK for Zoho ZeptoMail API
Maintainers
Readme
@codepunter-labs/mock-zeptomail
Mock SDK for Zoho ZeptoMail API. Provides fully-typed mock implementations for testing transactional email sending, templates, domains, and email logs without making real API calls.
Installation
npm install @codepunter-labs/mock-zeptomailFeatures
- Email Sending: Send single and batch transactional emails
- Templates: Create, update, list, and delete email templates
- Domains: Manage sending domains with verification
- Email Logs: Track email delivery status and logs
- 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-zeptomail
- Source Code: src/
- Tests: tests/
Usage
Basic Setup
import { vi } from 'vitest';
import { createMockZeptoMail } from '@codepunter-labs/mock-zeptomail';
const zeptoMail = createMockZeptoMail({ spy: vi.fn });Using with Jest
import { createMockZeptoMail } from '@codepunter-labs/mock-zeptomail';
const zeptoMail = createMockZeptoMail({ spy: jest.fn });Example: Send Email
// Default behavior - returns realistic mock data
const result = await zeptoMail.sendEmail({
from: { address: '[email protected]', name: 'Sender' },
to: [{ address: '[email protected]', name: 'Recipient' }],
subject: 'Test Email',
html: '<p>Hello World</p>'
});Example: Send Batch Email
const result = await zeptoMail.sendBatchEmail({
from: { address: '[email protected]' },
to: [
[{ address: '[email protected]' }],
[{ address: '[email protected]' }]
],
subject: 'Batch Email',
text: 'Hello World'
});Example: Create Template
const result = await zeptoMail.createTemplate({
templateName: 'Welcome Email',
subject: 'Welcome',
htmlContent: '<h1>Welcome {{name}}</h1>'
});Example: Override Mock Response
import { makeSendEmailResponse } from '@codepunter-labs/mock-zeptomail';
zeptoMail.sendEmail.mockResolvedValue({
message: 'Email sent successfully',
data: makeSendEmailResponse({ messageId: 'custom_msg_123' })
});Example: Error Simulation
import { MockErrors } from '@codepunter-labs/mock-core';
zeptoMail.sendEmail.mockRejectedValue(
MockErrors.badRequest('Invalid email address')
);API Reference
MockZeptoMail
sendEmail(request)- Send single emailsendBatchEmail(request)- Send batch emailcreateTemplate(request)- Create email templateupdateTemplate(request)- Update email templategetTemplate(templateId)- Get template detailslistTemplates()- List all templatesdeleteTemplate(templateId)- Delete templatecreateDomain(request)- Create domainupdateDomain(request)- Update domaingetDomain(domainId)- Get domain detailslistDomains()- List all domainsverifyDomain(domainId)- Verify domaindeleteDomain(domainId)- Delete domaingetEmailLogs(options?)- Get email logsgetEmailLog(messageId)- Get specific email log
Fixture Factories
makeEmailAddress(address, name?)- Create email addressmakeSendEmailResponse(options?)- Create send email responsemakeBatchEmailResponse(options?)- Create batch email responsemakeTemplate(options?)- Create templatemakeDomain(options?)- Create domainmakeEmailLog(options?)- Create email log
Testing Patterns
Test Success Path
test('should send email successfully', async () => {
const zeptoMail = createMockZeptoMail({ spy: vi.fn });
const result = await zeptoMail.sendEmail(request);
expect(result.message).toBe('Email sent successfully');
expect(result.data.messageId).toBeDefined();
});Test Error Handling
test('should handle invalid email address error', async () => {
const zeptoMail = createMockZeptoMail({ spy: vi.fn });
zeptoMail.sendEmail.mockRejectedValue(
ZeptoMailErrors.invalidEmail()
);
await expect(zeptoMail.sendEmail(request)).rejects.toMatchObject({ message: /Invalid email/ });
});Test with Custom Data
test('should use custom message ID', async () => {
const zeptoMail = createMockZeptoMail({ spy: vi.fn });
zeptoMail.sendEmail.mockResolvedValue({
message: 'Email sent successfully',
data: makeSendEmailResponse({ messageId: 'custom_msg_123' })
});
const result = await zeptoMail.sendEmail(request);
expect(result.data.messageId).toBe('custom_msg_123');
});License
MIT zeptoMail.sendEmail.mockResolvedValue({ message: 'Email sent successfully', data: makeSendEmailResponse({ messageId: 'custom_msg_123' }) });
const result = await zeptoMail.sendEmail(request); expect(result.data.messageId).toBe('custom_msg_123'); });
## License
MIT