44 "bytes"
55 "context"
66 "errors"
7+ "fmt"
78 "io"
89 "net/http"
910 "os"
@@ -86,7 +87,7 @@ func TestProfilesList_Empty(t *testing.T) {
8687 buf := captureProfilesOutput (t )
8788 fake := & FakeProfilesService {}
8889 p := ProfilesCmd {profiles : fake }
89- _ = p .List (context .Background (), ProfilesListInput {})
90+ _ = p .List (context .Background (), ProfilesListInput {Page : 1 , PerPage : 20 })
9091 assert .Contains (t , buf .String (), "No profiles found" )
9192}
9293
@@ -98,11 +99,65 @@ func TestProfilesList_WithRows(t *testing.T) {
9899 return & pagination.OffsetPagination [kernel.Profile ]{Items : rows }, nil
99100 }}
100101 p := ProfilesCmd {profiles : fake }
101- _ = p .List (context .Background (), ProfilesListInput {})
102+ _ = p .List (context .Background (), ProfilesListInput {Page : 1 , PerPage : 20 })
102103 out := buf .String ()
103104 assert .Contains (t , out , "p1" )
104105 assert .Contains (t , out , "alpha" )
105106 assert .Contains (t , out , "p2" )
107+ assert .Contains (t , out , "Has more: no" )
108+ }
109+
110+ func TestProfilesList_HasMore (t * testing.T ) {
111+ buf := captureProfilesOutput (t )
112+ created := time .Unix (0 , 0 )
113+ perPage := 2
114+ items := make ([]kernel.Profile , perPage + 1 )
115+ for i := range items {
116+ items [i ] = kernel.Profile {ID : fmt .Sprintf ("p%d" , i ), CreatedAt : created , UpdatedAt : created }
117+ }
118+ fake := & FakeProfilesService {ListFunc : func (ctx context.Context , query kernel.ProfileListParams , opts ... option.RequestOption ) (* pagination.OffsetPagination [kernel.Profile ], error ) {
119+ return & pagination.OffsetPagination [kernel.Profile ]{Items : items }, nil
120+ }}
121+ p := ProfilesCmd {profiles : fake }
122+ _ = p .List (context .Background (), ProfilesListInput {Page : 1 , PerPage : perPage })
123+ out := buf .String ()
124+ assert .Contains (t , out , "Has more: yes" )
125+ assert .Contains (t , out , "Next: kernel profile list --page 2 --per-page 2" )
126+ assert .Contains (t , out , "p0" )
127+ assert .Contains (t , out , "p1" )
128+ assert .NotContains (t , out , "p2" )
129+ }
130+
131+ func TestProfilesList_QueryInNextHint (t * testing.T ) {
132+ buf := captureProfilesOutput (t )
133+ created := time .Unix (0 , 0 )
134+ items := make ([]kernel.Profile , 3 )
135+ for i := range items {
136+ items [i ] = kernel.Profile {ID : fmt .Sprintf ("p%d" , i ), CreatedAt : created , UpdatedAt : created }
137+ }
138+ fake := & FakeProfilesService {ListFunc : func (ctx context.Context , query kernel.ProfileListParams , opts ... option.RequestOption ) (* pagination.OffsetPagination [kernel.Profile ], error ) {
139+ return & pagination.OffsetPagination [kernel.Profile ]{Items : items }, nil
140+ }}
141+ p := ProfilesCmd {profiles : fake }
142+ _ = p .List (context .Background (), ProfilesListInput {Page : 1 , PerPage : 2 , Query : "my-bot" })
143+ out := buf .String ()
144+ assert .Contains (t , out , `--query "my-bot"` )
145+ }
146+
147+ func TestProfilesList_QueryWithSpacesQuoted (t * testing.T ) {
148+ buf := captureProfilesOutput (t )
149+ created := time .Unix (0 , 0 )
150+ items := make ([]kernel.Profile , 3 )
151+ for i := range items {
152+ items [i ] = kernel.Profile {ID : fmt .Sprintf ("p%d" , i ), CreatedAt : created , UpdatedAt : created }
153+ }
154+ fake := & FakeProfilesService {ListFunc : func (ctx context.Context , query kernel.ProfileListParams , opts ... option.RequestOption ) (* pagination.OffsetPagination [kernel.Profile ], error ) {
155+ return & pagination.OffsetPagination [kernel.Profile ]{Items : items }, nil
156+ }}
157+ p := ProfilesCmd {profiles : fake }
158+ _ = p .List (context .Background (), ProfilesListInput {Page : 1 , PerPage : 2 , Query : "my bot" })
159+ out := buf .String ()
160+ assert .Contains (t , out , `--query "my bot"` )
106161}
107162
108163func TestProfilesGet_Success (t * testing.T ) {
0 commit comments