@@ -10,6 +10,7 @@ import {
1010import { IterableClient } from "../../src/client" ;
1111import {
1212 GetUserByEmailParamsSchema ,
13+ MergeUsersParamsSchema ,
1314 UpdateEmailParamsSchema ,
1415 UpdateUserParamsSchema ,
1516 UpdateUserSubscriptionsParamsSchema ,
@@ -267,6 +268,78 @@ describe("User Management", () => {
267268 } ) ;
268269 } ) ;
269270
271+ describe ( "mergeUsers" , ( ) => {
272+ it ( "should call merge endpoint with email-based params" , async ( ) => {
273+ const params = {
274+ sourceEmail : "source@example.com" ,
275+ destinationEmail : "dest@example.com" ,
276+ } ;
277+ const mockResponse = { data : { code : "Success" , msg : "Merged" } } ;
278+ mockAxiosInstance . post . mockResolvedValue ( mockResponse ) ;
279+
280+ const result = await client . mergeUsers ( params ) ;
281+
282+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
283+ "/api/users/merge" ,
284+ params
285+ ) ;
286+ expect ( result . code ) . toBe ( "Success" ) ;
287+ } ) ;
288+
289+ it ( "should call merge endpoint with userId-based params" , async ( ) => {
290+ const params = {
291+ sourceUserId : "src-user-123" ,
292+ destinationUserId : "dst-user-456" ,
293+ } ;
294+ const mockResponse = { data : { code : "Success" , msg : "Merged" } } ;
295+ mockAxiosInstance . post . mockResolvedValue ( mockResponse ) ;
296+
297+ const result = await client . mergeUsers ( params ) ;
298+
299+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
300+ "/api/users/merge" ,
301+ params
302+ ) ;
303+ expect ( result . code ) . toBe ( "Success" ) ;
304+ } ) ;
305+
306+ it ( "should support mixed email/userId identifiers" , async ( ) => {
307+ const params = {
308+ sourceEmail : "source@example.com" ,
309+ destinationUserId : "dst-user-456" ,
310+ } ;
311+ const mockResponse = { data : { code : "Success" , msg : "Merged" } } ;
312+ mockAxiosInstance . post . mockResolvedValue ( mockResponse ) ;
313+
314+ await client . mergeUsers ( params ) ;
315+
316+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
317+ "/api/users/merge" ,
318+ params
319+ ) ;
320+ } ) ;
321+
322+ it ( "should support arrayMerge parameter" , async ( ) => {
323+ const params = {
324+ sourceEmail : "source@example.com" ,
325+ destinationEmail : "dest@example.com" ,
326+ arrayMerge : [
327+ { field : "purchaseHistory" , dedupeBy : "orderId" } ,
328+ { field : "tags" } ,
329+ ] ,
330+ } ;
331+ const mockResponse = { data : { code : "Success" , msg : "Merged" } } ;
332+ mockAxiosInstance . post . mockResolvedValue ( mockResponse ) ;
333+
334+ await client . mergeUsers ( params ) ;
335+
336+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
337+ "/api/users/merge" ,
338+ params
339+ ) ;
340+ } ) ;
341+ } ) ;
342+
270343 describe ( "Schema Validation" , ( ) => {
271344 it ( "should validate get_user_by_email parameters" , ( ) => {
272345 expect ( ( ) =>
@@ -369,5 +442,62 @@ describe("User Management", () => {
369442 } )
370443 ) . not . toThrow ( ) ;
371444 } ) ;
445+
446+ it ( "should validate mergeUsers parameters" , ( ) => {
447+ // Valid: email to email
448+ expect ( ( ) =>
449+ MergeUsersParamsSchema . parse ( {
450+ sourceEmail : "source@example.com" ,
451+ destinationEmail : "dest@example.com" ,
452+ } )
453+ ) . not . toThrow ( ) ;
454+
455+ // Valid: userId to userId
456+ expect ( ( ) =>
457+ MergeUsersParamsSchema . parse ( {
458+ sourceUserId : "src-123" ,
459+ destinationUserId : "dst-456" ,
460+ } )
461+ ) . not . toThrow ( ) ;
462+
463+ // Valid: email to userId (mixed)
464+ expect ( ( ) =>
465+ MergeUsersParamsSchema . parse ( {
466+ sourceEmail : "source@example.com" ,
467+ destinationUserId : "dst-456" ,
468+ } )
469+ ) . not . toThrow ( ) ;
470+
471+ // Valid: with arrayMerge
472+ expect ( ( ) =>
473+ MergeUsersParamsSchema . parse ( {
474+ sourceEmail : "source@example.com" ,
475+ destinationEmail : "dest@example.com" ,
476+ arrayMerge : [ { field : "tags" } , { field : "orders" , dedupeBy : "id" } ] ,
477+ } )
478+ ) . not . toThrow ( ) ;
479+
480+ // Invalid: missing source
481+ expect ( ( ) =>
482+ MergeUsersParamsSchema . parse ( {
483+ destinationEmail : "dest@example.com" ,
484+ } )
485+ ) . toThrow ( ) ;
486+
487+ // Invalid: missing destination
488+ expect ( ( ) =>
489+ MergeUsersParamsSchema . parse ( {
490+ sourceEmail : "source@example.com" ,
491+ } )
492+ ) . toThrow ( ) ;
493+
494+ // Invalid: bad email format
495+ expect ( ( ) =>
496+ MergeUsersParamsSchema . parse ( {
497+ sourceEmail : "not-an-email" ,
498+ destinationEmail : "dest@example.com" ,
499+ } )
500+ ) . toThrow ( ) ;
501+ } ) ;
372502 } ) ;
373503} ) ;
0 commit comments