"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const projects_1 = require("../types/projects");
const connectionChanges_1 = require("./connectionChanges");
describe('hasConnectionChanges', () => {
    it('should return false when both configs are identical', () => {
        const warehouse = {
            type: projects_1.WarehouseTypes.POSTGRES,
            host: 'localhost',
            port: 5432,
            user: 'admin',
            password: 'secret',
            dbname: 'mydb',
            schema: 'public',
        };
        const dbt = {
            type: projects_1.DbtProjectType.GITHUB,
            repository: 'org/repo',
            branch: 'main',
            project_sub_path: '/',
            host_domain: 'github.com',
            authorization_method: 'personal_access_token',
            personal_access_token: 'ghp_xxx',
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ warehouseConnection: warehouse, dbtConnection: dbt }, { warehouseConnection: warehouse, dbtConnection: dbt })).toBe(false);
    });
    it('should return true when warehouse connection changes', () => {
        const before = {
            type: projects_1.WarehouseTypes.POSTGRES,
            host: 'localhost',
            port: 5432,
            user: 'admin',
            password: 'secret',
            dbname: 'mydb',
            schema: 'public',
        };
        const after = {
            ...before,
            host: 'production.db.com',
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ warehouseConnection: before }, { warehouseConnection: after })).toBe(true);
    });
    it('should return true when dbt connection changes', () => {
        const before = {
            type: projects_1.DbtProjectType.GITHUB,
            repository: 'org/repo',
            branch: 'main',
            project_sub_path: '/',
            host_domain: 'github.com',
            authorization_method: 'personal_access_token',
            personal_access_token: 'ghp_xxx',
        };
        const after = {
            ...before,
            branch: 'develop',
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ dbtConnection: before }, { dbtConnection: after })).toBe(true);
    });
    it('should return false when both connections are undefined', () => {
        expect((0, connectionChanges_1.hasConnectionChanges)({}, {})).toBe(false);
    });
    it('should return true when warehouse connection is removed', () => {
        const warehouse = {
            type: projects_1.WarehouseTypes.POSTGRES,
            host: 'localhost',
            port: 5432,
            user: 'admin',
            password: 'secret',
            dbname: 'mydb',
            schema: 'public',
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ warehouseConnection: warehouse }, {})).toBe(true);
    });
    it('should return true when warehouse connection is added', () => {
        const warehouse = {
            type: projects_1.WarehouseTypes.POSTGRES,
            host: 'localhost',
            port: 5432,
            user: 'admin',
            password: 'secret',
            dbname: 'mydb',
            schema: 'public',
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({}, { warehouseConnection: warehouse })).toBe(true);
    });
    it('should return true when dbt connection is removed', () => {
        const dbt = {
            type: projects_1.DbtProjectType.GITHUB,
            repository: 'org/repo',
            branch: 'main',
            project_sub_path: '/',
            host_domain: 'github.com',
            authorization_method: 'personal_access_token',
            personal_access_token: 'ghp_xxx',
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ dbtConnection: dbt }, {})).toBe(true);
    });
    it('should return true when warehouse type changes', () => {
        const before = {
            type: projects_1.WarehouseTypes.POSTGRES,
            host: 'localhost',
            port: 5432,
            user: 'admin',
            password: 'secret',
            dbname: 'mydb',
            schema: 'public',
        };
        const after = {
            type: projects_1.WarehouseTypes.BIGQUERY,
            project: 'my-project',
            dataset: 'my_dataset',
            keyfileContents: {},
            timeoutSeconds: 300,
            priority: 'interactive',
            retries: 3,
            location: 'US',
            maximumBytesBilled: 1000000,
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ warehouseConnection: before }, { warehouseConnection: after })).toBe(true);
    });
    it('should return false when nested objects have same values but different key order', () => {
        const before = {
            type: projects_1.WarehouseTypes.BIGQUERY,
            project: 'my-project',
            dataset: 'my_dataset',
            keyfileContents: { project_id: 'abc', client_email: 'x@y.com' },
            timeoutSeconds: 300,
            priority: 'interactive',
            retries: 3,
            location: 'US',
            maximumBytesBilled: 1000000,
        };
        const after = {
            type: projects_1.WarehouseTypes.BIGQUERY,
            project: 'my-project',
            dataset: 'my_dataset',
            keyfileContents: { client_email: 'x@y.com', project_id: 'abc' },
            timeoutSeconds: 300,
            priority: 'interactive',
            retries: 3,
            location: 'US',
            maximumBytesBilled: 1000000,
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ warehouseConnection: before }, { warehouseConnection: after })).toBe(false);
    });
    it('should detect changes when key order differs but values are same', () => {
        const before = {
            type: projects_1.WarehouseTypes.POSTGRES,
            host: 'localhost',
            port: 5432,
            user: 'admin',
            password: 'secret',
            dbname: 'mydb',
            schema: 'public',
        };
        const after = {
            schema: 'public',
            dbname: 'mydb',
            password: 'secret',
            user: 'admin',
            port: 5432,
            host: 'localhost',
            type: projects_1.WarehouseTypes.POSTGRES,
        };
        expect((0, connectionChanges_1.hasConnectionChanges)({ warehouseConnection: before }, { warehouseConnection: after })).toBe(false);
    });
});
//# sourceMappingURL=connectionChanges.test.js.map