Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,6 @@ func (c *Client) UpdateStreamTags(ctx context.Context, tags []string) (EmptyResp
return EmptyResponse{}, nil
}

func (c *Client) UpdateCustomTags(ctx context.Context, tags []string) (EmptyResponse, error) {
type patchBodyRequest struct {
CustomTags []string `json:"custom_tags"`
}

body, err := json.Marshal(patchBodyRequest{CustomTags: tags})
if err != nil {
return EmptyResponse{}, fmt.Errorf("failed to marshal body: %v", err)
}

_, err = makeRequest[EmptyResponse](
ctx,
c,
http.MethodPatch,
"/public/v1/channels",
http.StatusNoContent,
bytes.NewReader(body),
)
if err != nil {
return EmptyResponse{}, err
}

return EmptyResponse{}, nil
}

func (c *Client) GetChannelRewards(ctx context.Context) (ChannelRewardsResponseWrapper, error) {
response, err := makeRequest[[]ChannelRewardResponse](
ctx,
Expand Down
110 changes: 0 additions & 110 deletions channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,116 +392,6 @@ func TestUpdateStreamTagsSuccess(t *testing.T) {
require.NoError(t, err)
}

func TestUpdateCustomTagsError(t *testing.T) {
t.Run("on new request", func(t *testing.T) {
kickClient, err := gokick.NewClient(&gokick.ClientOptions{UserAccessToken: "access-token"})
require.NoError(t, err)

var ctx context.Context
_, err = kickClient.UpdateCustomTags(ctx, []string{"pog", "chad"})
require.EqualError(t, err, "failed to create request: net/http: nil Context")
})

t.Run("timeout", func(t *testing.T) {
kickClient := setupTimeoutMockClient(t)

_, err := kickClient.UpdateCustomTags(context.Background(), []string{"pog", "chad"})
require.EqualError(t, err, `failed to make request: Patch "https://api.kick.com/public/v1/channels": context deadline exceeded `+
`(Client.Timeout exceeded while awaiting headers)`)
})

t.Run("unmarshal error response", func(t *testing.T) {
kickClient := setupMockClient(t, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, `117`)
})

_, err := kickClient.UpdateCustomTags(context.Background(), []string{"pog", "chad"})

assert.EqualError(t, err, `failed to unmarshal error response (KICK status code: 500 and body "117"): json: cannot unmarshal `+
`number into Go value of type gokick.errorResponse`)
})

t.Run("unmarshal token response", func(t *testing.T) {
kickClient := setupMockClient(t, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "117")
})

_, err := kickClient.UpdateCustomTags(context.Background(), []string{"pog", "chad"})

assert.EqualError(t, err, `failed to unmarshal error response (KICK status code: 200 and body "117"): json: cannot unmarshal `+
`number into Go value of type gokick.errorResponse`)
})

t.Run("reader failure", func(t *testing.T) {
kickClient := setupMockClient(t, func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Length", "10")
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, "")
})

_, err := kickClient.UpdateCustomTags(context.Background(), []string{"pog", "chad"})

assert.EqualError(t, err, `failed to read response body (KICK status code 500): unexpected EOF`)
})

t.Run("with internal server error", func(t *testing.T) {
kickClient := setupMockClient(t, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, `{"message":"internal server error", "data":null}`)
})

_, err := kickClient.UpdateCustomTags(context.Background(), []string{"pog", "chad"})

var kickError gokick.Error
require.ErrorAs(t, err, &kickError)
assert.Equal(t, http.StatusInternalServerError, kickError.Code())
assert.Equal(t, "internal server error", kickError.Message())
})
}

func TestUpdateCustomTagsSuccess(t *testing.T) {
t.Run("with tags", func(t *testing.T) {
kickClient := setupMockClient(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPatch, r.Method)
assert.Equal(t, "/public/v1/channels", r.URL.Path)
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
assert.Equal(t, "Bearer access-token", r.Header.Get("Authorization"))

var body map[string]interface{}
err := json.NewDecoder(r.Body).Decode(&body)
assert.NoError(t, err)

customTags, ok := body["custom_tags"].([]interface{})
assert.True(t, ok, "custom_tags should be present in request body")
assert.Equal(t, []interface{}{"pog", "chad"}, customTags)

w.WriteHeader(http.StatusNoContent)
})

_, err := kickClient.UpdateCustomTags(context.Background(), []string{"pog", "chad"})
require.NoError(t, err)
})

t.Run("with empty tags", func(t *testing.T) {
kickClient := setupMockClient(t, func(w http.ResponseWriter, r *http.Request) {
var body map[string]interface{}
err := json.NewDecoder(r.Body).Decode(&body)
assert.NoError(t, err)

customTags, ok := body["custom_tags"].([]interface{})
assert.True(t, ok, "custom_tags should be present in request body")
assert.Empty(t, customTags)

w.WriteHeader(http.StatusNoContent)
})

_, err := kickClient.UpdateCustomTags(context.Background(), []string{})
require.NoError(t, err)
})
}

func TestGetChannelRewardsError(t *testing.T) {
t.Run("on new request", func(t *testing.T) {
kickClient, err := gokick.NewClient(&gokick.ClientOptions{UserAccessToken: "access-token"})
Expand Down