@@ -225,4 +225,45 @@ describe("List Customers By Name", () => {
225225 expect ( customers [ 100 ] . customerId ) . toEqual ( "customer-101" ) ;
226226 expect ( customers [ 149 ] . customerId ) . toEqual ( "customer-150" ) ;
227227 } ) ;
228+
229+ it ( "should search across all apps when appSlug is undefined" , async ( ) => {
230+ const customersResponse = {
231+ data : [
232+ { id : "customer-1" , name : "Test Customer" , app_name : "App 1" } ,
233+ { id : "customer-2" , name : "Test Customer Two" , app_name : "App 2" } ,
234+ { id : "customer-3" , name : "Test Customer Three" , app_name : "App 3" }
235+ ] ,
236+ total_count : 3
237+ } ;
238+
239+ // When appSlug is undefined, we should NOT call the /apps endpoint
240+ // Just set up the search endpoint response
241+ await mockServer . forPost ( "/customers/search" ) . thenReply ( 200 , JSON . stringify ( customersResponse ) ) ;
242+
243+ const customers : CustomerSummary [ ] = await listCustomersByName ( apiClient , undefined , "Test Customer" ) ;
244+ expect ( customers ) . toHaveLength ( 3 ) ;
245+ expect ( customers [ 0 ] . name ) . toEqual ( "Test Customer" ) ;
246+ expect ( customers [ 1 ] . name ) . toEqual ( "Test Customer Two" ) ;
247+ expect ( customers [ 2 ] . name ) . toEqual ( "Test Customer Three" ) ;
248+ } ) ;
249+
250+ it ( "should include app_id when appSlug is provided" , async ( ) => {
251+ const appId = "test-app-123" ;
252+ const appSlug = "test-app" ;
253+ const expectedApplications = {
254+ apps : [ { id : appId , name : "Test App" , slug : appSlug } ]
255+ } ;
256+ const customersResponse = {
257+ data : [ { id : "customer-1" , name : "Test Customer" } ] ,
258+ total_count : 1
259+ } ;
260+
261+ // When appSlug is provided, we should call /apps first, then search
262+ await mockServer . forGet ( "/apps" ) . thenReply ( 200 , JSON . stringify ( expectedApplications ) ) ;
263+ await mockServer . forPost ( "/customers/search" ) . thenReply ( 200 , JSON . stringify ( customersResponse ) ) ;
264+
265+ const customers : CustomerSummary [ ] = await listCustomersByName ( apiClient , appSlug , "Test Customer" ) ;
266+ expect ( customers ) . toHaveLength ( 1 ) ;
267+ expect ( customers [ 0 ] . name ) . toEqual ( "Test Customer" ) ;
268+ } ) ;
228269} ) ;
0 commit comments