Skip to content

Commit 4c998af

Browse files
committed
feat: limit results
1 parent 7531afa commit 4c998af

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed

pkg/cmd/time-entry/report/today/today_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,45 @@ func TestCmdToday(t *testing.T) {
193193
time-entry-2
194194
`),
195195
},
196+
{
197+
name: "report only the first time entry",
198+
args: "--limit 2 -q",
199+
factory: func(t *testing.T) cmdutil.Factory {
200+
f := mocks.NewMockFactory(t)
201+
f.On("GetUserID").Return("user-id", nil)
202+
f.On("GetWorkspaceID").Return("w-id", nil)
203+
204+
f.On("Config").Return(&mocks.SimpleConfig{})
205+
206+
c := mocks.NewMockClient(t)
207+
f.On("Client").Return(c, nil)
208+
209+
c.On("LogRange", api.LogRangeParam{
210+
Workspace: "w-id",
211+
UserID: "user-id",
212+
FirstDate: first,
213+
LastDate: last,
214+
TagIDs: []string{},
215+
PaginationParam: api.PaginationParam{
216+
Page: 1,
217+
PageSize: 2,
218+
},
219+
}).
220+
Return(
221+
[]dto.TimeEntry{
222+
{ID: "time-entry-1"},
223+
{ID: "time-entry-2"},
224+
},
225+
nil,
226+
)
227+
228+
return f
229+
},
230+
expected: heredoc.Doc(`
231+
time-entry-1
232+
time-entry-2
233+
`),
234+
},
196235
}
197236

198237
for i := range tts {

pkg/cmd/time-entry/report/util/reportwithrange_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,136 @@ func TestReportWithRange(t *testing.T) {
668668
2006-01-04 22:00:00
669669
`),
670670
},
671+
{
672+
name: "limit number of time entries",
673+
flags: func(t *testing.T) util.ReportFlags {
674+
rf := util.NewReportFlags()
675+
rf.Limit = 2
676+
rf.Quiet = true
677+
return rf
678+
},
679+
factory: func(t *testing.T) cmdutil.Factory {
680+
f := mocks.NewMockFactory(t)
681+
f.On("GetUserID").Return("u", nil)
682+
f.On("GetWorkspaceID").Return("w", nil)
683+
684+
f.EXPECT().Config().Return(
685+
&mocks.SimpleConfig{AllowNameForID: true})
686+
687+
c := mocks.NewMockClient(t)
688+
f.On("Client").Return(c, nil)
689+
690+
c.EXPECT().LogRange(api.LogRangeParam{
691+
Workspace: "w",
692+
UserID: "u",
693+
FirstDate: first,
694+
LastDate: last,
695+
PaginationParam: api.PaginationParam{
696+
Page: 1,
697+
PageSize: 2,
698+
},
699+
}).Return([]dto.TimeEntry{
700+
{ID: "te-1",
701+
TimeInterval: dto.TimeInterval{
702+
Start: first,
703+
},
704+
},
705+
{ID: "te-3",
706+
TimeInterval: dto.TimeInterval{
707+
Start: first.Add(time.Duration(2)),
708+
},
709+
},
710+
}, nil)
711+
712+
return f
713+
},
714+
expected: heredoc.Doc(`
715+
te-1
716+
te-3
717+
`),
718+
},
719+
{
720+
name: "limit number of time entries with client filter",
721+
flags: func(t *testing.T) util.ReportFlags {
722+
rf := util.NewReportFlags()
723+
rf.Limit = 2
724+
rf.Client = "me"
725+
rf.Quiet = true
726+
return rf
727+
},
728+
factory: func(t *testing.T) cmdutil.Factory {
729+
730+
f := mocks.NewMockFactory(t)
731+
f.On("GetUserID").Return("u", nil)
732+
f.On("GetWorkspaceID").Return("w", nil)
733+
734+
f.EXPECT().Config().Return(
735+
&mocks.SimpleConfig{AllowNameForID: true})
736+
737+
c := mocks.NewMockClient(t)
738+
f.On("Client").Return(c, nil)
739+
740+
c.EXPECT().GetClients(api.GetClientsParam{
741+
Workspace: "w",
742+
PaginationParam: api.AllPages(),
743+
}).
744+
Return([]dto.Client{
745+
{ID: "c1", Name: "me"},
746+
{ID: "c2", Name: "you"},
747+
}, nil)
748+
749+
c.EXPECT().GetProjects(api.GetProjectsParam{
750+
Workspace: "w",
751+
Clients: []string{"c1"},
752+
PaginationParam: api.AllPages(),
753+
}).Return([]dto.Project{
754+
{ID: "p1", Name: "p1", ClientID: "c1", ClientName: "me"},
755+
{ID: "p3", Name: "p3", ClientID: "c1", ClientName: "me"},
756+
}, nil)
757+
758+
p := api.PaginationParam{Page: 1, PageSize: 2}
759+
c.EXPECT().LogRange(api.LogRangeParam{
760+
Workspace: "w",
761+
UserID: "u",
762+
ProjectID: "p1",
763+
FirstDate: first,
764+
LastDate: last,
765+
PaginationParam: p,
766+
}).Return([]dto.TimeEntry{
767+
{ID: "te-1",
768+
TimeInterval: dto.TimeInterval{
769+
Start: first,
770+
},
771+
},
772+
{ID: "te-3",
773+
TimeInterval: dto.TimeInterval{
774+
Start: first.Add(time.Duration(2)),
775+
},
776+
},
777+
}, nil)
778+
779+
c.EXPECT().LogRange(api.LogRangeParam{
780+
Workspace: "w",
781+
UserID: "u",
782+
ProjectID: "p3",
783+
FirstDate: first,
784+
LastDate: last,
785+
PaginationParam: p,
786+
}).Return([]dto.TimeEntry{
787+
{ID: "te-2",
788+
TimeInterval: dto.TimeInterval{
789+
Start: first.Add(time.Duration(1)),
790+
},
791+
},
792+
}, nil)
793+
794+
return f
795+
},
796+
expected: heredoc.Doc(`
797+
te-1
798+
te-2
799+
`),
800+
},
671801
}
672802

673803
for _, tt := range tts {

0 commit comments

Comments
 (0)