Skip to content

Commit

Permalink
twitch: add tests for Get Users
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrtronium committed Aug 9, 2024
1 parent a6bff33 commit 73ac6b8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
17 changes: 17 additions & 0 deletions twitch/testdata/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"data": [
{
"id": "141981764",
"login": "twitchdev",
"display_name": "TwitchDev",
"type": "",
"broadcaster_type": "partner",
"description": "Supporting third-party developers building Twitch integrations from chatbots to game integrations.",
"profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/8a6381c7-d0c0-4576-b179-38bd5ce1d6af-profile_image-300x300.png",
"offline_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/3f13ab61-ec78-4fe6-8481-8682cb3b0ac2-channel_offline_image-1920x1080.png",
"view_count": 5980557,
"email": "[email protected]",
"created_at": "2016-12-14T20:32:28Z"
}
]
}
52 changes: 52 additions & 0 deletions twitch/user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package twitch

import (
"context"
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
"golang.org/x/oauth2"
)

func TestUsers(t *testing.T) {
t.Run("decode", func(t *testing.T) {
spy := apiresp(200, "users.json")
cl := Client{
HTTP: &http.Client{
Transport: spy,
},
Token: &oauth2.Token{
AccessToken: "bocchi",
},
}
u := []User{
{ID: "141981764"},
{Login: "twitchdev"},
}
u, err := Users(context.Background(), cl, u)
if err != nil {
t.Error(err)
}
if len(u) != 1 {
t.Fatalf("wrong number of results: want 1, got %d", len(u))
}
want := User{
ID: "141981764",
Login: "twitchdev",
DisplayName: "TwitchDev",
Type: "",
BroadcasterType: "partner",
Description: "Supporting third-party developers building Twitch integrations from chatbots to game integrations.",
ProfileImageURL: "https://static-cdn.jtvnw.net/jtv_user_pictures/8a6381c7-d0c0-4576-b179-38bd5ce1d6af-profile_image-300x300.png",
OfflineImageURL: "https://static-cdn.jtvnw.net/jtv_user_pictures/3f13ab61-ec78-4fe6-8481-8682cb3b0ac2-channel_offline_image-1920x1080.png",
ViewCount: 5980557,
Email: "[email protected]",
CreatedAt: "2016-12-14T20:32:28Z",
}
got := u[0]
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("wrong result (+got/-want):\n%s", diff)
}
})
}

0 comments on commit 73ac6b8

Please sign in to comment.