"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,
    userId: 'eric-15',
    type: 'identify',
    traits: {
        contactKey: 'ericForman15'
    }
});
const requestUrl = `https://${settings.subdomain}.rest.marketingcloudapis.com/contacts/v1/contacts`;
describe('Salesforce Marketing Cloud', () => {
    describe('Create Contact Action', () => {
        it('Create a Contact', async () => {
            (0, nock_1.default)(requestUrl).post('').reply(200, {});
            const responses = await testDestination.testAction('contact', {
                event,
                settings,
                mapping: {
                    contactKey: { '@path': '$.traits.contactKey' }
                }
            });
            expect(responses[0].status).toBe(200);
            expect(responses[0].options.body).toMatchInlineSnapshot(`"{\\"contactKey\\":\\"ericForman15\\",\\"attributeSets\\":[]}"`);
        });
        it('Create a Contact with Default', async () => {
            (0, nock_1.default)(requestUrl).post('').reply(200, {});
            const responses = await testDestination.testAction('contact', {
                event,
                settings,
                useDefaultMappings: true
            });
            expect(responses[0].status).toBe(200);
            expect(responses[0].options.body).toMatchInlineSnapshot(`"{\\"contactKey\\":\\"eric-15\\",\\"attributeSets\\":[]}"`);
        });
        it('Fail to create contact due to missing required field -> contactKey', async () => {
            (0, nock_1.default)(requestUrl).post('').reply(400, {});
            await expect(testDestination.testAction('contact', {
                event,
                settings
            })).rejects.toThrowError(`The root value is missing the required field 'contactKey'.`);
        });
    });
});
//# sourceMappingURL=contact.test.js.map