forked from Divineifed1/StrellerMinds-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailService.test.js
More file actions
23 lines (18 loc) · 774 Bytes
/
emailService.test.js
File metadata and controls
23 lines (18 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { sendEmail, trackEmailAnalytics } = require('./emailService');
// Mock SendGrid's library
jest.mock('@sendgrid/mail', () => ({
setApiKey: jest.fn(),
send: jest.fn(() => [{ statusCode: 202 }]),
}));
// Test cases
describe('Email Service Integration', () => {
it('should send an email successfully', async () => {
const response = await sendEmail('test@example.com', 'Test Subject', 'Test text', '<p>Test HTML</p>');
expect(response[0].statusCode).toBe(202);
});
it('should track email analytics successfully', () => {
const consoleSpy = jest.spyOn(console, 'log');
trackEmailAnalytics({ event: 'delivered' });
expect(consoleSpy).toHaveBeenCalledWith('Email event:', { event: 'delivered' });
});
});