diff --git a/docs/event.md b/docs/event.md index 7dbe1eda..47510b13 100644 --- a/docs/event.md +++ b/docs/event.md @@ -16,28 +16,25 @@ Used to either create or send mock events for use with local webhooks testing. **Args** -| Argument | Description | -| ---------------------- | ---------------------------------------------------------------------------------------------------------- | -| `subscribe` | A standard subscription event. Triggers a basic tier 1 sub. | -| `unsubscribe` | A standard unsubscribe event. Triggers a basic tier 1 sub. | -| `gift` | A gifted subscription event. Triggers a basic tier 1 sub. | -| `cheer` | Only usable with the `eventsub` transport, shows Cheers from chat. | -| `transaction` | Bits in Extensions transactions events. | -| `add-reward` | Channel Points EventSub event for a Custom Reward being added. | -| `update-reward` | Channel Points EventSub event for a Custom Reward being updated. | -| `remove-reward` | Channel Points EventSub event for a Custom Reward being removed. | -| `add-redemption` | Channel Points EventSub event for a redemption being performed. | -| `update-redemption` | Channel Points EventSub event for a redemption being updated. | -| `raid` | Channel Raid event with a random viewer count. | -| `revoke` | User authorization revoke event. Uses local Client as set in `twitch configure` or generates one randomly. | -| `stream-change` | Stream Changed event. | -| `streamup` | Only usable with the `eventsub` transport, a stream online event. | -| `streamdown` | Only usable with the `eventsub` transport, a stream offline event. | -| `add-moderator` | Channel moderator add event. | -| `remove-moderator` | Channel moderator removal event. | -| `hype-train-begin` | Hype Train begins event. | -| `hype-train-progress` | Hype Train progress event. | -| `hype-train-end` | Hype Train ends event. | +| Argument | Description | +| ------------------- | ---------------------------------------------------------------------------------------------------------- | +| `subscribe` | A standard subscription event. Triggers a basic tier 1 sub. | +| `unsubscribe` | A standard unsubscribe event. Triggers a basic tier 1 sub. | +| `gift` | A gifted subscription event. Triggers a basic tier 1 sub. | +| `cheer` | Only usable with the `eventsub` transport, shows Cheers from chat. | +| `transaction` | Bits in Extensions transactions events. | +| `add-reward` | Channel Points EventSub event for a Custom Reward being added. | +| `update-reward` | Channel Points EventSub event for a Custom Reward being updated. | +| `remove-reward` | Channel Points EventSub event for a Custom Reward being removed. | +| `add-redemption` | Channel Points EventSub event for a redemption being performed. | +| `update-redemption` | Channel Points EventSub event for a redemption being updated. | +| `raid` | Channel Raid event with a random viewer count. | +| `revoke` | User authorization revoke event. Uses local Client as set in `twitch configure` or generates one randomly. | +| `stream-change` | Stream Changed event. | +| `streamup` | Only usable with the `eventsub` transport, a stream online event. | +| `streamdown` | Only usable with the `eventsub` transport, a stream offline event. | +| `add-moderator` | Channel moderator add event. | +| `remove-moderator` | Channel moderator removal event. | **Flags** @@ -105,27 +102,24 @@ Allows you to test if your webserver responds to subscription requests properly. **Args** | Argument | Description | -| ---------------------- | ---------------------------------------------------------------------------------------------------------- | -| `subscribe` | A standard subscription event. Triggers a basic tier 1 sub. | -| `unsubscribe` | A standard unsubscribe event. Triggers a basic tier 1 sub. | -| `gift` | A gifted subscription event. Triggers a basic tier 1 sub. | -| `cheer` | Only usable with the `eventsub` transport, shows Cheers from chat. | -| `transaction` | Bits in Extensions transactions events. | -| `add-reward` | Channel Points EventSub event for a Custom Reward being added. | -| `update-reward` | Channel Points EventSub event for a Custom Reward being updated. | -| `remove-reward` | Channel Points EventSub event for a Custom Reward being removed. | -| `add-redemption` | Channel Points EventSub event for a redemption being performed. | -| `update-redemption` | Channel Points EventSub event for a redemption being updated. | -| `raid` | Channel Raid event with a random viewer count. | -| `revoke` | User authorization revoke event. Uses local Client as set in `twitch configure` or generates one randomly. | -| `stream_change` | Stream changed event. | -| `streamup` | Only usable with the `eventsub` transport, a stream online event. | -| `streamdown` | Only usable with the `eventsub` transport, a stream offline event. | -| `add-moderator` | Channel moderator add event. | -| `remove-moderator` | Channel moderator removal event. | -| `hype-train-begin` | Hype Train begins event. | -| `hype-train-progress` | Hype Train progress event. | -| `hype-train-end` | Hype Train ends event. | +| ------------------- | ---------------------------------------------------------------------------------------------------------- | +| `subscribe` | A standard subscription event. Triggers a basic tier 1 sub. | +| `unsubscribe` | A standard unsubscribe event. Triggers a basic tier 1 sub. | +| `gift` | A gifted subscription event. Triggers a basic tier 1 sub. | +| `cheer` | Only usable with the `eventsub` transport, shows Cheers from chat. | +| `transaction` | Bits in Extensions transactions events. | +| `add-reward` | Channel Points EventSub event for a Custom Reward being added. | +| `update-reward` | Channel Points EventSub event for a Custom Reward being updated. | +| `remove-reward` | Channel Points EventSub event for a Custom Reward being removed. | +| `add-redemption` | Channel Points EventSub event for a redemption being performed. | +| `update-redemption` | Channel Points EventSub event for a redemption being updated. | +| `raid` | Channel Raid event with a random viewer count. | +| `revoke` | User authorization revoke event. Uses local Client as set in `twitch configure` or generates one randomly. | +| `stream_change` | Stream changed event. | +| `streamup` | Only usable with the `eventsub` transport, a stream online event. | +| `streamdown` | Only usable with the `eventsub` transport, a stream offline event. | +| `add-moderator` | Channel moderator add event. | +| `remove-moderator` | Channel moderator removal event. | **Flags** diff --git a/internal/events/models.go b/internal/events/models.go index 7da6b9f5..a4f9afc9 100644 --- a/internal/events/models.go +++ b/internal/events/models.go @@ -3,22 +3,19 @@ package events var triggerSupported = map[string]bool{ - "subscribe": true, - "unsubscribe": true, - "gift": true, - "cheer": true, - "transaction": true, - "follow": true, - "add-redemption": true, - "update-redemption": true, - "add-reward": true, - "update-reward": true, - "remove-reward": true, - "add-moderator": true, - "remove-moderator": true, - "hype-train-begin": true, - "hype-train-progress": true, - "hype-train-end": true, + "subscribe": true, + "unsubscribe": true, + "gift": true, + "cheer": true, + "transaction": true, + "follow": true, + "add-redemption": true, + "update-redemption": true, + "add-reward": true, + "update-reward": true, + "remove-reward": true, + "add-moderator": true, + "remove-moderator": true, } var transportSupported = map[string]bool{ diff --git a/internal/events/types/hype_train_begin/hype_train_begin_event.go b/internal/events/types/hype_train_begin/hype_train_begin_event.go deleted file mode 100644 index 246c2268..00000000 --- a/internal/events/types/hype_train_begin/hype_train_begin_event.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -package hype_train_begin - -import( - "encoding/json" - "time" - - "github.com/twitchdev/twitch-cli/internal/events" - "github.com/twitchdev/twitch-cli/internal/models" - "github.com/twitchdev/twitch-cli/internal/util" -) - -var transportsSupported = map[string]bool{ - models.TransportWebSub: false, - models.TransportEventSub: true, -} - -var triggerSupported = []string{"hype-train-begin"} - -var triggerMapping = map[string]map[string]string{ - models.TransportEventSub: { - "hype-train-begin": "channel.hype_train.begin", - }, -} - -type Event struct{} - -func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEventResponse, error) { - var event []byte - var err error - - //Some values - StartedAtTime := util.GetTimestamp() - localTotal := util.RandomViewerCount() - localGoal := util.RandomViewerCount() - localProgress := (localTotal/localGoal) - localRandomUser1 := util.RandomUserID() - localRandomUser2 := util.RandomUserID() - localRandomUser3 := util.RandomUserID() - localLC := models.ContributionData{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser1, UserNameWhoMadeContribution: localRandomUser1, UserLoginWhoMadeContribution: localRandomUser1} - localTC := []models.ContributionData{{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser2, UserNameWhoMadeContribution: localRandomUser2, UserLoginWhoMadeContribution: localRandomUser2},{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser3, UserNameWhoMadeContribution: localRandomUser3, UserLoginWhoMadeContribution: localRandomUser3}} - ExpiresAtTime := util.GetTimestamp() - - switch params.Transport { - case models.TransportEventSub: - body := *&models.EventsubResponse{ - Subscription: models.EventsubSubscription{ - ID: params.ID, - Status: "enabled", - Type: triggerMapping[params.Transport][params.Trigger], - Version: "1.0", - Condition: models.EventsubCondition{ - BroadcasterUserID: params.ToUserID, - }, - Transport: models.EventsubTransport{ - Method: "webhook", - Callback: "null", - }, - CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano), - }, - Event: models.HypeTrainEventBeginSubEvent{ - BroadcasterUserID: params.ToUserID, - BroadcasterUserLogin: params.ToUserName, - BroadcasterUserName: params.ToUserName, - Total: localTotal, - Progress: localProgress, - Goal: localGoal, - TopContributions: localTC, - LastContribution: localLC, - StartedAtTimestamp: StartedAtTime.String(), - ExpiresAtTimestamp: ExpiresAtTime.String(), - }, - } - - event, err = json.Marshal(body) - if err != nil { - return events.MockEventResponse{}, err - } - - default: - return events.MockEventResponse{}, nil - } - - return events.MockEventResponse{ - ID: params.ID, - JSON: event, - FromUser: params.FromUserID, - ToUser: params.ToUserID, - }, nil -} - -func (e Event) ValidTransport(t string) bool { - return transportsSupported[t] -} - -func (e Event) ValidTrigger(t string) bool { - for _, ts := range triggerSupported { - if ts == t { - return true - } - } - return false -} -func (e Event) GetTopic(transport string, trigger string) string { - return triggerMapping[transport][trigger] -} \ No newline at end of file diff --git a/internal/events/types/hype_train_begin/hype_train_begin_event_test.go b/internal/events/types/hype_train_begin/hype_train_begin_event_test.go deleted file mode 100644 index 17e10163..00000000 --- a/internal/events/types/hype_train_begin/hype_train_begin_event_test.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -package hype_train_begin - -import ( - "encoding/json" - "testing" - - "github.com/twitchdev/twitch-cli/internal/events" - "github.com/twitchdev/twitch-cli/internal/models" - "github.com/twitchdev/twitch-cli/internal/util" -) - - -var toUser = "4567" - -func TestEventSub(t *testing.T) { - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: models.TransportEventSub, - Trigger: "hype-train-begin", - } - - r, err := Event{}.GenerateEvent(params) - a.Nil(err) - - var body models.HypeTrainEventBeginSubResponse - err = json.Unmarshal(r.JSON, &body) - a.Nil(err) - - a.Equal("channel.hype_train.begin", body.Subscription.Type, "Expected event type %v, got %v", "channel.hype_train.begin", body.Subscription.Type) - a.Equal(toUser, body.Event.BroadcasterUserID, "Expected to user %v, got %v", toUser, body.Event.BroadcasterUserID) - -} - -func TestWebSub(t *testing.T) { - - // Hype_Train_begin does not have a websub part - // Remove? - - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: models.TransportWebSub, - Trigger: "hype-train-begin", - } - - _, err := Event{}.GenerateEvent(params) - a.NotNil(err) - - -} -func TestFakeTransport(t *testing.T) { - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: "fake_transport", - Trigger: "hype-train-begin", - } - - r, err := Event{}.GenerateEvent(params) - a.Nil(err) - a.Empty(r) -} -func TestValidTrigger(t *testing.T) { - a := util.SetupTestEnv(t) - - r := Event{}.ValidTrigger("hype-train-begin") - a.Equal(true, r) -} - -func TestValidTransport(t *testing.T) { - a := util.SetupTestEnv(t) - - r := Event{}.ValidTransport(models.TransportWebSub) - a.Equal(false, r) - - r = Event{}.ValidTransport(models.TransportEventSub) - a.Equal(true, r) -} - -func TestGetTopic(t *testing.T) { - a := util.SetupTestEnv(t) -} diff --git a/internal/events/types/hype_train_end/hype_train_end_event.go b/internal/events/types/hype_train_end/hype_train_end_event.go deleted file mode 100644 index d62c66a3..00000000 --- a/internal/events/types/hype_train_end/hype_train_end_event.go +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -package hype_train_end - -import( - "encoding/json" - "time" - - "github.com/twitchdev/twitch-cli/internal/events" - "github.com/twitchdev/twitch-cli/internal/models" - "github.com/twitchdev/twitch-cli/internal/util" -) - -var transportsSupported = map[string]bool{ - models.TransportWebSub: false, - models.TransportEventSub: true, -} - -var triggerSupported = []string{"hype-train-end"} - -var triggerMapping = map[string]map[string]string{ - models.TransportEventSub: { - "hype-train-end": "channel.hype_train.end", - }, -} - -type Event struct{} - -func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEventResponse, error) { - var event []byte - var err error - - //Some values - StartedAtTime := util.GetTimestamp() - localTotal := util.RandomViewerCount() - localLevel := util.RandomViewerCount()%4 - localRandomUser2 := util.RandomUserID() - localRandomUser3 := util.RandomUserID() - localTC := []models.ContributionData{{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser2, UserNameWhoMadeContribution: localRandomUser2, UserLoginWhoMadeContribution: localRandomUser2},{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser3, UserNameWhoMadeContribution: localRandomUser3, UserLoginWhoMadeContribution: localRandomUser3}} - EndedAtTime := util.GetTimestamp() - CooldownAtTime := util.GetTimestamp() - - switch params.Transport { - case models.TransportEventSub: - body := *&models.EventsubResponse{ - Subscription: models.EventsubSubscription{ - ID: params.ID, - Status: "enabled", - Type: triggerMapping[params.Transport][params.Trigger], - Version: "1.0", - Condition: models.EventsubCondition{ - BroadcasterUserID: params.ToUserID, - }, - Transport: models.EventsubTransport{ - Method: "webhook", - Callback: "null", - }, - CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano), - }, - Event: models.HypeTrainEventEndSubEvent{ - BroadcasterUserID: params.ToUserID, - BroadcasterUserLogin: params.ToUserName, - BroadcasterUserName: params.ToUserName, - Level: localLevel, - Total: localTotal, - TopContributions: localTC, - StartedAtTimestamp: StartedAtTime.String(), - EndedAtTimestamp: EndedAtTime.String(), - CooldownEndsAtTimestamp: CooldownAtTime.String(), - }, - } - - event, err = json.Marshal(body) - if err != nil { - return events.MockEventResponse{}, err - } - default: - return events.MockEventResponse{}, nil - } - - return events.MockEventResponse{ - ID: params.ID, - JSON: event, - FromUser: params.FromUserID, - ToUser: params.ToUserID, - }, nil -} - -func (e Event) ValidTransport(t string) bool { - return transportsSupported[t] -} - -func (e Event) ValidTrigger(t string) bool { - for _, ts := range triggerSupported { - if ts == t { - return true - } - } - return false -} -func (e Event) GetTopic(transport string, trigger string) string { - return triggerMapping[transport][trigger] -} \ No newline at end of file diff --git a/internal/events/types/hype_train_end/hype_train_end_event_test.go b/internal/events/types/hype_train_end/hype_train_end_event_test.go deleted file mode 100644 index d9eefc95..00000000 --- a/internal/events/types/hype_train_end/hype_train_end_event_test.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -package hype_train_end - -import ( - "encoding/json" - "testing" - - "github.com/twitchdev/twitch-cli/internal/events" - "github.com/twitchdev/twitch-cli/internal/models" - "github.com/twitchdev/twitch-cli/internal/util" -) - - -var toUser = "4567" - -func TestEventSub(t *testing.T) { - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: models.TransportEventSub, - Trigger: "hype-train-end", - } - - r, err := Event{}.GenerateEvent(params) - a.Nil(err) - - var body models.HypeTrainEventEndSubResponse - err = json.Unmarshal(r.JSON, &body) - a.Nil(err) - - a.Equal("channel.hype_train.end", body.Subscription.Type, "Expected event type %v, got %v", "channel.hype_train.end", body.Subscription.Type) - a.Equal(toUser, body.Event.BroadcasterUserID, "Expected to user %v, got %v", toUser, body.Event.BroadcasterUserID) - -} - -func TestWebSub(t *testing.T) { - - // Hype_Train_begin does not have a websub part - // Remove? - - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: models.TransportWebSub, - Trigger: "hype-train-end", - } - - _, err := Event{}.GenerateEvent(params) - a.NotNil(err) - - -} -func TestFakeTransport(t *testing.T) { - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: "fake_transport", - Trigger: "hype-train-end", - } - - r, err := Event{}.GenerateEvent(params) - a.Nil(err) - a.Empty(r) -} -func TestValidTrigger(t *testing.T) { - a := util.SetupTestEnv(t) - - r := Event{}.ValidTrigger("hype-train-end") - a.Equal(true, r) -} - -func TestValidTransport(t *testing.T) { - a := util.SetupTestEnv(t) - - r := Event{}.ValidTransport(models.TransportWebSub) - a.Equal(false, r) - - r = Event{}.ValidTransport(models.TransportEventSub) - a.Equal(true, r) -} - -func TestGetTopic(t *testing.T) { - a := util.SetupTestEnv(t) -} diff --git a/internal/events/types/hype_train_progress/hype_train_progress_event.go b/internal/events/types/hype_train_progress/hype_train_progress_event.go deleted file mode 100644 index 924818c9..00000000 --- a/internal/events/types/hype_train_progress/hype_train_progress_event.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -package hype_train_progress - -import( - "encoding/json" - "time" - - "github.com/twitchdev/twitch-cli/internal/events" - "github.com/twitchdev/twitch-cli/internal/models" - "github.com/twitchdev/twitch-cli/internal/util" -) - -var transportsSupported = map[string]bool{ - models.TransportWebSub: true, - models.TransportEventSub: true, -} - -var triggerSupported = []string{"hype-train-begin", "hype-train-progress", "hype-train-end"} - -var triggerMapping = map[string]map[string]string{ - models.TransportWebSub: { - "hype-train-progress": "hypetrain.progression", - }, - models.TransportEventSub: { - "hype-train-progress": "channel.hype_train.progress", - }, -} - -type Event struct{} - -func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEventResponse, error) { - var event []byte - var err error - - //Some values - StartedAtTime := util.GetTimestamp() - localTotal := util.RandomViewerCount() - localLevel := util.RandomViewerCount()%4 - localGoal := util.RandomViewerCount() - localProgress := (localTotal/localGoal) - localRandomUser1 := util.RandomUserID() - localRandomUser2 := util.RandomUserID() - localRandomUser3 := util.RandomUserID() - localLC := models.ContributionData{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser1, UserNameWhoMadeContribution: localRandomUser1, UserLoginWhoMadeContribution: localRandomUser1} - localTC := []models.ContributionData{{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser2, UserNameWhoMadeContribution: localRandomUser2, UserLoginWhoMadeContribution: localRandomUser2},{TotalContribution: util.RandomViewerCount(), TypeOfContribution: util.RandomType(), UserWhoMadeContribution: localRandomUser3, UserNameWhoMadeContribution: localRandomUser3, UserLoginWhoMadeContribution: localRandomUser3}} - ExpiresAtTime := util.GetTimestamp() - CooldownAtTime := util.GetTimestamp() - - switch params.Transport { - case models.TransportEventSub: - body := *&models.EventsubResponse{ - Subscription: models.EventsubSubscription{ - ID: params.ID, - Status: "enabled", - Type: triggerMapping[params.Transport][params.Trigger], - Version: "1", - Condition: models.EventsubCondition{ - BroadcasterUserID: params.ToUserID, - }, - Transport: models.EventsubTransport{ - Method: "webhook", - Callback: "null", - }, - CreatedAt: util.GetTimestamp().Format(time.RFC3339Nano), - }, - Event: models.HypeTrainEventProgressSubEvent{ - BroadcasterUserID: params.ToUserID, - BroadcasterUserLogin: params.ToUserName, - BroadcasterUserName: params.ToUserName, - Level: localLevel, - Total: localTotal, - Progress: localProgress, - Goal: localGoal, - TopContributions: localTC, - LastContribution: localLC, - StartedAtTimestamp: StartedAtTime.String(), - ExpiresAtTimestamp: ExpiresAtTime.String(), - }, - } - - event, err = json.Marshal(body) - if err != nil { - return events.MockEventResponse{}, err - } - case models.TransportWebSub: - body := *&models.HypeTrainWebSubResponse{ - Data: []models.HypeTrainWebSubEvent{ - { - ID: params.ID, - EventType: triggerMapping[params.Transport][params.Trigger], - EventTimestamp: util.GetTimestamp().Format(time.RFC3339), - Version: "1.0", - EventData: models.HypeTrainWebsubEventData{ - BroadcasterID: params.ToUserID, - CooldownEndTimestamp: CooldownAtTime.String(), - ExpiresAtTimestamp: ExpiresAtTime.String(), - Goal: localGoal, - Id: util.RandomGUID(), - LastContribution: localLC, - Level: localLevel, - StartedAtTimestamp: StartedAtTime.String(), - TopContributions: localTC, - Total: localTotal, - }, - }, - }, - } - event, err = json.Marshal(body) - if err != nil { - return events.MockEventResponse{}, err - } - - default: - return events.MockEventResponse{}, nil - } - - return events.MockEventResponse{ - ID: params.ID, - JSON: event, - FromUser: params.FromUserID, - ToUser: params.ToUserID, - }, nil -} - -func (e Event) ValidTransport(t string) bool { - return transportsSupported[t] -} - -func (e Event) ValidTrigger(t string) bool { - for _, ts := range triggerSupported { - if ts == t { - return true - } - } - return false -} -func (e Event) GetTopic(transport string, trigger string) string { - return triggerMapping[transport][trigger] -} diff --git a/internal/events/types/hype_train_progress/hype_train_progress_event_test.go b/internal/events/types/hype_train_progress/hype_train_progress_event_test.go deleted file mode 100644 index 878a17e3..00000000 --- a/internal/events/types/hype_train_progress/hype_train_progress_event_test.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -package hype_train_progress - -import ( - "encoding/json" - "testing" - - "github.com/twitchdev/twitch-cli/internal/events" - "github.com/twitchdev/twitch-cli/internal/models" - "github.com/twitchdev/twitch-cli/internal/util" -) - -var toUser = "4567" - -func TestEventSub(t *testing.T) { - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - FromUserID: fromUser, - ToUserID: toUser, - Transport: models.TransportEventSub, - Trigger: "hype-train-progress", - } - - r, err := Event{}.GenerateEvent(params) - a.Nil(err) - - var body models.HypeTrainEventProgressSubResponse - err = json.Unmarshal(r.JSON, &body) - a.Nil(err) - - a.Equal("channel.hype_train.progress", body.Subscription.Type, "Expected event type %v, got %v", "channel.hype_train.progress", body.Subscription.Type) - a.Equal(toUser, body.Event.BroadcasterUserID, "Expected to user %v, got %v", toUser, body.Event.BroadcasterUserID) - -} - -func TestWebSub(t *testing.T) { - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: models.TransportWebSub, - Trigger: "hype-train-progress", - } - - r, err := Event{}.GenerateEvent(params) - a.Nil(err) - - var body models.HypeTrainWebSubResponse - err = json.Unmarshal(r.JSON, &body) - a.Nil(err) - - a.Equal("hypetrain.progression", body.Data[0].EventType, "Expected event type %v, got %v", "hypetrain.progression", body.Data[0].EventType) - a.Equal(toUser, body.Data[0].EventData.BroadcasterID, "Expected to user %v, got %v", toUser, body.Data[0].EventData.BroadcasterID) - - - params = *&events.MockEventParameters{ - ToUserID: toUser, - Transport: models.TransportWebSub, - } -} -func TestFakeTransport(t *testing.T) { - a := util.SetupTestEnv(t) - - params := *&events.MockEventParameters{ - ToUserID: toUser, - Transport: "fake_transport", - Trigger: "hype-train-progress", - } - - r, err := Event{}.GenerateEvent(params) - a.Nil(err) - a.Empty(r) -} -func TestValidTrigger(t *testing.T) { - a := util.SetupTestEnv(t) - - r := Event{}.ValidTrigger("hype-train-progress") - a.Equal(true, r) - -} - -func TestValidTransport(t *testing.T) { - a := util.SetupTestEnv(t) - - r := Event{}.ValidTransport(models.TransportWebSub) - a.Equal(true, r) - - r = Event{}.ValidTransport(models.TransportEventSub) - a.Equal(true, r) -} - -func TestGetTopic(t *testing.T) { - a := util.SetupTestEnv(t) - - r := Event{}.GetTopic(models.TransportWebSub, "hype-train-progress") - a.Equal("hypetrain.progression", r, "Expected %v, got %v", "hypetrain.progression", r) -} diff --git a/internal/events/types/types.go b/internal/events/types/types.go index f416f25f..9b96decd 100644 --- a/internal/events/types/types.go +++ b/internal/events/types/types.go @@ -12,9 +12,6 @@ import ( "github.com/twitchdev/twitch-cli/internal/events/types/cheer" "github.com/twitchdev/twitch-cli/internal/events/types/extension_transaction" "github.com/twitchdev/twitch-cli/internal/events/types/follow" - "github.com/twitchdev/twitch-cli/internal/events/types/hype_train_begin" - "github.com/twitchdev/twitch-cli/internal/events/types/hype_train_end" - "github.com/twitchdev/twitch-cli/internal/events/types/hype_train_progress" "github.com/twitchdev/twitch-cli/internal/events/types/moderator_change" "github.com/twitchdev/twitch-cli/internal/events/types/raid" "github.com/twitchdev/twitch-cli/internal/events/types/stream_change" @@ -37,9 +34,6 @@ func All() []events.MockEvent { streamup.Event{}, streamdown.Event{}, moderator_change.Event{}, - hype_train_begin.Event{}, - hype_train_end.Event{}, - hype_train_progress.Event{}, } } diff --git a/internal/models/hype_train.go b/internal/models/hype_train.go deleted file mode 100644 index 2441559e..00000000 --- a/internal/models/hype_train.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -package models - - -type HypeTrainWebSubEvent struct { - ID string `json:"id"` - EventType string `json:"event_type"` - EventTimestamp string `json:"event_timestamp"` - Version string `json:"version"` - EventData HypeTrainWebsubEventData `json:"event_data"` -} - -type HypeTrainWebsubEventData struct { - BroadcasterID string `json:"broadcaster_id"` - CooldownEndTimestamp string `json:"cooldown_end_time"` - ExpiresAtTimestamp string `json:"expires_at"` - Goal int64 `json:"goal"` - Id string `json:"id"` - LastContribution ContributionData `json:"last_contribution"` - Level int64 `json:"level"` - StartedAtTimestamp string `json:"started_at"` - TopContributions []ContributionData `json:"top_contributions"` - Total int64 `json:"total"` -} - -type ContributionData struct{ - TotalContribution int64 `json:"total"` - TypeOfContribution string `json:"type"` - UserWhoMadeContribution string `json:"user_id"` - UserNameWhoMadeContribution string `json:"user_name"` - UserLoginWhoMadeContribution string `json:"user_login"` -} - -type HypeTrainWebSubResponse struct { - Data []HypeTrainWebSubEvent `json:"data"` -} - -type HypeTrainEventBeginSubResponse struct { - Subscription EventsubSubscription `json:"subscription"` - Event HypeTrainEventBeginSubEvent `json:"event"` -} - -type HypeTrainEventProgressSubResponse struct { - Subscription EventsubSubscription `json:"subscription"` - Event HypeTrainEventProgressSubEvent `json:"event"` -} - -type HypeTrainEventEndSubResponse struct { - Subscription EventsubSubscription `json:"subscription"` - Event HypeTrainEventEndSubEvent `json:"event"` -} - -type HypeTrainEventBeginSubEvent struct { - BroadcasterUserID string `json:"broadcaster_user_id"` - BroadcasterUserLogin string `json:"broadcaster_user_login"` - BroadcasterUserName string `json:"broadcaster_user_name"` - Total int64 `json:"total"` - Progress int64 `json:"progress"` - Goal int64 `json:"goal"` - TopContributions []ContributionData `json:"top_contributions"` - LastContribution ContributionData `json:"last_contribution"` - StartedAtTimestamp string `json:"started_at"` - ExpiresAtTimestamp string `json:"expires_at"` -} - -type HypeTrainEventProgressSubEvent struct { - BroadcasterUserID string `json:"broadcaster_user_id"` - BroadcasterUserLogin string `json:"broadcaster_user_login"` - BroadcasterUserName string `json:"broadcaster_user_name"` - Level int64 `json:"level"` - Total int64 `json:"total"` - Progress int64 `json:"progress"` - Goal int64 `json:"goal"` - TopContributions []ContributionData `json:"top_contributions"` - LastContribution ContributionData `json:"last_contribution"` - StartedAtTimestamp string `json:"started_at"` - ExpiresAtTimestamp string `json:"expires_at"` -} - -type HypeTrainEventEndSubEvent struct { - BroadcasterUserID string `json:"broadcaster_user_id"` - BroadcasterUserLogin string `json:"broadcaster_user_login"` - BroadcasterUserName string `json:"broadcaster_user_name"` - Level int64 `json:"level"` - Total int64 `json:"total"` - TopContributions []ContributionData `json:"top_contributions"` - StartedAtTimestamp string `json:"started_at"` - EndedAtTimestamp string `json:"ended_at"` - CooldownEndsAtTimestamp string `json:"cooldown_ends_at"` -} \ No newline at end of file diff --git a/internal/util/random.go b/internal/util/random.go index 6e454955..6e7ceb15 100644 --- a/internal/util/random.go +++ b/internal/util/random.go @@ -46,17 +46,3 @@ func RandomViewerCount() int64 { } return viewer.Int64() } - -// RandomViewerCount generates a fake viewercount between 0->10,000,000 -func RandomType() string { - someInt, err := rand.Int(rand.Reader, big.NewInt(1*10*100*100*100)) - if err != nil { - log.Fatal(err.Error()) - } - if (someInt.Int64()%2) == 0{ - return "bits" - }else - { - return "subscription" - } -} \ No newline at end of file