"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nock_1 = __importDefault(require("nock"));
const actions_core_1 = require("@segment/actions-core");
const index_1 = __importDefault(require("./index"));
const utils_1 = require("./utils");
const testDestination = (0, actions_core_1.createTestIntegration)(index_1.default);
describe('Iterable', () => {
    describe('testAuthentication', () => {
        it('should authenticate with Iterable API key', async () => {
            (0, nock_1.default)('https://api.iterable.com').get('/api/webhooks').reply(200, {});
            const settings = {
                apiKey: 'iterableApiKey',
                dataCenterLocation: 'united_states'
            };
            await expect(testDestination.testAuthentication(settings)).resolves.not.toThrowError();
        });
        it('should throw error on invalid Iterable API key', async () => {
            (0, nock_1.default)('https://api.iterable.com').get('/api/webhooks').reply(401, { msg: 'Invalid API key' });
            const settings = {
                apiKey: 'badApiKey',
                dataCenterLocation: 'united_states'
            };
            await expect(testDestination.testAuthentication(settings)).rejects.toThrowError('Credentials are invalid: 401 Unauthorized');
        });
    });
});
describe('getRegionalEndpoint', () => {
    test('should return the correct endpoint for a specific action and region', () => {
        const action = 'updateUser';
        const dataCenterLocation = 'europe';
        const expectedEndpoint = 'https://api.eu.iterable.com/api/users/update';
        const endpoint = (0, utils_1.getRegionalEndpoint)(action, dataCenterLocation);
        expect(endpoint).toBe(expectedEndpoint);
    });
    test('should use the default dataCenterLocation if no dataCenterLocation is provided', () => {
        const action = 'updateCart';
        const expectedEndpoint = 'https://api.iterable.com/api/commerce/updateCart';
        const endpoint = (0, utils_1.getRegionalEndpoint)(action);
        expect(endpoint).toBe(expectedEndpoint);
    });
});
//# sourceMappingURL=index.test.js.map