Skip to content

Commit

Permalink
few bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lleadbet committed Jul 22, 2023
1 parent 69cbc13 commit 2480f7d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type MockEventParameters struct {
ToUserName string
IsAnonymous bool
IsGift bool
GiftUser string
EventStatus string
SubscriptionStatus string
ItemID string
Expand Down
1 change: 1 addition & 0 deletions internal/events/trigger/trigger_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
CharityCurrentValue: p.CharityCurrentValue,
CharityTargetValue: p.CharityTargetValue,
ClientID: p.ClientID,
GiftUser: p.GiftUser,
}

e, err := types.GetByTriggerAndTransportAndVersion(p.Event, p.Transport, p.Version)
Expand Down
7 changes: 6 additions & 1 deletion internal/events/types/subscribe/sub_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
params.IsGift = true
}

if params.GiftUser != "" {
params.FromUserID = params.GiftUser
params.IsGift = true // make doubly sure it's set to to in cases of "twitch event trigger channel.subscribe -g 1"
}

switch params.Transport {
case models.TransportWebhook, models.TransportWebSocket:
body := *&models.EventsubResponse{
body := &models.EventsubResponse{
Subscription: models.EventsubSubscription{
ID: params.ID,
Status: params.SubscriptionStatus,
Expand Down
29 changes: 27 additions & 2 deletions internal/events/types/subscribe/sub_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var tierTwo = "2000"
func TestEventSub(t *testing.T) {
a := test_setup.SetupTestEnv(t)

params := *&events.MockEventParameters{
params := events.MockEventParameters{
FromUserID: fromUser,
ToUserID: toUser,
Transport: models.TransportWebhook,
Expand All @@ -39,10 +39,35 @@ func TestEventSub(t *testing.T) {
a.Equal(tierTwo, body.Event.Tier, "Expected tier %v, got %v", tierTwo, body.Event.Tier)
}

func TestGiftLogic(t *testing.T) {
a := test_setup.SetupTestEnv(t)

params := events.MockEventParameters{
ToUserID: toUser,
Transport: models.TransportWebhook,
SubscriptionStatus: "enabled",
Trigger: "channel.subscribe",
Tier: tierTwo,
GiftUser: "1",
}

r, err := Event{}.GenerateEvent(params)
a.Nil(err)

var body models.SubEventSubResponse
err = json.Unmarshal(r.JSON, &body)
a.Nil(err)

a.Equal(toUser, body.Event.BroadcasterUserID, "Expected to user %v, got %v", toUser, body.Event.BroadcasterUserID)
a.Equal(tierTwo, body.Event.Tier, "Expected tier %v, got %v", tierTwo, body.Event.Tier)
a.Equal("1", body.Event.UserID, "Expected user ID %v, got %v", "1", body.Event.UserID)
a.Equal(true, body.Event.IsGift, "Expected is_gift to be true")
}

func TestFakeTransport(t *testing.T) {
a := test_setup.SetupTestEnv(t)

params := *&events.MockEventParameters{
params := events.MockEventParameters{
FromUserID: fromUser,
ToUserID: toUser,
Transport: "fake_transport",
Expand Down
7 changes: 6 additions & 1 deletion internal/mock_api/endpoints/drops/entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func getEntitlements(w http.ResponseWriter, r *http.Request) {
Cursor: dbr.Cursor,
}
}

bytes, err := json.Marshal(apiResponse)
w.Write(bytes)
}
Expand Down Expand Up @@ -170,6 +171,10 @@ func patchEntitlements(w http.ResponseWriter, r *http.Request) {
}
}

bytes, _ := json.Marshal(resp)
apiResponse := models.APIResponse{
Data: resp,
}

bytes, _ := json.Marshal(apiResponse)
w.Write(bytes)
}

0 comments on commit 2480f7d

Please sign in to comment.