Skip to content

Commit 1e77f8f

Browse files
[del-1607] Added tests for inclusion of 'external_id' field in Contact model requests
1 parent 9516fac commit 1e77f8f

1 file changed

Lines changed: 150 additions & 0 deletions

File tree

test/chartmogul/contact.js

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Contact', () => {
1313
customer_uuid: 'cus_919d5d7c-9e23-11ed-a936-97fbf69ba02b',
1414
data_source_uuid: 'ds_87832fac-ab61-11ec-a8d8-6fb18044a151',
1515
data_source_customer_external_id: 'scus_606e14228cff7d9db01be55f4e32e5e4',
16+
external_id: 'contact_external_id_001',
1617
first_name: 'First name',
1718
last_name: 'Last name',
1819
position: 9,
@@ -37,6 +38,7 @@ describe('Contact', () => {
3738
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000',
3839
data_source_uuid: 'ds_00000000-0000-0000-0000-000000000000',
3940
data_source_customer_external_id: 'external_001',
41+
external_id: 'contact_external_id_001',
4042
first_name: 'First name',
4143
last_name: 'Last name',
4244
position: 9,
@@ -57,6 +59,109 @@ describe('Contact', () => {
5759
expect(contact).to.have.property('uuid');
5860
});
5961

62+
it('creates a new contact without external_id', async () => {
63+
const postBody = {
64+
/* eslint-disable camelcase */
65+
customer_uuid: 'cus_919d5d7c-9e23-11ed-a936-97fbf69ba02b',
66+
data_source_uuid: 'ds_87832fac-ab61-11ec-a8d8-6fb18044a151',
67+
data_source_customer_external_id: 'scus_606e14228cff7d9db01be55f4e32e5e4',
68+
first_name: 'First name',
69+
last_name: 'Last name',
70+
position: 9,
71+
title: 'Title',
72+
email: 'test@example.com',
73+
phone: '+1234567890',
74+
linked_in: 'https://linkedin.com/not_found',
75+
twitter: 'https://twitter.com/not_found',
76+
notes: 'Heading\nBody\nFooter',
77+
custom: [
78+
{ key: 'Booleanz', value: false },
79+
{ key: 'MyIntegerAttribute', value: 123 }
80+
]
81+
/* eslint-enable camelcase */
82+
};
83+
84+
nock(config.API_BASE)
85+
.post('/v1/contacts', postBody)
86+
.reply(200, {
87+
/* eslint-disable camelcase */
88+
uuid: 'con_00000000-0000-0000-0000-000000000000',
89+
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000',
90+
data_source_uuid: 'ds_00000000-0000-0000-0000-000000000000',
91+
data_source_customer_external_id: 'external_001',
92+
external_id: null,
93+
first_name: 'First name',
94+
last_name: 'Last name',
95+
position: 9,
96+
title: 'Title',
97+
email: 'test@example.com',
98+
phone: '+1234567890',
99+
linked_in: 'https://linkedin.com/not_found',
100+
twitter: 'https://twitter.com/not_found',
101+
notes: 'Heading\nBody\nFooter',
102+
custom: {
103+
MyStringAttribute: 'Test',
104+
MyIntegerAttribute: 123
105+
}
106+
/* eslint-enable camelcase */
107+
});
108+
109+
const contact = await Contact.create(config, postBody);
110+
expect(contact.external_id).to.equal(null);
111+
});
112+
113+
it('creates a new contact with external_id as null', async () => {
114+
const postBody = {
115+
/* eslint-disable camelcase */
116+
customer_uuid: 'cus_919d5d7c-9e23-11ed-a936-97fbf69ba02b',
117+
data_source_uuid: 'ds_87832fac-ab61-11ec-a8d8-6fb18044a151',
118+
data_source_customer_external_id: 'scus_606e14228cff7d9db01be55f4e32e5e4',
119+
external_id: null,
120+
first_name: 'First name',
121+
last_name: 'Last name',
122+
position: 9,
123+
title: 'Title',
124+
email: 'test@example.com',
125+
phone: '+1234567890',
126+
linked_in: 'https://linkedin.com/not_found',
127+
twitter: 'https://twitter.com/not_found',
128+
notes: 'Heading\nBody\nFooter',
129+
custom: [
130+
{ key: 'Booleanz', value: false },
131+
{ key: 'MyIntegerAttribute', value: 123 }
132+
]
133+
/* eslint-enable camelcase */
134+
};
135+
136+
nock(config.API_BASE)
137+
.post('/v1/contacts', postBody)
138+
.reply(200, {
139+
/* eslint-disable camelcase */
140+
uuid: 'con_00000000-0000-0000-0000-000000000000',
141+
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000',
142+
data_source_uuid: 'ds_00000000-0000-0000-0000-000000000000',
143+
data_source_customer_external_id: 'external_001',
144+
external_id: null,
145+
first_name: 'First name',
146+
last_name: 'Last name',
147+
position: 9,
148+
title: 'Title',
149+
email: 'test@example.com',
150+
phone: '+1234567890',
151+
linked_in: 'https://linkedin.com/not_found',
152+
twitter: 'https://twitter.com/not_found',
153+
notes: 'Heading\nBody\nFooter',
154+
custom: {
155+
MyStringAttribute: 'Test',
156+
MyIntegerAttribute: 123
157+
}
158+
/* eslint-enable camelcase */
159+
});
160+
161+
const contact = await Contact.create(config, postBody);
162+
expect(contact.external_id).to.equal(null);
163+
});
164+
60165
it('should list all contacts with pagination', async () => {
61166
const query = {
62167
per_page: 1,
@@ -118,6 +223,7 @@ describe('Contact', () => {
118223
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000',
119224
data_source_uuid: 'ds_00000000-0000-0000-0000-000000000000',
120225
customer_external_id: 'external_001',
226+
external_id: 'contact_external_id_001',
121227
first_name: 'First name',
122228
last_name: 'Last name',
123229
position: 9,
@@ -161,6 +267,50 @@ describe('Contact', () => {
161267
expect(contact.email).to.be.equal('test2@example.com');
162268
});
163269

270+
it('updates a contact with external_id as a string', async () => {
271+
const contactUuid = 'con_00000000-0000-0000-0000-000000000000';
272+
273+
/* eslint-disable camelcase */
274+
const patchBody = { external_id: 'contact_external_id_002' };
275+
/* eslint-enable camelcase */
276+
277+
nock(config.API_BASE)
278+
.patch(`/v1/contacts/${contactUuid}`, patchBody)
279+
.reply(200, {
280+
/* eslint-disable camelcase */
281+
uuid: contactUuid,
282+
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000',
283+
data_source_uuid: 'ds_00000000-0000-0000-0000-000000000000',
284+
external_id: 'contact_external_id_002'
285+
/* eslint-enable camelcase */
286+
});
287+
288+
const contact = await Contact.modify(config, contactUuid, patchBody);
289+
expect(contact.external_id).to.be.equal('contact_external_id_002');
290+
});
291+
292+
it('updates a contact with external_id as null', async () => {
293+
const contactUuid = 'con_00000000-0000-0000-0000-000000000000';
294+
295+
/* eslint-disable camelcase */
296+
const patchBody = { external_id: null };
297+
/* eslint-enable camelcase */
298+
299+
nock(config.API_BASE)
300+
.patch(`/v1/contacts/${contactUuid}`, patchBody)
301+
.reply(200, {
302+
/* eslint-disable camelcase */
303+
uuid: contactUuid,
304+
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000',
305+
data_source_uuid: 'ds_00000000-0000-0000-0000-000000000000',
306+
external_id: null
307+
/* eslint-enable camelcase */
308+
});
309+
310+
const contact = await Contact.modify(config, contactUuid, patchBody);
311+
expect(contact.external_id).to.equal(null);
312+
});
313+
164314
it('deletes a contact', async () => {
165315
const uuid = 'con_00000000-0000-0000-0000-000000000000';
166316

0 commit comments

Comments
 (0)