"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createBatchTestEvents = void 0;
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 event = (0, actions_core_1.createTestEvent)({
    event: 'Audience Entered',
    type: 'track',
    properties: {
        audience_key: 'personas_test_audience'
    },
    context: {
        device: {
            advertisingId: '123'
        },
        traits: {
            email: 'testing@testing.com',
            phoneNumbers: '+1234567890',
            zipCodes: '12345',
            firstName: 'John',
            lastName: 'Doe',
            countryCode: 'US'
        }
    }
});
describe('First-Party-dv360.addToAudContactInfo', () => {
    it('should hash pii data if not already hashed', async () => {
        (0, nock_1.default)('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences')
            .post('/1234567890:editCustomerMatchMembers')
            .reply(200, { success: true });
        const responses = await testDestination.testAction('addToAudContactInfo', {
            event,
            mapping: {
                emails: ['testing@testing.com'],
                phoneNumbers: ['+1234567890'],
                zipCodes: ['12345'],
                firstName: 'John',
                lastName: 'Doe',
                countryCode: 'US',
                external_id: '1234567890',
                advertiser_id: '1234567890',
                enable_batching: false,
                batch_size: 1
            }
        });
        expect(responses[0].options.body).toMatchInlineSnapshot('"{\\"advertiserId\\":\\"1234567890\\",\\"addedContactInfoList\\":{\\"contactInfos\\":[{\\"hashedEmails\\":\\"584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777\\",\\"hashedPhoneNumbers\\":\\"422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8\\",\\"zipCodes\\":\\"12345\\",\\"hashedFirstName\\":\\"96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a\\",\\"hashedLastName\\":\\"799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f\\",\\"countryCode\\":\\"US\\"}],\\"consent\\":{\\"adUserData\\":\\"CONSENT_STATUS_GRANTED\\",\\"adPersonalization\\":\\"CONSENT_STATUS_GRANTED\\"}}}"');
    });
    it('should not hash pii data if already hashed', async () => {
        (0, nock_1.default)('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences')
            .post('/1234567890:editCustomerMatchMembers')
            .reply(200, { success: true });
        const responses = await testDestination.testAction('addToAudContactInfo', {
            event,
            mapping: {
                emails: ['584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777'],
                phoneNumbers: ['422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8'],
                zipCodes: ['12345'],
                firstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a',
                lastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f',
                countryCode: 'US',
                external_id: '1234567890',
                advertiser_id: '1234567890',
                enable_batching: false,
                batch_size: 1
            }
        });
        expect(responses[0].options.body).toMatchInlineSnapshot('"{\\"advertiserId\\":\\"1234567890\\",\\"addedContactInfoList\\":{\\"contactInfos\\":[{\\"hashedEmails\\":\\"584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777\\",\\"hashedPhoneNumbers\\":\\"422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8\\",\\"zipCodes\\":\\"12345\\",\\"hashedFirstName\\":\\"96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a\\",\\"hashedLastName\\":\\"799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f\\",\\"countryCode\\":\\"US\\"}],\\"consent\\":{\\"adUserData\\":\\"CONSENT_STATUS_GRANTED\\",\\"adPersonalization\\":\\"CONSENT_STATUS_GRANTED\\"}}}"');
    });
    it('should batch multiple payloads into a single request when enable_batching is true', async () => {
        (0, nock_1.default)('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences')
            .post('/1234567890:editCustomerMatchMembers')
            .reply(200, { success: true });
        const events = (0, exports.createBatchTestEvents)(createContactList);
        const responses = await testDestination.testBatchAction('addToAudContactInfo', {
            events: events,
            mapping: {
                emails: ['584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777'],
                phoneNumbers: ['422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8'],
                zipCodes: ['12345'],
                firstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a',
                lastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f',
                countryCode: 'US',
                external_id: '1234567890',
                advertiser_id: '1234567890',
                enable_batching: true,
                batch_size: 2
            }
        });
        const requestBody = JSON.parse(String(responses[0].options.body));
        expect(requestBody.addedContactInfoList.contactInfos.length).toBe(2);
        expect(requestBody.addedContactInfoList.contactInfos[0].hashedEmails).toBeDefined();
        expect(requestBody.addedContactInfoList.contactInfos[1].hashedEmails).toBeDefined();
    });
    it('should batch multiple payloads into a single request when enable_batching is true ( CANARY VERSION )', async () => {
        (0, nock_1.default)('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences')
            .post('/1234567890:editCustomerMatchMembers')
            .reply(200, { success: true });
        const events = (0, exports.createBatchTestEvents)(createContactList);
        const responses = await testDestination.testBatchAction('addToAudContactInfo', {
            events: events,
            mapping: {
                emails: ['584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777'],
                phoneNumbers: ['422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8'],
                zipCodes: ['12345'],
                firstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a',
                lastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f',
                countryCode: 'US',
                external_id: '1234567890',
                advertiser_id: '1234567890',
                enable_batching: true,
                batch_size: 2
            },
            features: { 'first-party-dv360-canary-version': true }
        });
        const requestBody = JSON.parse(String(responses[0].options.body));
        expect(requestBody.addedContactInfoList.contactInfos.length).toBe(2);
        expect(requestBody.addedContactInfoList.contactInfos[0].hashedEmails).toBeDefined();
        expect(requestBody.addedContactInfoList.contactInfos[1].hashedEmails).toBeDefined();
    });
});
const createBatchTestEvents = (batchContactList) => batchContactList.map((contact) => (0, actions_core_1.createTestEvent)({
    type: 'identify',
    traits: {
        email: contact.email,
        firstname: contact.firstname,
        lastname: contact.lastname,
        address: {
            city: 'San Francisco',
            country: 'USA',
            postal_code: '600001',
            state: 'California',
            street: 'Vancover st'
        },
        graduation_date: 1664533942262,
        company: 'Some Company',
        phone: '+13134561129',
        website: 'somecompany.com'
    }
}));
exports.createBatchTestEvents = createBatchTestEvents;
const createContactList = [
    {
        email: 'userone@somecompany.com',
        firstname: 'User',
        lastname: 'One'
    },
    {
        email: 'usertwo@somecompany.com',
        firstname: 'User',
        lastname: 'Two'
    }
];
//# sourceMappingURL=index.test.js.map