@@ -11,7 +11,15 @@ afterEach(() => {
1111} ) ;
1212
1313describe ( "registerUsersCli" , ( ) => {
14- it ( "routes link-email through the admin gateway method" , async ( ) => {
14+ it ( "reports the authoritative linked profile and uses the admin gateway method" , async ( ) => {
15+ const output = vi . spyOn ( process . stdout , "write" ) . mockImplementation ( ( ) => true ) ;
16+ callGatewayFromCli . mockResolvedValue ( {
17+ profile : {
18+ id : "p-1\nshadow" ,
19+ displayName : "Ada\tadmin\u001b[2J" ,
20+ 21+ } ,
22+ } ) ;
1523 const program = new Command ( ) . exitOverride ( ) ;
1624 registerUsersCli ( program ) ;
1725
@@ -31,6 +39,37 @@ describe("registerUsersCli", () => {
3139 { email :
"[email protected] " , targetProfileId :
"p-1" } , 3240 { scopes : [ "operator.admin" ] } ,
3341 ) ;
42+ expect ( output ) . toHaveBeenCalledWith (
43+ 44+ ) ;
45+ } ) ;
46+
47+ it ( "reports an empty user profile list" , async ( ) => {
48+ const output = vi . spyOn ( process . stdout , "write" ) . mockImplementation ( ( ) => true ) ;
49+ callGatewayFromCli . mockResolvedValue ( { profiles : [ ] } ) ;
50+ const program = new Command ( ) . exitOverride ( ) ;
51+ registerUsersCli ( program ) ;
52+
53+ await program . parseAsync ( [ "node" , "openclaw" , "users" , "list" ] ) ;
54+
55+ expect ( callGatewayFromCli ) . toHaveBeenCalledWith (
56+ "users.list" ,
57+ expect . any ( Object ) ,
58+ { } ,
59+ { scopes : [ "operator.read" ] } ,
60+ ) ;
61+ expect ( output ) . toHaveBeenCalledWith ( "No user profiles found.\n" ) ;
62+ } ) ;
63+
64+ it ( "preserves the empty profile list JSON response" , async ( ) => {
65+ const output = vi . spyOn ( process . stdout , "write" ) . mockImplementation ( ( ) => true ) ;
66+ callGatewayFromCli . mockResolvedValue ( { profiles : [ ] } ) ;
67+ const program = new Command ( ) . exitOverride ( ) ;
68+ registerUsersCli ( program ) ;
69+
70+ await program . parseAsync ( [ "node" , "openclaw" , "users" , "list" , "--json" ] ) ;
71+
72+ expect ( output ) . toHaveBeenCalledWith ( '{\n "profiles": []\n}\n' ) ;
3473 } ) ;
3574
3675 it ( "prints the link result as JSON when requested" , async ( ) => {
0 commit comments