"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.userAgent = exports.testBatchAction = exports.testAction = exports.settings = void 0;
const actions_core_1 = require("@segment/actions-core");
const nock_1 = __importDefault(require("nock"));
const api_1 = require("./api");
const index_1 = __importDefault(require("./index"));
const testDestination = (0, actions_core_1.createTestIntegration)(index_1.default);
exports.settings = { apiKey: 'TEST_API_KEY', environment: 'helium' };
const testAction = async (actionName, event) => {
    (0, nock_1.default)((0, api_1.submitEventUrl)(exports.settings.environment, eventType(event)))
        .post('')
        .reply(200, {});
    const input = { event, settings: exports.settings, useDefaultMappings: true };
    const responses = await testDestination.testAction(actionName, input);
    expect(responses.length).toBe(1);
    const request = responses[0].request;
    expect(request.headers.get('Authorization')).toBe(`Bearer ${exports.settings.apiKey}`);
    const rawBody = await request.text();
    return JSON.parse(rawBody);
};
exports.testAction = testAction;
const testBatchAction = async (actionName, events) => {
    (0, nock_1.default)((0, api_1.submitEventBatchUrl)(exports.settings.environment, eventType(events[0])))
        .post('')
        .reply(200, {});
    const input = { events, settings: exports.settings, useDefaultMappings: true };
    const responses = await testDestination.testBatchAction(actionName, input);
    expect(responses.length).toBe(1);
    const request = responses[0].request;
    expect(request.headers.get('Authorization')).toBe(`Bearer ${exports.settings.apiKey}`);
    const rawBody = await request.text();
    return JSON.parse(rawBody);
};
exports.testBatchAction = testBatchAction;
exports.userAgent = '"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1';
const eventType = (event) => {
    if (event.type == 'track' || event.type == 'identify' || event.type == 'screen' || event.type == 'page')
        return event.type;
    throw new Error(`Not supported event type for tests: ${event.type}`);
};
//# sourceMappingURL=testing.js.map