From 72cc33fa90fc6473f897f56efa9b905ad740307f Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Sat, 6 Apr 2024 21:25:53 -0300 Subject: [PATCH] fix: force interactive --- pkg/cmd/time-entry/defaults/set/set.go | 14 +++++++------- pkg/cmd/time-entry/defaults/set/set_test.go | 14 ++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/pkg/cmd/time-entry/defaults/set/set.go b/pkg/cmd/time-entry/defaults/set/set.go index 0a6167f8..6d90a85a 100644 --- a/pkg/cmd/time-entry/defaults/set/set.go +++ b/pkg/cmd/time-entry/defaults/set/set.go @@ -54,12 +54,12 @@ func NewCmdSet( return err } + c, err := f.Client() if changed || d.Workspace != n.Workspace { if n.TaskID != "" && n.ProjectID == "" { return errors.New("can't set task without project") } - c, err := f.Client() if err != nil { return err } @@ -71,12 +71,6 @@ func NewCmdSet( } } - if f.Config().IsInteractive() { - if n, err = ask(n, f.Config(), c, f.UI()); err != nil { - return err - } - } - if !f.Config().IsAllowNameForID() { if err = checkIDs(c, n); err != nil { return err @@ -84,6 +78,12 @@ func NewCmdSet( } } + if f.Config().IsInteractive() { + if n, err = ask(n, f.Config(), c, f.UI()); err != nil { + return err + } + } + if err = f.TimeEntryDefaults().Write(n); err != nil { return err } diff --git a/pkg/cmd/time-entry/defaults/set/set_test.go b/pkg/cmd/time-entry/defaults/set/set_test.go index 8f720963..d118ae37 100644 --- a/pkg/cmd/time-entry/defaults/set/set_test.go +++ b/pkg/cmd/time-entry/defaults/set/set_test.go @@ -515,6 +515,9 @@ func TestNewCmdSet_ShouldFail_WhenInvalidArgs(t *testing.T) { f.EXPECT().GetWorkspaceID().Return("w", nil) + f.EXPECT().Client(). + Return(mocks.NewMockClient(t), nil) + return f }, }, @@ -622,16 +625,21 @@ func TestNewCmdSet_ShouldUpdateDefaultsFile_OnlyByFlags(t *testing.T) { for i := range tts { tt := &tts[i] t.Run(tt.name, func(t *testing.T) { + f := mocks.NewMockFactory(t) + c := mocks.NewMockClient(t) + f.EXPECT().Client(). + Return(c, nil) + + f.EXPECT().Config().Return(&mocks.SimpleConfig{}) + if len(tt.args) != 0 { f.EXPECT().Config().Return(&mocks.SimpleConfig{ AllowNameForID: false, Interactive: false, }) - c := mocks.NewMockClient(t) - tasks := make([]dto.Task, 0) if tt.expected.TaskID != "" { @@ -656,8 +664,6 @@ func TestNewCmdSet_ShouldUpdateDefaultsFile_OnlyByFlags(t *testing.T) { c.On("GetTags", mock.Anything).Return(tags, nil) } - - f.EXPECT().Client().Return(c, nil) } f.EXPECT().GetWorkspaceID().Return(tt.expected.Workspace, nil)