@@ -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,70 @@ describe('Contact', () => {
5759 expect ( contact ) . to . have . property ( 'uuid' ) ;
5860 } ) ;
5961
62+ it ( 'creates a new contact with external_id as null' , 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+ external_id : null ,
69+ first_name : 'First name' ,
70+ last_name : 'Last name' ,
71+ position : 9 ,
72+ title : 'Title' ,
73+ email : 'test@example.com' ,
74+ phone : '+1234567890' ,
75+ linked_in : 'https://linkedin.com/not_found' ,
76+ twitter : 'https://twitter.com/not_found' ,
77+ notes : 'Heading\nBody\nFooter' ,
78+ custom : [
79+ { key : 'Booleanz' , value : false } ,
80+ { key : 'MyIntegerAttribute' , value : 123 }
81+ ]
82+ /* eslint-enable camelcase */
83+ } ;
84+
85+ let requestBody ;
86+ nock ( config . API_BASE )
87+ . post ( '/v1/contacts' , body => { requestBody = body ; return true ; } )
88+ . reply ( 200 , { uuid : 'con_00000000-0000-0000-0000-000000000000' } ) ;
89+
90+ await Contact . create ( config , postBody ) ;
91+ // eslint-disable-next-line no-unused-expressions
92+ expect ( requestBody ) . to . have . property ( 'external_id' ) . that . is . null ;
93+ } ) ;
94+
95+ it ( 'creates a new contact without external_id' , async ( ) => {
96+ const postBody = {
97+ /* eslint-disable camelcase */
98+ customer_uuid : 'cus_919d5d7c-9e23-11ed-a936-97fbf69ba02b' ,
99+ data_source_uuid : 'ds_87832fac-ab61-11ec-a8d8-6fb18044a151' ,
100+ data_source_customer_external_id : 'scus_606e14228cff7d9db01be55f4e32e5e4' ,
101+ first_name : 'First name' ,
102+ last_name : 'Last name' ,
103+ position : 9 ,
104+ title : 'Title' ,
105+ email : 'test@example.com' ,
106+ phone : '+1234567890' ,
107+ linked_in : 'https://linkedin.com/not_found' ,
108+ twitter : 'https://twitter.com/not_found' ,
109+ notes : 'Heading\nBody\nFooter' ,
110+ custom : [
111+ { key : 'Booleanz' , value : false } ,
112+ { key : 'MyIntegerAttribute' , value : 123 }
113+ ]
114+ /* eslint-enable camelcase */
115+ } ;
116+
117+ let requestBody ;
118+ nock ( config . API_BASE )
119+ . post ( '/v1/contacts' , body => { requestBody = body ; return true ; } )
120+ . reply ( 200 , { uuid : 'con_00000000-0000-0000-0000-000000000000' } ) ;
121+
122+ await Contact . create ( config , postBody ) ;
123+ expect ( requestBody ) . to . not . have . property ( 'external_id' ) ;
124+ } ) ;
125+
60126 it ( 'should list all contacts with pagination' , async ( ) => {
61127 const query = {
62128 per_page : 1 ,
@@ -118,6 +184,7 @@ describe('Contact', () => {
118184 customer_uuid : 'cus_00000000-0000-0000-0000-000000000000' ,
119185 data_source_uuid : 'ds_00000000-0000-0000-0000-000000000000' ,
120186 customer_external_id : 'external_001' ,
187+ external_id : 'contact_external_id_001' ,
121188 first_name : 'First name' ,
122189 last_name : 'Last name' ,
123190 position : 9 ,
@@ -142,23 +209,42 @@ describe('Contact', () => {
142209 const contactUuid = 'con_00000000-0000-0000-0000-000000000000' ;
143210
144211 /* eslint-disable camelcase */
145- const postBody = { email : 'test2@example.com' } ;
212+ const patchBody = { email : 'test2@example.com' , external_id : 'contact_external_id_002 ' } ;
146213 /* eslint-enable camelcase */
147214
148215 nock ( config . API_BASE )
149- . patch ( `/v1/contacts/${ contactUuid } ` , postBody )
216+ . patch ( `/v1/contacts/${ contactUuid } ` , patchBody )
150217 . reply ( 200 , {
151218 /* eslint-disable camelcase */
152219 uuid : contactUuid ,
153220 customer_uuid : 'cus_00000000-0000-0000-0000-000000000000' ,
154221 data_source_uuid : 'ds_00000000-0000-0000-0000-000000000000' ,
155222 customer_external_id : 'external_001' ,
156- email : 'test2@example.com'
223+ email : 'test2@example.com' ,
224+ external_id : 'contact_external_id_002'
157225 /* eslint-enable camelcase */
158226 } ) ;
159227
160- const contact = await Contact . modify ( config , contactUuid , postBody ) ;
228+ const contact = await Contact . modify ( config , contactUuid , patchBody ) ;
161229 expect ( contact . email ) . to . be . equal ( 'test2@example.com' ) ;
230+ expect ( contact . external_id ) . to . be . equal ( 'contact_external_id_002' ) ;
231+ } ) ;
232+
233+ it ( 'updates a contact with external_id as null' , async ( ) => {
234+ const contactUuid = 'con_00000000-0000-0000-0000-000000000000' ;
235+
236+ /* eslint-disable camelcase */
237+ const patchBody = { external_id : null } ;
238+ /* eslint-enable camelcase */
239+
240+ let requestBody ;
241+ nock ( config . API_BASE )
242+ . patch ( `/v1/contacts/${ contactUuid } ` , body => { requestBody = body ; return true ; } )
243+ . reply ( 200 , { uuid : contactUuid } ) ;
244+
245+ await Contact . modify ( config , contactUuid , patchBody ) ;
246+ // eslint-disable-next-line no-unused-expressions
247+ expect ( requestBody ) . to . have . property ( 'external_id' ) . that . is . null ;
162248 } ) ;
163249
164250 it ( 'deletes a contact' , async ( ) => {
0 commit comments