Skip to content

Commit

Permalink
rev: get projects (archived: nil)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Apr 6, 2024
1 parent eaf7e35 commit 51b415b
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 218 deletions.
2 changes: 0 additions & 2 deletions pkg/cmd/project/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func TestCmdGet(t *testing.T) {

c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).
Return([]dto.Project{{Name: "project", ID: "p1"}}, nil)
Expand Down Expand Up @@ -166,7 +165,6 @@ func TestCmdGet(t *testing.T) {

c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).
Return([]dto.Project{{Name: "project", ID: "p1"}}, nil)
Expand Down
58 changes: 27 additions & 31 deletions pkg/cmd/task/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func TestCmdAdd(t *testing.T) {
args: []string{"-n=a", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").
f.EXPECT().GetWorkspaceID().
Return("w", nil)

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

f.On("Client").Return(nil, errors.New("client error"))
f.EXPECT().Client().Return(nil, errors.New("client error"))
return f
},
},
Expand All @@ -99,7 +99,7 @@ func TestCmdAdd(t *testing.T) {
args: []string{"-n=a", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").
f.EXPECT().GetWorkspaceID().
Return("", errors.New("workspace error"))
return f
},
Expand All @@ -111,17 +111,16 @@ func TestCmdAdd(t *testing.T) {
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
c := mocks.NewMockClient(t)
f.On("GetWorkspaceID").
f.EXPECT().GetWorkspaceID().
Return("w", nil)
f.On("Client").Return(c, nil)
f.EXPECT().Client().Return(c, nil)

f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).
Return([]dto.Project{}, errors.New("no project"))
Expand All @@ -135,22 +134,21 @@ func TestCmdAdd(t *testing.T) {
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
c := mocks.NewMockClient(t)
f.On("GetWorkspaceID").
f.EXPECT().GetWorkspaceID().
Return("w", nil)
f.On("Client").Return(c, nil)
f.EXPECT().Client().Return(c, nil)

f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).
Return([]dto.Project{{Name: "Cli"}}, nil)

c.On("WorkspaceUsers", api.WorkspaceUsersParam{
c.EXPECT().WorkspaceUsers(api.WorkspaceUsersParam{
Workspace: "w",
PaginationParam: api.AllPages(),
}).
Expand All @@ -166,13 +164,13 @@ func TestCmdAdd(t *testing.T) {
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
c := mocks.NewMockClient(t)
f.On("GetWorkspaceID").
f.EXPECT().GetWorkspaceID().
Return("w", nil)
f.On("Client").Return(c, nil)
f.EXPECT().Client().Return(c, nil)

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

c.On("AddTask", api.AddTaskParam{
c.EXPECT().AddTask(api.AddTaskParam{
Workspace: "w",
ProjectID: "ok",
Name: "error",
Expand All @@ -192,24 +190,23 @@ func TestCmdAdd(t *testing.T) {
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
c := mocks.NewMockClient(t)
f.On("GetWorkspaceID").
f.EXPECT().GetWorkspaceID().
Return("w", nil)
f.On("Client").Return(c, nil)
f.EXPECT().Client().Return(c, nil)

f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).Return(
[]dto.Project{{ID: "p-1", Name: "Clockify CLI"}}, nil)

b := true
e := time.Hour * 32
c.On("AddTask", api.AddTaskParam{
c.EXPECT().AddTask(api.AddTaskParam{
Workspace: "w",
Name: "Add",
ProjectID: "p-1",
Expand All @@ -234,22 +231,21 @@ func TestCmdAdd(t *testing.T) {
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
c := mocks.NewMockClient(t)
f.On("GetWorkspaceID").
f.EXPECT().GetWorkspaceID().
Return("w", nil)
f.On("Client").Return(c, nil)
f.EXPECT().Client().Return(c, nil)

f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).Return(
[]dto.Project{{ID: "p-1", Name: "Clockify CLI"}}, nil)

c.On("WorkspaceUsers", api.WorkspaceUsersParam{
c.EXPECT().WorkspaceUsers(api.WorkspaceUsersParam{
Workspace: "w",
PaginationParam: api.AllPages(),
}).Return(
Expand All @@ -260,7 +256,7 @@ func TestCmdAdd(t *testing.T) {

b := false
as := []string{"u-1", "u-2"}
c.On("AddTask", api.AddTaskParam{
c.EXPECT().AddTask(api.AddTaskParam{
Workspace: "w",
Name: "Add Task",
ProjectID: "p-1",
Expand Down Expand Up @@ -352,16 +348,16 @@ func TestCmdAddReport(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
f := mocks.NewMockFactory(t)
c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
f.On("GetWorkspaceID").
f.EXPECT().Client().Return(c, nil)
f.EXPECT().GetWorkspaceID().
Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
f.EXPECT().Config().Return(cf)

cf.On("IsAllowNameForID").Return(false)
cf.EXPECT().IsAllowNameForID().Return(false)

c.On("AddTask", api.AddTaskParam{
c.EXPECT().AddTask(api.AddTaskParam{
Workspace: "w",
ProjectID: "p-1",
Name: "Task Add",
Expand Down
78 changes: 37 additions & 41 deletions pkg/cmd/task/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCmdDelete(t *testing.T) {
args: []string{"task-id", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").Return("", errors.New("w error"))
f.EXPECT().GetWorkspaceID().Return("", errors.New("w error"))
return f, nil
},
},
Expand All @@ -60,8 +60,8 @@ func TestCmdDelete(t *testing.T) {
args: []string{"task-id", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").Return("w", nil)
f.On("Client").Return(nil, errors.New("c error"))
f.EXPECT().GetWorkspaceID().Return("w", nil)
f.EXPECT().Client().Return(nil, errors.New("c error"))
return f, nil
},
},
Expand All @@ -71,18 +71,17 @@ func TestCmdDelete(t *testing.T) {
args: []string{"task-id", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").Return("w", nil)
f.EXPECT().GetWorkspaceID().Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)
f.EXPECT().Config().Return(cf)
cf.EXPECT().IsAllowNameForID().Return(true)
cf.EXPECT().IsSearchProjectWithClientsName().Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
c.On("GetProjects", api.GetProjectsParam{
f.EXPECT().Client().Return(c, nil)
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).Return([]dto.Project{}, nil)

Expand All @@ -95,22 +94,21 @@ func TestCmdDelete(t *testing.T) {
args: []string{"task-id", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").Return("w", nil)
f.EXPECT().GetWorkspaceID().Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)
f.EXPECT().Config().Return(cf)
cf.EXPECT().IsAllowNameForID().Return(true)
cf.EXPECT().IsSearchProjectWithClientsName().Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
c.On("GetProjects", api.GetProjectsParam{
f.EXPECT().Client().Return(c, nil)
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).Return([]dto.Project{{ID: "p-1"}}, nil)

c.On("GetTasks", api.GetTasksParam{
c.EXPECT().GetTasks(api.GetTasksParam{
Workspace: "w",
ProjectID: "p-1",
PaginationParam: api.AllPages(),
Expand All @@ -125,18 +123,17 @@ func TestCmdDelete(t *testing.T) {
args: []string{"delete", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").Return("w", nil)
f.EXPECT().GetWorkspaceID().Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)
f.EXPECT().Config().Return(cf)
cf.EXPECT().IsAllowNameForID().Return(true)
cf.EXPECT().IsSearchProjectWithClientsName().Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
c.On("GetProjects", api.GetProjectsParam{
f.EXPECT().Client().Return(c, nil)
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).Return([]dto.Project{{ID: "p-1"}}, nil)

Expand All @@ -145,13 +142,13 @@ func TestCmdDelete(t *testing.T) {
Name: "Delete Task",
ProjectID: "p-1",
}
c.On("GetTasks", api.GetTasksParam{
c.EXPECT().GetTasks(api.GetTasksParam{
Workspace: "w",
ProjectID: "p-1",
PaginationParam: api.AllPages(),
}).Return([]dto.Task{te}, nil)

c.On("DeleteTask", api.DeleteTaskParam{
c.EXPECT().DeleteTask(api.DeleteTaskParam{
Workspace: "w",
ProjectID: "p-1",
TaskID: "task-id",
Expand All @@ -165,18 +162,17 @@ func TestCmdDelete(t *testing.T) {
args: []string{"delete", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.On("GetWorkspaceID").Return("w", nil)
f.EXPECT().GetWorkspaceID().Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)
f.EXPECT().Config().Return(cf)
cf.EXPECT().IsAllowNameForID().Return(true)
cf.EXPECT().IsSearchProjectWithClientsName().Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
c.On("GetProjects", api.GetProjectsParam{
f.EXPECT().Client().Return(c, nil)
c.EXPECT().GetProjects(api.GetProjectsParam{
Workspace: "w",
Archived: &bFalse,
PaginationParam: api.AllPages(),
}).Return([]dto.Project{{ID: "p-1"}}, nil)

Expand All @@ -185,13 +181,13 @@ func TestCmdDelete(t *testing.T) {
Name: "Delete Task",
ProjectID: "p-1",
}
c.On("GetTasks", api.GetTasksParam{
c.EXPECT().GetTasks(api.GetTasksParam{
Workspace: "w",
ProjectID: "p-1",
PaginationParam: api.AllPages(),
}).Return([]dto.Task{te}, nil)

c.On("DeleteTask", api.DeleteTaskParam{
c.EXPECT().DeleteTask(api.DeleteTaskParam{
Workspace: "w",
ProjectID: "p-1",
TaskID: "task-id",
Expand Down Expand Up @@ -285,16 +281,16 @@ func TestCmdDeleteReport(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
f := mocks.NewMockFactory(t)
c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
f.On("GetWorkspaceID").
f.EXPECT().Client().Return(c, nil)
f.EXPECT().GetWorkspaceID().
Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
f.EXPECT().Config().Return(cf)

cf.On("IsAllowNameForID").Return(false)
cf.EXPECT().IsAllowNameForID().Return(false)

c.On("DeleteTask", api.DeleteTaskParam{
c.EXPECT().DeleteTask(api.DeleteTaskParam{
Workspace: "w",
ProjectID: "p-1",
TaskID: "t-1",
Expand Down
Loading

0 comments on commit 51b415b

Please sign in to comment.