Skip to content

Commit 65b3af7

Browse files
authored
Merge pull request #211 from twitchdev/mock-api-jan-23
Updating Mock API to changes as of end of January 2023
2 parents 28810f9 + 2957aa8 commit 65b3af7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3450
-432
lines changed

internal/database/categories.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Category struct {
1111
Name string `db:"category_name" json:"name"`
1212
BoxartURL string `json:"box_art_url"`
1313
ViewerCount int `db:"vc" json:"-"`
14+
IGDB string `db:"igdb_id" json:"igdb_id"`
1415
}
1516

1617
func (q *Query) GetCategories(cat Category) (*DBResponse, error) {
@@ -45,7 +46,7 @@ func (q *Query) GetCategories(cat Category) (*DBResponse, error) {
4546
}
4647

4748
func (q *Query) InsertCategory(category Category, upsert bool) error {
48-
_, err := q.DB.NamedExec(`insert into categories values(:id, :category_name)`, category)
49+
_, err := q.DB.NamedExec(`insert into categories values(:id, :category_name, :igdb_id)`, category)
4950
return err
5051
}
5152

@@ -73,7 +74,7 @@ func (q *Query) SearchCategories(query string) (*DBResponse, error) {
7374
func (q *Query) GetTopGames() (*DBResponse, error) {
7475
r := []Category{}
7576

76-
err := q.DB.Select(&r, "select c.id, c.category_name, IFNULL(SUM(s.viewer_count),0) as vc from categories c left join users u on c.id = u.category_id left join streams s on s.broadcaster_id = u.id group by c.id, c.category_name order by vc desc")
77+
err := q.DB.Select(&r, "select c.id, c.category_name, c.igdb_id, IFNULL(SUM(s.viewer_count),0) as vc from categories c left join users u on c.id = u.category_id left join streams s on s.broadcaster_id = u.id group by c.id, c.category_name order by vc desc"+q.SQL)
7778
if err != nil {
7879
return nil, err
7980
}

internal/database/chat.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package database
4+
5+
type ChatSettings struct {
6+
BroadcasterID string `db:"broadcaster_id" json:"broadcaster_id"`
7+
SlowMode *bool `db:"slow_mode" json:"slow_mode"`
8+
SlowModeWaitTime *int `db:"slow_mode_wait_time" json:"slow_mode_wait_time"`
9+
FollowerMode *bool `db:"follower_mode" json:"follower_mode"`
10+
FollowerModeDuration *int `db:"follower_mode_duration" json:"follower_mode_duration"`
11+
SubscriberMode *bool `db:"subscriber_mode" json:"subscriber_mode"`
12+
EmoteMode *bool `db:"emote_mode" json:"emote_mode"`
13+
UniqueChatMode *bool `db:"unique_chat_mode" json:"unique_chat_mode"`
14+
NonModeratorChatDelay *bool `db:"non_moderator_chat_delay" json:"non_moderator_chat_delay"`
15+
NonModeratorChatDelayDuration *int `db:"non_moderator_chat_delay_duration" json:"non_moderator_chat_delay_duration"`
16+
17+
// Shield mode
18+
ShieldModeIsActive bool `db:"shieldmode_is_active" json:"-"`
19+
ShieldModeModeratorID string `db:"shieldmode_moderator_id" json:"-"`
20+
ShieldModeModeratorLogin string `db:"shieldmode_moderator_login" json:"-"`
21+
ShieldModeModeratorName string `db:"shieldmode_moderator_name" json:"-"`
22+
ShieldModeLastActivated string `db:"shieldmode_last_activated" json:"-"`
23+
}
24+
25+
func (q *Query) GetChatSettingsByBroadcaster(broadcaster string) (*DBResponse, error) {
26+
var r []ChatSettings
27+
28+
err := q.DB.Select(&r, "SELECT * FROM chat_settings WHERE broadcaster_id = $1", broadcaster)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
dbr := DBResponse{
34+
Data: r,
35+
Limit: q.Limit,
36+
Total: len(r),
37+
}
38+
39+
// No cursor because there should only ever be one result
40+
41+
return &dbr, err
42+
}
43+
44+
func (q *Query) InsertChatSettings(s ChatSettings) error {
45+
stmt := generateInsertSQL("chat_settings", "broadcaster_id", s, true)
46+
_, err := q.DB.NamedExec(stmt, s)
47+
return err
48+
}
49+
50+
func (q *Query) UpdateChatSettings(s ChatSettings) error {
51+
sql := generateUpdateSQL("chat_settings", []string{"broadcaster_id"}, s)
52+
_, err := q.DB.NamedExec(sql, s)
53+
return err
54+
}

internal/database/database_test.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ const TEST_USER_ID = "1"
2323
const TEST_USER_LOGIN = "testing_user1"
2424
const TEST_USER_ID_2 = "2"
2525
const TEST_USER_LOGIN_2 = "second_user"
26+
const TEST_USER_ID_99 = "99"
27+
const TEST_USER_LOGIN_99 = "non_mod_user"
2628
const CATEGORY_ID = "1"
29+
const IGDB_ID = "123"
2730

2831
var db CLIDatabase
2932
var q *Query
@@ -49,7 +52,7 @@ func TestMain(m *testing.M) {
4952
}
5053
q = db.NewQuery(nil, 100)
5154

52-
err = q.InsertCategory(Category{Name: "test", ID: CATEGORY_ID, ViewerCount: 0, BoxartURL: ""}, false)
55+
err = q.InsertCategory(Category{Name: "test", ID: CATEGORY_ID, IGDB: IGDB_ID, ViewerCount: 0, BoxartURL: ""}, false)
5356
log.Print(err)
5457

5558
err = q.InsertUser(User{
@@ -86,6 +89,23 @@ func TestMain(m *testing.M) {
8689
}, false)
8790
log.Print(err)
8891

92+
err = q.InsertUser(User{
93+
ID: TEST_USER_ID_99,
94+
UserLogin: TEST_USER_LOGIN_99,
95+
DisplayName: TEST_USER_LOGIN_99,
96+
Email: "",
97+
BroadcasterType: "partner",
98+
UserType: "testing",
99+
UserDescription: "hi mom",
100+
CreatedAt: util.GetTimestamp().Format(time.RFC3339),
101+
ModifiedAt: util.GetTimestamp().Format(time.RFC3339),
102+
CategoryID: sql.NullString{String: "", Valid: false},
103+
Title: "hello",
104+
Language: "en",
105+
Delay: 0,
106+
}, false)
107+
log.Print(err)
108+
89109
os.Exit(m.Run())
90110
db.DB.Close()
91111
}
@@ -170,7 +190,7 @@ func TestAPI(t *testing.T) {
170190
func TestCategories(t *testing.T) {
171191
a := test_setup.SetupTestEnv(t)
172192

173-
c := Category{Name: "test", ID: CATEGORY_ID}
193+
c := Category{Name: "test", ID: CATEGORY_ID, IGDB: IGDB_ID}
174194
err := q.InsertCategory(c, false)
175195
a.NotNil(err)
176196

@@ -180,6 +200,7 @@ func TestCategories(t *testing.T) {
180200
categories := dbr.Data.([]Category)
181201
a.Len(categories, 1)
182202
a.Equal(c.ID, categories[0].ID)
203+
a.Equal(c.IGDB, categories[0].IGDB)
183204

184205
// search
185206
dbr, err = q.SearchCategories("es")
@@ -213,7 +234,7 @@ func TestUsers(t *testing.T) {
213234
Title: "hello",
214235
Language: "en",
215236
Delay: 0,
216-
}, false)
237+
}, true)
217238
a.Nil(err)
218239

219240
err = q.InsertUser(User{
@@ -230,7 +251,7 @@ func TestUsers(t *testing.T) {
230251
Title: "hello",
231252
Language: "en",
232253
Delay: 0,
233-
}, false)
254+
}, true)
234255
a.Nil(err)
235256

236257
u, err := q.GetUser(User{ID: TEST_USER_ID})
@@ -406,7 +427,7 @@ func TestModeration(t *testing.T) {
406427
moderators := dbr.Data.([]Moderator)
407428
a.GreaterOrEqual(len(moderators), 1)
408429

409-
dbr, err = q.GetModeratorsForBroadcaster(TEST_USER_ID, "2")
430+
dbr, err = q.GetModeratorsForBroadcaster(TEST_USER_ID)
410431
a.Nil(err)
411432
moderators = dbr.Data.([]Moderator)
412433
a.GreaterOrEqual(len(moderators), 1)
@@ -604,7 +625,7 @@ func TestStreams(t *testing.T) {
604625
dbr, err = q.GetStreamTags(TEST_USER_ID)
605626
a.Nil(err)
606627
tags = dbr.Data.([]Tag)
607-
a.GreaterOrEqual(len(tags), 1)
628+
a.GreaterOrEqual(len(tags), 0)
608629

609630
dbr, err = q.GetFollowedStreams(s.UserID)
610631
a.Nil(err)
@@ -624,7 +645,7 @@ func TestStreams(t *testing.T) {
624645
streams = dbr.Data.([]Stream)
625646
a.GreaterOrEqual(len(streams), 1)
626647
stream := streams[0]
627-
a.GreaterOrEqual(len(stream.TagIDs), 1)
648+
a.GreaterOrEqual(len(stream.TagIDs), 0)
628649

629650
err = q.DeleteAllStreamTags(s.UserID)
630651
a.Nil(err)
@@ -771,6 +792,7 @@ func TestVideos(t *testing.T) {
771792
ViewCount: 100,
772793
Duration: 1234.5,
773794
CreatedAt: util.GetTimestamp().Format(time.RFC3339),
795+
VodOffset: int(util.RandomInt(3000)),
774796
}
775797

776798
err = q.InsertClip(c)

internal/database/drops.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ package database
55
import "log"
66

77
type DropsEntitlement struct {
8-
ID string `db:"id" json:"id" dbs:"de.id"`
9-
UserID string `db:"user_id" json:"user_id"`
10-
BenefitID string `db:"benefit_id" json:"benefit_id"`
11-
GameID string `db:"game_id" json:"game_id"`
12-
Timestamp string `db:"timestamp" json:"timestamp"`
13-
Status string `db:"status" json:"fulfillment_status"`
8+
ID string `db:"id" json:"id" dbs:"de.id"`
9+
UserID string `db:"user_id" json:"user_id"`
10+
BenefitID string `db:"benefit_id" json:"benefit_id"`
11+
GameID string `db:"game_id" json:"game_id"`
12+
Timestamp string `db:"timestamp" json:"timestamp"`
13+
Status string `db:"status" json:"fulfillment_status"`
14+
LastUpdated string `db:"last_updated" json:"last_updated"`
1415
}
1516

1617
func (q *Query) GetDropsEntitlements(de DropsEntitlement) (*DBResponse, error) {

0 commit comments

Comments
 (0)