Skip to content

Commit 9370e1a

Browse files
authored
Merge pull request #79 from twitchdev/feature/mock-api-fixes-072621
Updating ban events to match production
2 parents 4d7f059 + 2c536f7 commit 9370e1a

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

docs/mock-api.md

+8-13
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ The `mock-api` product has two primary functions. The first is to generate so-ca
2020
* Teams
2121
* Users
2222

23-
The second is the actual server used to mock the endpoints. In the next iteration, you will be able to edit these and add further ones manually (for example, making a user with specific attributes), but for the beta we won't be providing this functionality as the current `generate` feature will make all of these (and more),
23+
The second is the actual server used to mock the endpoints. In the next iteration, you will be able to edit these and add further ones manually (for example, making a user with specific attributes), but for the beta we won't be providing this functionality as the current `generate` feature will make all of these (and more).
2424

25+
As of the 1.1 release, this product is in an **open beta** and any bugs should be filed via GitHub Issues. Given the breadth of the tool, it is likely you may run across oddities; please fill out an issue if that is the case.
2526

2627
## generate
2728

@@ -40,18 +41,12 @@ None.
4041

4142
## start
4243

43-
The `start` function starts a new mock server for use with testing functionality. Currently, this replicates a large majority of the current API endpoints on the new API, but are ommitting:
44-
45-
* GET /analytics/extensions
46-
* GET /analytics/games
47-
* GET /extensions/transactions
48-
* POST /eventsub/subscriptions
49-
* DELETE /eventsub/subscriptions
50-
* GET /eventsub/subscriptions
51-
* GET /users/extensions/list
52-
* GET /users/extensions
53-
* PUT /users/extensions
54-
* GET /webhooks/subscriptions
44+
The `start` function starts a new mock server for use with testing functionality. Currently, this replicates a large majority of the current API endpoints on the new API, but are omitting:
45+
46+
* Extensions endpoints
47+
* Code entitlement endpoints
48+
* Websub endpoints
49+
* EventSub endpoints
5550

