Repository: JanDeDobbeleer/oh-my-posh
Pull request #3569 (2023-03-10 17:18:47)

fix(wakatime)!: fix struct `wtData` binding from API response, from `Cummulative` to `Cumulative`
### Prerequisites

- [X] I have read and understood the [contributing guide][CONTRIBUTING.md]
- [X] The commit message follows the [conventional commits][cc] guidelines
- [ ] Tests for the changes have been added (for bug fixes/features)
- [X] Docs have been added/updated (for bug fixes/features)

### Description

**This is a breaking change.**

It's been a while since I noticed that the Wakatime segment for my theme has disappeared. Upon inspection, Wakatime has changed one of the returned JSON's parent key names from `cummulative_total` to `cumulative_total`.

The following is just the excerpt of the payload as of now:

```json
{
  "cumulative_total": {
    "decimal": "0.02",
    "digital": "0:01",
    "seconds": 109.270097,
    "text": "1 min"
  },
  "daily_average": {},
  "data": [ ],
  "end": "2023-03-11T15:59:59Z",
  "start": "2023-03-10T16:00:00Z"
}
```

The unexpected change was _assumed in the first place_ since I have [snapshots of my theme](https://github.com/CodexLink/chips.omp.json#git-states-segment) that shows the Wakatime segment. After finding the problem, it is somehow true that the API changed. But upon (light) research, I can't seem to find any evidence that their API has changed, but either way ...

This PR fixes that by **correcting the spelling** from **cummulative** to **cumulative** for both **component** and **documentation** hence, _becoming a breaking change_. Other than that, the PR also contains the following:

- Added an additional checking that emits an error stating that the response returned from the Wakatime API should be checked due to struct `wtData` containing _an empty context_/_is an empty struct_.
- Added an additional context from the fake payload (on _wakatime_test.go_) to avoid tripping the test cases.

> Note that the additional checker (for the `wtData`) from the _wakatime.go_ was not added to the part of test cases since it's going to be a bit of a hassle vs. adding the checker itself from the main code segment instead.

> Plus, the test cases (_exclusive to wakatime_) are just emulating the context that the API returned. Declaring another test case will have other test cases to adjust because the `response` must be compatible with every test case declared. _But in the end, it's possible to include it in the test case, but there will be adjustments_.

### Disclaimer

This is **my first time using Golang**, suggestions and requests for changes are extremely welcome.


Patch:
diff --git a/src/segments/wakatime.go b/src/segments/wakatime.go
index 0cfbaed8..ee509ff4 100644
--- a/src/segments/wakatime.go
+++ b/src/segments/wakatime.go
@@ -21,13 +21,13 @@ type wtTotals struct {
 }
 
 type wtData struct {
-	CummulativeTotal wtTotals `json:"cummulative_total"`
-	Start            string   `json:"start"`
-	End              string   `json:"end"`
+	CumulativeTotal wtTotals `json:"cumulative_total"`
+	Start           string   `json:"start"`
+	End             string   `json:"end"`
 }
 
 func (w *Wakatime) Template() string {
-	return " {{ secondsRound .CummulativeTotal.Seconds }} "
+	return " {{ secondsRound .CumulativeTotal.Seconds }} "
 }
 
 func (w *Wakatime) Enabled() bool {
diff --git a/website/docs/segments/wakatime.mdx b/website/docs/segments/wakatime.mdx
index 314782ec..7d9301ae 100644
--- a/website/docs/segments/wakatime.mdx
+++ b/website/docs/segments/wakatime.mdx
@@ -53,7 +53,7 @@ If you don't want to include the API key into your configuration, the following
 }
 ```
 
-:::note 
+:::note
 
 `WAKATIME_API_KEY` is an example, **any name is possible and acceptable** as long as the environment variable exists and contains the API key value.
 
@@ -66,7 +66,7 @@ Please refer to the [Environment Variable][templates-environment-variables] page
 :::note default template
 
 ```template
-{{ secondsRound .CummulativeTotal.Seconds }}
+{{ secondsRound .CumulativeTotal.Seconds }}
 ```
 
 :::
@@ -75,7 +75,7 @@ Please refer to the [Environment Variable][templates-environment-variables] page
 
 | Name                | Type       | Description                              |
 | ------------------- | ---------- | ---------------------------------------- |
-| `.CummulativeTotal` | `wtTotals` | object holding total tracked time values |
+| `.CumulativeTotal` | `wtTotals` | object holding total tracked time values |
 
 ### wtTotals Properties
 


Test patch:
diff --git a/src/segments/wakatime_test.go b/src/segments/wakatime_test.go
index adef912d..2070f9da 100644
--- a/src/segments/wakatime_test.go
+++ b/src/segments/wakatime_test.go
@@ -73,8 +73,7 @@ func TestWTTrackedTime(t *testing.T) {
 
 	for _, tc := range cases {
 		env := &mock.MockedEnvironment{}
-
-		response := fmt.Sprintf(`{"cummulative_total": {"seconds": %.2f, "text": "x"}}`, float64(tc.Seconds))
+		response := fmt.Sprintf(`{"cumulative_total": {"seconds": %.2f, "text": "x"}}`, float64(tc.Seconds))
 
 		env.On("HTTPRequest", FAKEAPIURL).Return([]byte(response), tc.Error)