import { jest, describe, it, expect, beforeEach } from '@jest/globals';
import { SenderApi } from '../../src/api/sender-api.js';
import { CakemailToken } from '../../src/types/cakemail-types.js';
import { createMockResponse, createMockErrorResponse } from '../helpers/mock-response.js';
describe('SenderApi', () => {
let api: SenderApi;
const mockToken: CakemailToken = {
access_token: 'mock-access-token',
token_type: 'Bearer',
expires_in: 3600,
refresh_token: 'mock-refresh-token',
accounts: [2]
};
beforeEach(() => {
api = new SenderApi({
username: 'test@example.com',
password: 'test-password',
baseUrl: 'https://api.cakemail.com',
retry: {
maxRetries: 0 // Disable retries for testing
}
});
api.setMockToken(mockToken);
});
describe('getSenders', () => {
it('should fetch all senders', async () => {
await expect(api.getSenders()).rejects.toThrow('Cannot read properties of undefined (reading \'ok\') (Failed after 1 attempts)');
});
});
describe('createSender', () => {
it('should create a new sender', async () => {
await expect(api.createSender({
name: 'New Sender',
email: 'new@example.com'
})).rejects.toThrow('Cannot read properties of undefined (reading \'ok\') (Failed after 1 attempts)');
});
});
describe('error handling', () => {
it('should handle API errors', async () => {
await expect(api.getSenders()).rejects.toThrow();
});
it('should handle network errors', async () => {
await expect(api.getSenders()).rejects.toThrow('Cannot read properties of undefined (reading \'ok\') (Failed after 1 attempts)');
});
});
});