Skip to content

Commit

Permalink
feat: search-project-with-client config (#256)
Browse files Browse the repository at this point in the history
* feat: search-project-with-client config

* fix: tests

* fix: doc block
  • Loading branch information
lucassabreu authored Feb 16, 2024
1 parent 844eac3 commit e16e522
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 84 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- new config `search-project-with-client` to set whether or not the cli should lookup projects using the
client's name too

## [v0.47.0] - 2024-02-09

### Added
Expand Down
45 changes: 45 additions & 0 deletions internal/mocks/mock_Config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 21 additions & 14 deletions internal/mocks/simple_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ import "github.com/lucassabreu/clockify-cli/pkg/cmdutil"
// SimpleConfig is used to set configs for tests were changing the config or
// accessing them with Get and All is not important
type SimpleConfig struct {
WorkweekDays []string
Interactive bool
InteractivePageSizeNumber int
AllowNameForID bool
UserID string
Workspace string
Token string
AllowIncomplete bool
ShowTask bool
DescriptionAutocomplete bool
DescriptionAutocompleteDays int
ShowTotalDuration bool
LogLevelValue string
AllowArchivedTags bool
WorkweekDays []string
Interactive bool
InteractivePageSizeNumber int
AllowNameForID bool
UserID string
Workspace string
Token string
AllowIncomplete bool
ShowTask bool
DescriptionAutocomplete bool
DescriptionAutocompleteDays int
ShowTotalDuration bool
LogLevelValue string
AllowArchivedTags bool
SearchProjectWithClientsName bool
}

// IsSearchProjectWithClientsName defines if the project name for ID should
// include the client's name
func (s *SimpleConfig) IsSearchProjectWithClientsName() bool {
return s.SearchProjectWithClientsName
}

// InteractivePageSize sets how many items are shown when prompting
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ func NewCmdInit(f cmdutil.Factory) *cobra.Command {
return err
}

if config.IsAllowNameForID() {
if err := updateFlag(i, config,
cmdutil.CONF_SEARCH_PROJECTS_WITH_CLIENT_NAME,
`Should search projects looking into their `+
`client's name too?`,
); err != nil {
return err
}
}

if err := updateFlag(i, config, cmdutil.CONF_INTERACTIVE,
`Should use "Interactive Mode" by default?`,
); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion pkg/cmd/config/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ func TestInitCmd(t *testing.T) {

setStringFn(config, cmdutil.CONF_USER_ID, "user-1")

setBoolFn(config, cmdutil.CONF_ALLOW_NAME_FOR_ID, false, true)
setBoolFn(config, cmdutil.CONF_ALLOW_NAME_FOR_ID, false, true).
Run(func(args mock.Arguments) {
config.EXPECT().IsAllowNameForID().Return(true)
})
setBoolFn(config, cmdutil.CONF_SEARCH_PROJECTS_WITH_CLIENT_NAME,
false, true)
setBoolFn(config, cmdutil.CONF_INTERACTIVE, false, false)

config.EXPECT().GetInt(cmdutil.CONF_INTERACTIVE_PAGE_SIZE).
Expand Down Expand Up @@ -130,6 +135,10 @@ func TestInitCmd(t *testing.T) {
c.SendLine("y")
c.ExpectString("Yes")

c.ExpectString("search projects looking into their client's name")
c.SendLine("y")
c.ExpectString("Yes")

c.ExpectString("Interactive Mode\" by default?")
c.SendLine("n")
c.ExpectString("No")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/project/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewCmdGet(

if f.Config().IsAllowNameForID() {
if p.ProjectID, err = search.GetProjectByName(
c, p.Workspace, p.ProjectID, ""); err != nil {
c, f.Config(), p.Workspace, p.ProjectID, ""); err != nil {
return err
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/project/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestCmdGet(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.EXPECT().Config().Return(cf)
cf.EXPECT().IsAllowNameForID().Return(true)
cf.EXPECT().IsSearchProjectWithClientsName().Return(true)

c := mocks.NewMockClient(t)
f.EXPECT().Client().Return(c, nil)
Expand Down Expand Up @@ -155,6 +156,7 @@ func TestCmdGet(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.EXPECT().Config().Return(cf)
cf.EXPECT().IsAllowNameForID().Return(true)
cf.EXPECT().IsSearchProjectWithClientsName().Return(true)

c := mocks.NewMockClient(t)
f.EXPECT().Client().Return(c, nil)
Expand Down
32 changes: 14 additions & 18 deletions pkg/cmd/task/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ func TestCmdAdd(t *testing.T) {
f.On("GetWorkspaceID").
Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(false)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})

f.On("Client").Return(nil, errors.New("client error"))
return f
Expand Down Expand Up @@ -115,9 +113,9 @@ func TestCmdAdd(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand All @@ -138,9 +136,9 @@ func TestCmdAdd(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down Expand Up @@ -168,9 +166,7 @@ func TestCmdAdd(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(false)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})

c.On("AddTask", api.AddTaskParam{
Workspace: "w",
Expand All @@ -196,9 +192,9 @@ func TestCmdAdd(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down Expand Up @@ -237,9 +233,9 @@ func TestCmdAdd(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/task/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewCmdDelete(

if f.Config().IsAllowNameForID() {
if project, err = search.GetProjectByName(
c, w, project, ""); err != nil {
c, f.Config(), w, project, ""); err != nil {
return err
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/task/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestCmdDelete(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
Expand All @@ -96,6 +97,7 @@ func TestCmdDelete(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
Expand Down Expand Up @@ -124,6 +126,7 @@ func TestCmdDelete(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
Expand Down Expand Up @@ -162,6 +165,7 @@ func TestCmdDelete(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)

c := mocks.NewMockClient(t)
f.On("Client").Return(c, nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/task/done/done.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewCmdDone(

if f.Config().IsAllowNameForID() {
if project, err = search.GetProjectByName(
c, workspace, project, ""); err != nil {
c, f.Config(), workspace, project, ""); err != nil {
return err
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/task/done/done_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestCmdDone(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down Expand Up @@ -178,6 +179,7 @@ func TestCmdDone(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down Expand Up @@ -237,6 +239,7 @@ func TestCmdDone(t *testing.T) {
cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
cf.On("IsSearchProjectWithClientsName").Return(true)

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down
28 changes: 13 additions & 15 deletions pkg/cmd/task/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ func TestCmdEdit(t *testing.T) {
f.On("GetWorkspaceID").
Return("w", nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(false)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})

f.On("Client").Return(nil, errors.New("client error"))
return f
Expand Down Expand Up @@ -147,9 +145,9 @@ func TestCmdEdit(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down Expand Up @@ -177,9 +175,9 @@ func TestCmdEdit(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down Expand Up @@ -239,9 +237,9 @@ func TestCmdEdit(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down Expand Up @@ -290,9 +288,9 @@ func TestCmdEdit(t *testing.T) {
Return("w", nil)
f.On("Client").Return(c, nil)

cf := mocks.NewMockConfig(t)
f.On("Config").Return(cf)
cf.On("IsAllowNameForID").Return(true)
f.EXPECT().Config().Return(&mocks.SimpleConfig{
AllowNameForID: true,
})

c.On("GetProjects", api.GetProjectsParam{
Workspace: "w",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/task/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewCmdList(
if f.Config().IsAllowNameForID() &&
p.ProjectID != "" {
if p.ProjectID, err = search.GetProjectByName(
c, workspace, p.ProjectID, ""); err != nil {
c, f.Config(), workspace, p.ProjectID, ""); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit e16e522

Please sign in to comment.