74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
// Test setup file
|
|
|
|
// Mock environment variables for testing
|
|
process.env.RESEND_API_KEY = 'test-api-key';
|
|
process.env.FROM_DOMAIN = 'test.com';
|
|
process.env.NODE_ENV = 'test';
|
|
process.env.LOG_LEVEL = 'error'; // Reduce log noise in tests
|
|
|
|
// Mock console methods to reduce test output noise
|
|
const originalConsole = { ...console };
|
|
|
|
beforeAll(() => {
|
|
console.log = jest.fn();
|
|
console.info = jest.fn();
|
|
console.warn = jest.fn();
|
|
console.error = jest.fn();
|
|
console.debug = jest.fn();
|
|
});
|
|
|
|
afterAll(() => {
|
|
Object.assign(console, originalConsole);
|
|
});
|
|
|
|
// Mock Resend API
|
|
jest.mock('resend', () => ({
|
|
Resend: jest.fn().mockImplementation(() => ({
|
|
emails: {
|
|
send: jest.fn().mockResolvedValue({
|
|
data: { id: 'test-message-id' },
|
|
error: null
|
|
})
|
|
}
|
|
}))
|
|
}));
|
|
|
|
// Mock React DOM Server for template rendering
|
|
jest.mock('react-dom/server', () => ({
|
|
renderToStaticMarkup: jest.fn().mockReturnValue('<html><body>Test Email</body></html>')
|
|
}));
|
|
|
|
// Custom matchers
|
|
expect.extend({
|
|
toBeValidEmail(received: string) {
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
const pass = emailRegex.test(received);
|
|
|
|
if (pass) {
|
|
return {
|
|
message: () => `expected ${received} not to be a valid email`,
|
|
pass: true,
|
|
};
|
|
} else {
|
|
return {
|
|
message: () => `expected ${received} to be a valid email`,
|
|
pass: false,
|
|
};
|
|
}
|
|
},
|
|
|
|
toBeValidUrl(received: string) {
|
|
try {
|
|
new URL(received);
|
|
return {
|
|
message: () => `expected ${received} not to be a valid URL`,
|
|
pass: true,
|
|
};
|
|
} catch {
|
|
return {
|
|
message: () => `expected ${received} to be a valid URL`,
|
|
pass: false,
|
|
};
|
|
}
|
|
},
|
|
}); |