"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const auth_js_1 = require("./auth.js");
const index_js_1 = require("./index.js");
(0, vitest_1.describe)('isAuthenticatedDatasourceConfig', () => {
    (0, vitest_1.test)('returns true for config with authConfig and authType', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authType: auth_js_1.IntegrationAuthType.OAUTH2_CODE
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns false for config with authConfig and authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: 'fields' // This field must exist for the test to pass
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config without authConfig', () => {
        const config = {
            name: 'test',
            authType: auth_js_1.IntegrationAuthType.OAUTH2_CODE
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig but no authType or authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            }
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authType but no authConfig', () => {
        const config = {
            name: 'test',
            authType: auth_js_1.IntegrationAuthType.OAUTH2_CODE
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authTypeField but no authConfig', () => {
        const config = {
            name: 'test',
            authTypeField: 'connectionType'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for empty config', () => {
        const config = {
            name: 'test'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns true for config with authConfig and both authType and authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authType: auth_js_1.IntegrationAuthType.OAUTH2_CODE,
            authTypeField: 'connectionType',
            connectionType: 'fields' // This field must exist for the test to pass
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns false for config with authConfig but empty authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: ''
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig but undefined authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: undefined
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig but authTypeField pointing to non-existent field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'nonExistentField'
            // nonExistentField is not defined in the config
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig but undefined authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: undefined
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig and authTypeField pointing to undefined field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType'
            // connectionType is not defined, so it's undefined
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig and authTypeField pointing to undefined field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: undefined
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfig)(config)).toBe(false);
    });
});
(0, vitest_1.describe)('isAuthenticatedDatasourceConfigWithDynamicAuthType', () => {
    (0, vitest_1.test)('returns true for config with authConfig and valid authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: 'oauth2'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns true for config with authConfig and authTypeField pointing to non-empty string', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'authMethod',
            authMethod: 'api_key'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns false for config without authConfig', () => {
        const config = {
            name: 'test',
            authTypeField: 'connectionType',
            connectionType: 'oauth2'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig but no authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            }
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig and empty authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: '',
            connectionType: 'oauth2'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig and undefined authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: undefined,
            connectionType: 'oauth2'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig and authTypeField pointing to undefined field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType'
            // connectionType is not defined
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig and authTypeField pointing to null field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: null
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig and authTypeField pointing to empty string', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: ''
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns true for config with authConfig and authTypeField pointing to zero', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: 0
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns true for config with authConfig and authTypeField pointing to false', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: false
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns true for config with authConfig and authTypeField pointing to object', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: { type: 'oauth2' }
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns true for config with authConfig and authTypeField pointing to array', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: ['oauth2', 'api_key']
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns false for empty config', () => {
        const config = {
            name: 'test'
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns false for config with authConfig but authTypeField pointing to non-existent field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'nonExistentField'
            // nonExistentField is not defined in the config
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(false);
    });
    (0, vitest_1.test)('returns true for config with authConfig and authTypeField pointing to numeric value', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: 42
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
    (0, vitest_1.test)('returns true for config with authConfig and authTypeField pointing to boolean true', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: true
        };
        (0, vitest_1.expect)((0, index_js_1.isAuthenticatedDatasourceConfigWithDynamicAuthType)(config)).toBe(true);
    });
});
(0, vitest_1.describe)('getAuthTypeFromConfig', () => {
    (0, vitest_1.test)('returns authType for config with direct authType field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authType: auth_js_1.IntegrationAuthType.OAUTH2_CODE
        };
        (0, vitest_1.expect)((0, index_js_1.getAuthTypeFromConfig)(config)).toBe(auth_js_1.IntegrationAuthType.OAUTH2_CODE);
    });
    (0, vitest_1.test)('returns authType for config with authTypeField pointing to valid field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: 'fields'
        };
        (0, vitest_1.expect)((0, index_js_1.getAuthTypeFromConfig)(config)).toBe('fields');
    });
    (0, vitest_1.test)('returns undefined for non-authenticated config', () => {
        const config = {
            name: 'test'
        };
        (0, vitest_1.expect)((0, index_js_1.getAuthTypeFromConfig)(config)).toBe(undefined);
    });
    (0, vitest_1.test)('returns undefined for config with authConfig but no authType or authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            }
        };
        (0, vitest_1.expect)((0, index_js_1.getAuthTypeFromConfig)(config)).toBe(undefined);
    });
    (0, vitest_1.test)('returns undefined for config with authTypeField pointing to undefined field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType'
            // connectionType is not defined
        };
        (0, vitest_1.expect)((0, index_js_1.getAuthTypeFromConfig)(config)).toBe(undefined);
    });
    (0, vitest_1.test)('returns undefined for config with authTypeField pointing to undefined field', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authTypeField: 'connectionType',
            connectionType: undefined
        };
        (0, vitest_1.expect)((0, index_js_1.getAuthTypeFromConfig)(config)).toBe(undefined);
    });
    (0, vitest_1.test)('prioritizes direct authType over authTypeField', () => {
        const config = {
            name: 'test',
            authConfig: {
                clientId: 'test-client',
                clientSecret: 'test-secret'
            },
            authType: auth_js_1.IntegrationAuthType.OAUTH2_CODE,
            authTypeField: 'connectionType',
            connectionType: 'fields'
        };
        (0, vitest_1.expect)((0, index_js_1.getAuthTypeFromConfig)(config)).toBe(auth_js_1.IntegrationAuthType.OAUTH2_CODE);
    });
});
//# sourceMappingURL=index.test.js.map