Skip to content

Commit

Permalink
(wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Jul 16, 2024
1 parent 6f12bb3 commit eb79f40
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/cmd/time-entry/in/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func NewCmdIn(
return err
}

tei, err = util.FromDefaults(f)(tei)

Check failure on line 110 in pkg/cmd/time-entry/in/in.go

View workflow job for this annotation

GitHub Actions / tests

undefined: util.FromDefaults

Check failure on line 110 in pkg/cmd/time-entry/in/in.go

View workflow job for this annotation

GitHub Actions / goreleaser

undefined: util.FromDefaults

Check failure on line 110 in pkg/cmd/time-entry/in/in.go

View workflow job for this annotation

GitHub Actions / lint

undefined: util.FromDefaults (typecheck)

Check failure on line 110 in pkg/cmd/time-entry/in/in.go

View workflow job for this annotation

GitHub Actions / lint

undefined: util.FromDefaults) (typecheck)

Check failure on line 110 in pkg/cmd/time-entry/in/in.go

View workflow job for this annotation

GitHub Actions / lint

undefined: util.FromDefaults) (typecheck)
if err != nil {
return err
}

c, err := f.Client()
if err != nil {
return err
Expand All @@ -124,6 +129,7 @@ func NewCmdIn(

if tei, err = util.Do(
tei,

util.FillTimeEntryWithFlags(cmd.Flags()),
util.ValidateClosingTimeEntry(f),
util.GetAllowNameForIDsFn(f.Config(), c),
Expand Down
48 changes: 45 additions & 3 deletions pkg/cmd/time-entry/in/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ import (

var w = dto.Workspace{ID: "w"}

func newTEDNotFound(t *testing.T) defaults.TimeEntryDefaults {
ted := mocks.NewMockTimeEntryDefaults(t)
ted.EXPECT().Read().Return(
defaults.DefaultTimeEntry{}, defaults.DefaultsFileNotFoundErr)

return ted
}

func TestNewCmdIn_ShouldBeBothBillableAndNotBillable(t *testing.T) {
f := mocks.NewMockFactory(t)

f.EXPECT().GetUserID().Return("u", nil)
f.EXPECT().GetWorkspaceID().Return(w.ID, nil)
f.EXPECT().TimeEntryDefaults().Return(newTEDNotFound(t))

f.EXPECT().Config().Return(&mocks.SimpleConfig{})

Expand Down Expand Up @@ -58,9 +67,10 @@ func TestNewCmdIn_ShouldBeBothBillableAndNotBillable(t *testing.T) {
t.Fatal("should've failed")
}

var bTrue = true
var bFalse = false

func TestNewCmdIn_ShouldNotSetBillable_WhenNotAsked(t *testing.T) {
bTrue := true
bFalse := false

tts := []struct {
name string
Expand Down Expand Up @@ -105,6 +115,7 @@ func TestNewCmdIn_ShouldNotSetBillable_WhenNotAsked(t *testing.T) {
f.EXPECT().GetUserID().Return("u", nil)
f.EXPECT().GetWorkspace().Return(w, nil)
f.EXPECT().GetWorkspaceID().Return(w.ID, nil)
f.EXPECT().TimeEntryDefaults().Return(newTEDNotFound(t))

f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
Expand Down Expand Up @@ -259,6 +270,7 @@ func TestNewCmdIn_ShouldLookupProject_WithAndWithoutClient(t *testing.T) {

f.EXPECT().GetUserID().Return("u", nil)
f.EXPECT().GetWorkspaceID().Return(w.ID, nil)
f.EXPECT().TimeEntryDefaults().Return(newTEDNotFound(t))

f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
Expand Down Expand Up @@ -364,6 +376,10 @@ func TestNewCmdIn_ShouldUseDefaults(t *testing.T) {
c.EXPECT().CreateTimeEntry(exp).
Return(dto.TimeEntryImpl{ID: "te"}, nil)

ted := mocks.NewMockTimeEntryDefaults(t)
f.EXPECT().TimeEntryDefaults().Return(ted)
ted.EXPECT().Read().Return(d, nil)

called := false
cmd := in.NewCmdIn(f, func(
_ dto.TimeEntryImpl, _ io.Writer, _ util.OutputFlags) error {
Expand All @@ -390,11 +406,37 @@ func TestNewCmdIn_ShouldUseDefaults(t *testing.T) {
}

ft("only defaults",
defaults.DefaultTimeEntry{},
defaults.DefaultTimeEntry{
Workspace: w.ID,
ProjectID: "p1",
TaskID: "t",
Billable: &bTrue,
TagIDs: []string{"t1", "t2"},
},
[]string{},
api.CreateTimeEntryParam{
Workspace: w.ID,
Start: timehlp.Now(),
ProjectID: "p1",
TaskID: "t",
Billable: &bTrue,
TagIDs: []string{"t1", "t2"},
},
)

ft("flags over defaults",
defaults.DefaultTimeEntry{
Workspace: w.ID,
ProjectID: "p1",
TaskID: "t",
TagIDs: []string{"t1", "t2"},
},
[]string{"-T", "tag", "-p", "p2"},
api.CreateTimeEntryParam{
Workspace: w.ID,
Start: timehlp.Now(),
ProjectID: "p2",
TagIDs: []string{"tag"},
},
)
}

0 comments on commit eb79f40

Please sign in to comment.