"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 testDestination = (0, actions_core_1.createTestIntegration)(index_1.default);
const timestamp = '2022-05-12T15:21:15.449Z';
const settings = {
    subdomain: 'test123',
    client_id: 'test123',
    client_secret: 'test123',
    account_id: 'test123'
};
const event = (0, actions_core_1.createTestEvent)({
    timestamp: timestamp,
    type: 'track',
    userId: 'harry-1',
    properties: {
        id: '1234567890',
        keys: {
            id: 'HS1'
        },
        values: {
            name: 'Harry Styles'
        }
    }
});
const requestUrl = `https://${settings.subdomain}.rest.marketingcloudapis.com/hub/v1/dataevents/1234567890/rowset`;
describe('Salesforce Marketing Cloud', () => {
    describe('Data Extension Action', () => {
        it('Add Event to Data Extension', async () => {
            (0, nock_1.default)(requestUrl).post('').reply(200, {});
            const responses = await testDestination.testAction('dataExtension', {
                event,
                settings,
                mapping: {
                    id: { '@path': '$.properties.id' },
                    keys: { '@path': '$.properties.keys' },
                    values: { '@path': '$.properties.values' }
                }
            });
            expect(responses[0].status).toBe(200);
            expect(responses[0].options.body).toMatchInlineSnapshot(`"[{\\"keys\\":{\\"id\\":\\"HS1\\"},\\"values\\":{\\"name\\":\\"Harry Styles\\"}}]"`);
        });
        it('Fail to add event to data extension due to missing key and id', async () => {
            (0, nock_1.default)(requestUrl).post('').reply(400, {});
            await expect(testDestination.testAction('dataExtension', {
                event,
                settings,
                mapping: {
                    keys: { '@path': '$.properties.keys' },
                    values: { '@path': '$.properties.values' }
                }
            })).rejects.toThrowError(`In order to send an event to a data extension either Data Extension ID or Data Extension Key must be defined.`);
        });
    });
});
//# sourceMappingURL=dataExtension.test.js.map