@@ -116,4 +116,65 @@ describe('users', () => {
116116 done ( ) ;
117117 } ) ;
118118 } ) ;
119+ it ( 'should permanently delete users by Intercom user ID in params' , ( done ) => {
120+ nock ( 'https://api.intercom.io' )
121+ . post ( '/user_delete_requests' , { intercom_user_id : 'foo' } )
122+ . reply ( 200 , { id : 10 } ) ;
123+ const client = new Client ( 'foo' , 'bar' ) . usePromises ( ) ;
124+ client . users . requestPermanentDeletionByParams ( { id : 'foo' } ) . then ( ( r ) => {
125+ assert . equal ( 200 , r . statusCode ) ;
126+ assert . deepStrictEqual ( { id : 10 } , r . body ) ;
127+ done ( ) ;
128+ } ) ;
129+ } ) ;
130+ it ( 'should permanently delete users by user_id' , ( done ) => {
131+ nock ( 'https://api.intercom.io' )
132+ . get ( '/users' )
133+ . query ( { user_id : 'foo' } )
134+ . reply ( 200 , { id : 10 } )
135+ . post ( '/user_delete_requests' , { intercom_user_id : 10 } )
136+ . reply ( 200 , { id : 10 } ) ;
137+ const client = new Client ( 'foo' , 'bar' ) . usePromises ( ) ;
138+ client . users . requestPermanentDeletionByParams ( { user_id : 'foo' } ) . then ( ( r ) => {
139+ assert . equal ( 200 , r . statusCode ) ;
140+ assert . deepStrictEqual ( { id : 10 } , r . body ) ;
141+ done ( ) ;
142+ } ) ;
143+ } ) ;
144+ it ( 'should permanently delete users by email' , ( done ) => {
145+ nock ( 'https://api.intercom.io' )
146+ . get ( '/users' )
147+ . query ( { email : 'foo' } )
148+ . reply ( 200 , { id : 10 } )
149+ . post ( '/user_delete_requests' , { intercom_user_id : 10 } )
150+ . reply ( 200 , { id : 10 } ) ;
151+ const client = new Client ( 'foo' , 'bar' ) . usePromises ( ) ;
152+ client . users . requestPermanentDeletionByParams ( { email : 'foo' } ) . then ( ( r ) => {
153+ assert . equal ( 200 , r . statusCode ) ;
154+ assert . deepStrictEqual ( { id : 10 } , r . body ) ;
155+ done ( ) ;
156+ } ) ;
157+ } ) ;
158+ it ( 'should callback with errors if calls fail' , ( done ) => {
159+ nock ( 'https://api.intercom.io' )
160+ . get ( '/users' )
161+ . query ( { email : 'foo' } )
162+ . reply ( 200 , { type : 'error.list' } ) ;
163+ const client = new Client ( 'foo' , 'bar' ) ;
164+ client . users . requestPermanentDeletionByParams ( { email : 'foo' } , ( err ) => {
165+ assert . equal ( true , err instanceof Error ) ;
166+ done ( ) ;
167+ } ) ;
168+ } ) ;
169+ it ( 'should reject promises if calls fail' , ( done ) => {
170+ nock ( 'https://api.intercom.io' )
171+ . get ( '/users' )
172+ . query ( { email : 'foo' } )
173+ . reply ( 200 , { type : 'error.list' } ) ;
174+ const client = new Client ( 'foo' , 'bar' ) . usePromises ( ) ;
175+ client . users . requestPermanentDeletionByParams ( { email : 'foo' } ) . catch ( err => {
176+ assert . equal ( true , err instanceof Error ) ;
177+ done ( ) ;
178+ } ) ;
179+ } ) ;
119180} ) ;
0 commit comments