"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const crypto_js_1 = require("./crypto.js");
(0, vitest_1.describe)('crypto', () => {
    const masterKey = 'test-master-key-for-unit-tests';
    (0, vitest_1.describe)('encrypt / decrypt round-trip', () => {
        (0, vitest_1.it)('should encrypt and decrypt a simple string', () => {
            const plaintext = 'hello-world-token';
            const encrypted = (0, crypto_js_1.encrypt)(plaintext, masterKey);
            const decrypted = (0, crypto_js_1.decrypt)(encrypted, masterKey);
            (0, vitest_1.expect)(decrypted).toBe(plaintext);
        });
        (0, vitest_1.it)('should produce different ciphertext for the same input (random IV)', () => {
            const plaintext = 'same-input';
            const a = (0, crypto_js_1.encrypt)(plaintext, masterKey);
            const b = (0, crypto_js_1.encrypt)(plaintext, masterKey);
            (0, vitest_1.expect)(a).not.toBe(b);
        });
        (0, vitest_1.it)('should handle empty string', () => {
            const encrypted = (0, crypto_js_1.encrypt)('', masterKey);
            (0, vitest_1.expect)((0, crypto_js_1.decrypt)(encrypted, masterKey)).toBe('');
        });
        (0, vitest_1.it)('should handle unicode content', () => {
            const plaintext = 'Türkçe içerik 🎉 日本語';
            const encrypted = (0, crypto_js_1.encrypt)(plaintext, masterKey);
            (0, vitest_1.expect)((0, crypto_js_1.decrypt)(encrypted, masterKey)).toBe(plaintext);
        });
    });
    (0, vitest_1.describe)('decrypt error handling', () => {
        (0, vitest_1.it)('should throw on invalid format', () => {
            (0, vitest_1.expect)(() => (0, crypto_js_1.decrypt)('not-valid', masterKey)).toThrow('Invalid encrypted data format');
        });
        (0, vitest_1.it)('should throw on wrong master key', () => {
            const encrypted = (0, crypto_js_1.encrypt)('secret', masterKey);
            (0, vitest_1.expect)(() => (0, crypto_js_1.decrypt)(encrypted, 'wrong-key')).toThrow();
        });
        (0, vitest_1.it)('should throw on tampered ciphertext', () => {
            const encrypted = (0, crypto_js_1.encrypt)('secret', masterKey);
            const parts = encrypted.split(':');
            parts[2] = 'AAAA' + parts[2].slice(4); // tamper with encrypted data
            (0, vitest_1.expect)(() => (0, crypto_js_1.decrypt)(parts.join(':'), masterKey)).toThrow();
        });
    });
    (0, vitest_1.describe)('generateEncryptionKey', () => {
        (0, vitest_1.it)('should return a 64-char hex string (32 bytes)', () => {
            const key = (0, crypto_js_1.generateEncryptionKey)();
            (0, vitest_1.expect)(key).toHaveLength(64);
            (0, vitest_1.expect)(/^[0-9a-f]{64}$/.test(key)).toBe(true);
        });
        (0, vitest_1.it)('should produce unique keys', () => {
            const a = (0, crypto_js_1.generateEncryptionKey)();
            const b = (0, crypto_js_1.generateEncryptionKey)();
            (0, vitest_1.expect)(a).not.toBe(b);
        });
    });
});
//# sourceMappingURL=crypto.test.js.map