5651
For many of these, we are exploring how to better integrate this with existing features (for example, allowing events to be triggered on unit creation or otherwise), and for others, the value is minimal compared to the docs. All other endpoints should be currently supported, however it is possible to be out of date- if so, [please raise an issue](https://github.com/twitchdev/twitch-cli/issues).
5752

internal/database/moderation.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ type ModeratorActionEvent struct {
4040
}
4141

4242
type BanActionEvent struct {
43-
BroadcasterID string `db:"broadcaster_id" json:"broadcaster_id"`
44-
BroadcasterLogin string `db:"broadcaster_login" json:"broadcaster_login"`
45-
BroadcasterName string `db:"broadcaster_name" json:"broadcaster_name"`
46-
UserID string `db:"user_id" json:"user_id"`
47-
UserLogin string `db:"user_login" json:"user_login"`
48-
UserName string `db:"user_name" json:"user_name"`
49-
ExpiresAt *string `db:"expires_at" json:"expires_at"`
43+
BroadcasterID string `db:"broadcaster_id" json:"broadcaster_id"`
44+
BroadcasterLogin string `db:"broadcaster_login" json:"broadcaster_login"`
45+
BroadcasterName string `db:"broadcaster_name" json:"broadcaster_name"`
46+
UserID string `db:"user_id" json:"user_id"`
47+
UserLogin string `db:"user_login" json:"user_login"`
48+
UserName string `db:"user_name" json:"user_name"`
49+
ExpiresAt *string `db:"expires_at" json:"expires_at"`
50+
Reason string `json:"reason"`
51+
ModeratorID string `json:"moderator_id"`
52+
ModeratorUserLogin string `json:"moderator_login"`
53+
ModeratorUserName string `json:"moderator_user_name"`
5054
}
5155

5256
type BanEvent struct {
@@ -57,10 +61,14 @@ type BanEvent struct {
5761
BanActionEvent `json:"event_data"`
5862
}
5963
type Ban struct {
60-
UserID string `db:"user_id" json:"user_id"`
61-
UserLogin string `db:"user_login" json:"user_login"`
62-
UserName string `db:"user_name" json:"user_name"`
63-
ExpiresAt *string `db:"expires_at" json:"expires_at"`
64+
UserID string `db:"user_id" json:"user_id"`
65+
UserLogin string `db:"user_login" json:"user_login"`
66+
UserName string `db:"user_name" json:"user_name"`
67+
ExpiresAt *string `db:"expires_at" json:"expires_at"`
68+
Reason string `json:"reason"`
69+
ModeratorID string `json:"moderator_id"`
70+
ModeratorUserLogin string `json:"moderator_login"`
71+
ModeratorUserName string `json:"moderator_user_name"`
6472
}
6573

6674
var es = ""
@@ -192,6 +200,7 @@ func (q *Query) GetBans(p UserRequestParams) (*DBResponse, error) {
192200
if b.ExpiresAt == nil {
193201
b.ExpiresAt = &es
194202
}
203+
b.Reason = "CLI ban"
195204
r = append(r, b)
196205
}
197206
dbr := DBResponse{
@@ -228,6 +237,7 @@ func (q *Query) GetBanEvents(p UserRequestParams) (*DBResponse, error) {
228237
if b.ExpiresAt == nil {
229238
b.ExpiresAt = &es
230239
}
240+
b.Reason = "CLI ban"
231241
r = append(r, b)
232242
}
233243
dbr := DBResponse{

internal/mock_api/endpoints/moderation/banned.go

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func getBans(w http.ResponseWriter, r *http.Request) {
6161
mock_errors.WriteUnauthorized(w, "broadcaster_id does not match token")
6262
return
6363
}
64+
broadcaster, err := db.NewQuery(r, 100).GetUser(database.User{ID: userCtx.UserID})
65+
if err != nil {
66+
mock_errors.WriteServerError(w, "error fetching broadcaster")
67+
return
68+
}
69+
6470
bans := []database.Ban{}
6571
userIDs := r.URL.Query()["user_id"]
6672
if len(userIDs) > 0 {
@@ -81,6 +87,11 @@ func getBans(w http.ResponseWriter, r *http.Request) {
8187
}
8288
bans = append(bans, dbr.Data.([]database.Ban)...)
8389
}
90+
for i := range bans {
91+
bans[i].ModeratorID = broadcaster.ID
92+
bans[i].ModeratorUserLogin = broadcaster.UserLogin
93+
bans[i].ModeratorUserName = broadcaster.DisplayName
94+
}
8495
apiResponse := models.APIResponse{Data: bans}
8596
if dbr.Cursor != "" {
8697
apiResponse.Pagination = &models.APIPagination{Cursor: dbr.Cursor}

internal/mock_api/endpoints/moderation/banned_events.go

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func getBanEvents(w http.ResponseWriter, r *http.Request) {
6060
mock_errors.WriteUnauthorized(w, "broadcaster_id does not match token")
6161
return
6262
}
63+
64+
broadcaster, err := db.NewQuery(r, 100).GetUser(database.User{ID: userCtx.UserID})
65+
if err != nil {
66+
mock_errors.WriteServerError(w, "error fetching broadcaster")
67+
return
68+
}
69+
6370
bans := []database.BanEvent{}
6471
userIDs := r.URL.Query()["user_id"]
6572
if len(userIDs) > 0 {
@@ -80,6 +87,11 @@ func getBanEvents(w http.ResponseWriter, r *http.Request) {
8087
}
8188
bans = append(bans, dbr.Data.([]database.BanEvent)...)
8289
}
90+
for i := range bans {
91+
bans[i].ModeratorID = broadcaster.ID
92+
bans[i].ModeratorUserLogin = broadcaster.UserLogin
93+
bans[i].ModeratorUserName = broadcaster.DisplayName
94+
}
8395
apiResponse := models.APIResponse{Data: bans}
8496
if dbr.Cursor != "" {
8597
apiResponse.Pagination = &models.APIPagination{Cursor: dbr.Cursor}

0 commit comments

Comments
 (0)