Skip to content

Commit

Permalink
re-introduce the "no-project" placeholder, e2e test for --billable
Browse files Browse the repository at this point in the history
  • Loading branch information
maelvls committed Jul 19, 2021
1 parent bf068c6 commit 9d5f27e
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 34 deletions.
2 changes: 1 addition & 1 deletion clockify/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func TestClockify_TimeEntries(t *testing.T) {
Description: "some work with project but no task",
TagIds: []interface{}{},
UserID: "60e086c24f27a949c058082d",
Billable: true,
Billable: false,
TaskID: "",
ProjectID: "60e0a9cf5f596c5a7d10d821",
TimeInterval: TimeInterval{
Expand Down
4 changes: 2 additions & 2 deletions clockify/fixtures/testclockify_projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interactions:
Content-Type:
- application/json
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down Expand Up @@ -57,7 +57,7 @@ interactions:
Content-Length:
- "0"
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down
4 changes: 2 additions & 2 deletions clockify/fixtures/testclockify_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interactions:
Content-Type:
- application/json
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down Expand Up @@ -59,7 +59,7 @@ interactions:
Content-Type:
- application/json
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down
10 changes: 5 additions & 5 deletions clockify/fixtures/testclockify_timeentries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ interactions:
work with project but no task","tagIds":[],"userId":"60e086c24f27a949c058082d","billable":true,"taskId":null,"projectId":"60e0a9cf5f596c5a7d10d821","timeInterval":{"start":"2021-07-03T14:45:00Z","end":"2021-07-03T15:30:00Z","duration":"PT45M"},"workspaceId":"60e086c24f27a949c058082e","isLocked":false,"customFieldValues":null},{"id":"60f467bbf547ce2601a54b59","description":"unit-test
of clockidup, work with project and task","tagIds":[],"userId":"60e086c24f27a949c058082d","billable":true,"taskId":"60e0a9f00afa073620eade56","projectId":"60e0a9cf5f596c5a7d10d821","timeInterval":{"start":"2021-07-03T14:30:00Z","end":"2021-07-03T14:45:00Z","duration":"PT15M"},"workspaceId":"60e086c24f27a949c058082e","isLocked":false,"customFieldValues":null},{"id":"60e0ccf4909afe51901a154c","description":"work
with no project","tagIds":[],"userId":"60e086c24f27a949c058082d","billable":false,"taskId":null,"projectId":null,"timeInterval":{"start":"2021-07-03T13:30:00Z","end":"2021-07-03T14:00:00Z","duration":"PT30M"},"workspaceId":"60e086c24f27a949c058082e","isLocked":false,"customFieldValues":null},{"id":"60e0cccf909afe51901a151c","description":"some
work with project but no task","tagIds":[],"userId":"60e086c24f27a949c058082d","billable":true,"taskId":null,"projectId":"60e0a9cf5f596c5a7d10d821","timeInterval":{"start":"2021-07-03T13:00:00Z","end":"2021-07-03T13:30:00Z","duration":"PT30M"},"workspaceId":"60e086c24f27a949c058082e","isLocked":false,"customFieldValues":null},{"id":"60e0ccbc4f27a949c058498b","description":"unit-test
work with project but no task","tagIds":[],"userId":"60e086c24f27a949c058082d","billable":false,"taskId":null,"projectId":"60e0a9cf5f596c5a7d10d821","timeInterval":{"start":"2021-07-03T13:00:00Z","end":"2021-07-03T13:30:00Z","duration":"PT30M"},"workspaceId":"60e086c24f27a949c058082e","isLocked":false,"customFieldValues":null},{"id":"60e0ccbc4f27a949c058498b","description":"unit-test
of clockidup, work with project and task","tagIds":[],"userId":"60e086c24f27a949c058082d","billable":true,"taskId":"60e0a9f00afa073620eade56","projectId":"60e0a9cf5f596c5a7d10d821","timeInterval":{"start":"2021-07-03T12:30:00Z","end":"2021-07-03T13:00:00Z","duration":"PT30M"},"workspaceId":"60e086c24f27a949c058082e","isLocked":false,"customFieldValues":null},{"id":"60f4681ba18d2d6d98bdab2c","description":"work
on project-2","tagIds":[],"userId":"60e086c24f27a949c058082d","billable":true,"taskId":null,"projectId":"60f4681a0fdfe402db9afae9","timeInterval":{"start":"2021-07-03T10:30:00Z","end":"2021-07-03T11:15:00Z","duration":"PT45M"},"workspaceId":"60e086c24f27a949c058082e","isLocked":false,"customFieldValues":null}]'
headers:
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Content-Length:
- "2659"
- "2660"
Content-Type:
- application/json
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down Expand Up @@ -63,7 +63,7 @@ interactions:
Content-Length:
- "0"
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down Expand Up @@ -103,7 +103,7 @@ interactions:
Content-Type:
- application/json
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down
4 changes: 2 additions & 2 deletions clockify/fixtures/testclockify_workspaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interactions:
Content-Type:
- application/json
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down Expand Up @@ -61,7 +61,7 @@ interactions:
Content-Type:
- application/json
Date:
- Sun, 18 Jul 2021 18:00:24 GMT
- Mon, 19 Jul 2021 08:50:21 GMT
Expected-Client-Version:
- 1.0.0
Expires:
Expand Down
21 changes: 14 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ where {{ url "DAY" }} is of the form:
"2 days ago"
2021-01-28
{{- if not .Extended }}
To see how to use clockidup, run:
clockidup help
{{- end -}}
{{- if .Extended }}
{{ section "HOW TO USE IT" }}
Expand Down Expand Up @@ -100,11 +107,7 @@ The auth token is saved to {{ url "~/.config/clockidup.yml" }}. The file looks
like this:
token: your-clockify-auth-token
{{- end }}
{{- if not .Extended }}
More help is available with the command {{ yel "clockidup help" }}.
workspace: workspace-1
{{- end }}
Expand Down Expand Up @@ -282,12 +285,12 @@ func Run(tokenFlag string, workspaceFlag string, printHelp func(bool) func()) er
return fmt.Errorf("while fetching time entries: %w", err)
}

entries = mergeSimilarEntries(entries)

if *onlyBillable {
entries = selectBillable(entries)
}

entries = mergeSimilarEntries(entries)

// Print the current day e.g., "Monday" if the date is within a week in
// the past; otherwise, print "2021-01-28".
if day.After(time.Now().AddDate(0, 0, -6)) {
Expand All @@ -299,6 +302,10 @@ func Run(tokenFlag string, workspaceFlag string, printHelp func(bool) func()) er
for i := range entries {
entry := entries[len(entries)-i-1]

if entry.Project == "" {
entry.Project = "no-project"
}

// The format "%.1f" (precision = 1) rounds the 2nd digit after the
// decimal to the closest neighbor. We also remove the leading zero to
// distinguish "small" amounts (e.g. 0.5) from larger amounts (e.g.
Expand Down
30 changes: 28 additions & 2 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ func Test_CLI(t *testing.T) {
assert.Equal(t, 0, cli.ProcessState.ExitCode())
})

t.Run("extended help", func(t *testing.T) {
cmd := exec.Command(cli, "help")
cli := startWith(t, cmd).Wait()

output := contents(cli.Output)
assert.Contains(t, output, "HOW TO USE IT")
assert.Equal(t, 0, cli.ProcessState.ExitCode())
})

t.Run("no token available", func(t *testing.T) {
home := withConfigInFakeHome(t, "")
cmd := exec.Command(cli, "--server=http://localhost:"+port, "2021-07-03")
Expand Down Expand Up @@ -116,7 +125,24 @@ func Test_CLI(t *testing.T) {
- [.8] project-2: work on project-2
- [.8] project-1: unit-test of clockidup, work with project and task
- [1.2] project-1: some work with project but no task
- [1.8] : work with no project
- [1.8] no-project: work with no project
`), output)

assert.Equal(t, 0, cli.ProcessState.ExitCode())
})

t.Run("--billable only shows the entries that are billable", func(t *testing.T) {
home := withConfigInFakeHome(t, "")
cmd := exec.Command(cli, "--server=http://localhost:"+port, "--billable", "--workspace=workspace-1", "--token="+withToken(t), "2021-07-03")
cmd.Env = append(cmd.Env, "HOME="+home)
cli := startWith(t, cmd).Wait()

output := contents(cli.Output)
assert.Equal(t, heredoc.Doc(`
2021-07-03:
- [.8] project-2: work on project-2
- [.8] project-1: unit-test of clockidup, work with project and task
- [.8] project-1: some work with project but no task
`), output)

assert.Equal(t, 0, cli.ProcessState.ExitCode())
Expand Down Expand Up @@ -189,7 +215,7 @@ func withConfigInFakeHome(t *testing.T, clockidupConfigYAML string) string {
home, err := ioutil.TempDir("", "clockidup-e2e-*")
require.NoError(t, err)
t.Cleanup(func() {
// os.RemoveAll(home)
os.RemoveAll(home)
})
os.MkdirAll(home+"/.config", 0755)

Expand Down
Loading

0 comments on commit 9d5f27e

Please sign in to comment.