Skip to content

Commit

Permalink
Merge branch 'main' into feature/m1
Browse files Browse the repository at this point in the history
  • Loading branch information
lleadbet committed Apr 14, 2021
2 parents e80bad7 + df96efa commit b9db1bb
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 19 deletions.
28 changes: 26 additions & 2 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package api
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

Expand All @@ -29,6 +30,19 @@ func TestNewRequest(t *testing.T) {
a.Equal(params.ClientID, r.Header.Get("Client-ID"), "ClientID mismatch")
a.Equal("Bearer "+params.Token, r.Header.Get("Authorization"), "Token mismatch")

if r.URL.Path == "/error" {
w.WriteHeader(http.StatusInternalServerError)
} else if r.URL.Path == "/nocontent" {
w.WriteHeader(http.StatusNoContent)
return
} else if r.URL.Path == "/cursor" {
if strings.Contains(r.URL.RawQuery, "after") {
w.Write([]byte("{}"))
return
}
w.Write([]byte("{\"data\":[],\"pagination\":{\"cursor\":\"test\"}}"))
return
}
w.Write([]byte("{}"))
}))
defer ts.Close()
Expand All @@ -39,8 +53,18 @@ func TestNewRequest(t *testing.T) {
viper.Set("accesstoken", "4567")
viper.Set("refreshtoken", "123")

NewRequest("POST", "", []string{"test=1", "test=2"}, nil, true, false)
NewRequest("POST", "", []string{"test=1", "test=2"}, nil, false, true)
// tests for normal get requests
NewRequest("GET", "", []string{"test=1", "test=2"}, nil, true, false)
NewRequest("GET", "", []string{"test=1", "test=2"}, nil, false, true)

// testing cursors autopagination
NewRequest("GET", "/cursor", []string{"test=1", "test=2"}, nil, false, true)

// testing 204 no-content apis
NewRequest("POST", "/nocontent", []string{"test=1", "test=2"}, nil, false, false)

// testing 500 errors
NewRequest("GET", "/error", []string{"test=1", "test=2"}, nil, false, true)
}

func TestValidOptions(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 1,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.AuthorizationRevokeEvent{
Expand Down
1 change: 1 addition & 0 deletions internal/events/types/ban/ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.BanEventSubEvent{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: tNow,
},
Event: models.RedemptionEventSubEvent{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: tNow,
},
Event: models.RewardEventSubEvent{
Expand Down
1 change: 1 addition & 0 deletions internal/events/types/cheer/cheer_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.CheerEventSubEvent{
Expand Down
1 change: 1 addition & 0 deletions internal/events/types/follow/follow_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (e Event) GenerateEvent(p events.MockEventParameters) (events.MockEventResp
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.FollowEventSubEvent{
Expand Down
1 change: 1 addition & 0 deletions internal/events/types/hype_train/hype_train_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.HypeTrainEventSubEvent{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
ID: params.ID,
Status: "enabled",
Type: triggerMapping[params.Transport][params.Trigger],
Version: "beta",
Version: "1",
Condition: models.EventsubCondition{
BroadcasterUserID: params.ToUserID,
},
Transport: models.EventsubTransport{
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.ModeratorChangeEventSubEvent{
Expand Down
3 changes: 2 additions & 1 deletion internal/events/types/raid/raid.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
ID: params.ID,
Status: "enabled",
Type: triggerMapping[params.Transport][params.Trigger],
Version: "beta",
Version: "1",
Condition: models.EventsubCondition{
ToBroadcasterUserID: params.ToUserID,
},
Transport: models.EventsubTransport{
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.RaidEvent{
Expand Down
1 change: 1 addition & 0 deletions internal/events/types/stream_change/stream_change_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.ChannelUpdateEventSubEvent{
Expand Down
4 changes: 2 additions & 2 deletions internal/events/types/streamdown/streamdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.StreamDownEventSubEvent{
Expand All @@ -62,8 +63,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
}
case models.TransportWebSub:
body := *&models.StreamDownWebSubResponse{
Data: []models.StreamDownWebSubResponseData{
}}
Data: []models.StreamDownWebSubResponseData{}}

event, err = json.Marshal(body)
if err != nil {
Expand Down
27 changes: 14 additions & 13 deletions internal/events/types/streamup/streamup.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.StreamUpEventSubEvent{
Expand All @@ -71,20 +72,20 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
body := models.StreamUpWebSubResponse{
Data: []models.StreamUpWebSubResponseData{
{
ID: params.ID,
UserID: params.ToUserID,
UserLogin: params.ToUserName,
UserName: params.ToUserName,
GameID: "509658",
Type: "live",
Title: params.StreamTitle,
ViewerCount: 1337,
StartedAt: util.GetTimestamp().Format(time.RFC3339),
Language: "en",
ThumbnailURL: "https://static-cdn.jtvnw.net/ttv-static/404_preview-440x248.jpg",
TagIDs: make([]string, 0),
ID: params.ID,
UserID: params.ToUserID,
UserLogin: params.ToUserName,
UserName: params.ToUserName,
GameID: "509658",
Type: "live",
Title: params.StreamTitle,
ViewerCount: 1337,
StartedAt: util.GetTimestamp().Format(time.RFC3339),
Language: "en",
ThumbnailURL: "https://static-cdn.jtvnw.net/ttv-static/404_preview-440x248.jpg",
TagIDs: make([]string, 0),
},
},
},
}

event, err = json.Marshal(body)
Expand Down
1 change: 1 addition & 0 deletions internal/events/types/subscribe/sub_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Method: "webhook",
Callback: "null",
},
Cost: 0,
CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano),
},
Event: models.SubEventSubEvent{
Expand Down
1 change: 1 addition & 0 deletions internal/models/eventsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type EventsubSubscription struct {
Condition EventsubCondition `json:"condition"`
Transport EventsubTransport `json:"transport"`
CreatedAt string `json:"created_at"`
Cost int64 `json:"cost"`
}

type EventsubTransport struct {
Expand Down

0 comments on commit b9db1bb

Please sign in to comment.