import { describe, it, expect } from 'vitest';
import jwt from 'jsonwebtoken';
import { generateUnsubscribeToken, generateUnsubscribeUrl, injectUnsubscribeFooter, getUnsubscribeHeaders, } from '../email-utils.js';
const SECRET = 'a'.repeat(32);
const SERVER_URL = 'https://app.example.com';
describe('email-utils', () => {
    it('should generate a valid JWT unsubscribe token', () => {
        const token = generateUnsubscribeToken('user@test.com', SECRET);
        const decoded = jwt.verify(token, SECRET);
        expect(decoded.email).toBe('user@test.com');
        expect(decoded.action).toBe('unsubscribe');
    });
    it('should generate unsubscribe URL', () => {
        const url = generateUnsubscribeUrl('user@test.com', SECRET, SERVER_URL);
        expect(url).toContain('/api/email/unsubscribe/');
        expect(url.startsWith(SERVER_URL)).toBe(true);
    });
    it('should inject unsubscribe footer into HTML', () => {
        const html = '<html><body><p>Hello</p></body></html>';
        const result = injectUnsubscribeFooter(html, 'https://example.com/unsub');
        expect(result).toContain('https://example.com/unsub');
        expect(result).toContain('unsubscribe');
        expect(result).toContain('</body>');
    });
    it('should inject footer even without body tag', () => {
        const html = '<p>Hello</p>';
        const result = injectUnsubscribeFooter(html, 'https://example.com/unsub');
        expect(result).toContain('https://example.com/unsub');
    });
    it('should return List-Unsubscribe headers', () => {
        const headers = getUnsubscribeHeaders('https://example.com/unsub');
        expect(headers['List-Unsubscribe']).toContain('https://example.com/unsub');
        expect(headers['List-Unsubscribe-Post']).toBe('List-Unsubscribe=One-Click');
    });
});
//# sourceMappingURL=email-utils.test.js.map