Repository: nicklaw5/helix (go)

Issue:
Get Emote Sets missing OwnerID value
The [Get Emote Sets](https://github.com/nicklaw5/helix/blob/main/chat.go#L128) function is missing the `OwnerID` value returned [from the API](https://dev.twitch.tv/docs/api/reference#get-emote-sets).

The simple solution is to add `OwnerID` to the `Emote` type, but that'd mean an empty value in the other calls using the type (i.e. Get Channel Emotes and Get Global Emotes).
The complex solution is to return a different type in the response of Get Emote Sets.

I'm happy to make the change with a PR but I'd like to hear your preferred solution first.

Pull request description:
Fix GetEmoteSets method missing OwnerID in emote response
- `GetEmoteSets` now returns a `GetEmoteSetsResponse` instead of `GetChannelEmotesResponse`
- Ensure emotes are marshalled properly in `TestGetEmoteSets`

There's still a few ways you could chose to do the emote type - I went with a "parent" type EmoteWithOwner - let me know if you have another preference.

Unrelated to the PR but I noteiced while working on this - The naming of the `Set_ID` parameter seems out of place among all the other members. Would love to see that changed to `SetID` but I'll create an issue for it instead of rambling on in this PR.

Fixes #98 

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 67210aa..65013f7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,6 +1,9 @@
 name: Tests and Coverage
 
-on: [push, pull_request]
+on:
+  push:
+    branches: [ main ]
+  pull_request:
 
 jobs:
   lint:
diff --git a/chat.go b/chat.go
index 40e44d3..7694020 100644
--- a/chat.go
+++ b/chat.go
@@ -74,11 +74,22 @@ type GetChannelEmotesResponse struct {
 	Data ManyEmotes
 }
 
+// GetEmoteSetsResponse ...
+type GetEmoteSetsResponse struct {
+	ResponseCommon
+	Data ManyEmotesWithOwner
+}
+
 // ManyEmotes ...
 type ManyEmotes struct {
 	Emotes []Emote `json:"data"`
 }
 
+// EmoteSets ...
+type ManyEmotesWithOwner struct {
+	Emotes []EmoteWithOwner `json:"data"`
+}
+
 // Emote ...
 type Emote struct {
 	ID     string     `json:"id"`
@@ -89,6 +100,12 @@ type Emote struct {
 	Set_ID string     `json:"emote_set_id"`
 }
 
+// EmoteWithOwner ...
+type EmoteWithOwner struct {
+	Emote
+	OwnerID string `json:"owner_id"`
+}
+
 // EmoteImage ...
 type EmoteImage struct {
 	Url1x string `json:"url_1x"`
@@ -125,15 +142,15 @@ func (c *Client) GetGlobalEmotes() (*GetChannelEmotesResponse, error) {
 }
 
 // GetEmoteSets
-func (c *Client) GetEmoteSets(params *GetEmoteSetsParams) (*GetChannelEmotesResponse, error) {
-	resp, err := c.get("/chat/emotes/set", &ManyEmotes{}, params)
+func (c *Client) GetEmoteSets(params *GetEmoteSetsParams) (*GetEmoteSetsResponse, error) {
+	resp, err := c.get("/chat/emotes/set", &ManyEmotesWithOwner{}, params)
 	if err != nil {
 		return nil, err
 	}
 
-	emotes := &GetChannelEmotesResponse{}
+	emotes := &GetEmoteSetsResponse{}
 	resp.HydrateResponseCommon(&emotes.ResponseCommon)
-	emotes.Data.Emotes = resp.Data.(*ManyEmotes).Emotes
+	emotes.Data.Emotes = resp.Data.(*ManyEmotesWithOwner).Emotes
 
 	return emotes, nil
 }


Test patch:
diff --git a/chat_test.go b/chat_test.go
index dfc5a66..e138198 100644
--- a/chat_test.go
+++ b/chat_test.go
@@ -302,19 +302,37 @@ func TestGetEmoteSets(t *testing.T) {
 		statusCode         int
 		options            *Options
 		GetEmoteSetsParams *GetEmoteSetsParams
+		expectedEmotes     []EmoteWithOwner
 		respBody           string
 	}{
 		{
 			http.StatusBadRequest,
 			&Options{ClientID: "my-client-id"},
 			&GetEmoteSetsParams{EmoteSetIDs: nil},
+			nil,
 			`{"error":"Bad Request","status":400,"message":"The parameter \"emote_set_id\" was malformed: the value must be greater than or equal to 1"}`,
 		},
 		{
 			http.StatusOK,
 			&Options{ClientID: "my-client-id"},
 			&GetEmoteSetsParams{EmoteSetIDs: []string{"300678379"}},
-			`{"data":[{"id":"301147694","name":"sixone3SixDab","images":{"url_1x":"https://static-cdn.jtvnw.net/emoticons/v1/301147694/1.0","url_2x":"https://static-cdn.jtvnw.net/emoticons/v1/301147694/2.0","url_4x":"https://static-cdn.jtvnw.net/emoticons/v1//3.0"},"emote_type":"subscriptions","emote_set_id":"300678379","owner_id":"44931651"}]}`,
+			[]EmoteWithOwner{
+				{
+					Emote: Emote{
+						ID:   "301147694",
+						Name: "sixone3SixDab",
+						Images: EmoteImage{
+							Url1x: "https://static-cdn.jtvnw.net/emoticons/v1/301147694/1.0",
+							Url2x: "https://static-cdn.jtvnw.net/emoticons/v1/301147694/2.0",
+							Url4x: "https://static-cdn.jtvnw.net/emoticons/v1/301147694/3.0",
+						},
+						Type:   "subscriptions",
+						Set_ID: "300678379",
+					},
+					OwnerID: "44931651",
+				},
+			},
+			`{"data":[{"id":"301147694","name":"sixone3SixDab","images":{"url_1x":"https://static-cdn.jtvnw.net/emoticons/v1/301147694/1.0","url_2x":"https://static-cdn.jtvnw.net/emoticons/v1/301147694/2.0","url_4x":"https://static-cdn.jtvnw.net/emoticons/v1/301147694/3.0"},"emote_type":"subscriptions","emote_set_id":"300678379","owner_id":"44931651"}]}`,
 		},
 	}
 
@@ -346,6 +364,17 @@ func TestGetEmoteSets(t *testing.T) {
 
 			continue
 		}
+
+		if len(resp.Data.Emotes) != len(testCase.expectedEmotes) {
+			t.Errorf("returned emotes were different lengths")
+		} else {
+			for i, expectedEmote := range testCase.expectedEmotes {
+				actualEmote := resp.Data.Emotes[i]
+				if expectedEmote != actualEmote {
+					t.Errorf("mismatching emotes %#v != %#v", expectedEmote, actualEmote)
+				}
+			}
+		}
 	}
 
 	// Test with HTTP Failure