Skip to content

Commit 2957aa8

Browse files
authored
Merge branch 'main' into mock-api-jan-23
2 parents 907ff67 + 28810f9 commit 2957aa8

34 files changed

Lines changed: 225 additions & 77 deletions

File tree

cmd/events.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/twitchdev/twitch-cli/internal/events"
1313
"github.com/twitchdev/twitch-cli/internal/events/mock_wss_server"
1414
"github.com/twitchdev/twitch-cli/internal/events/trigger"
15+
"github.com/twitchdev/twitch-cli/internal/events/types"
1516
"github.com/twitchdev/twitch-cli/internal/events/verify"
1617
"github.com/twitchdev/twitch-cli/internal/util"
1718
)
@@ -36,6 +37,7 @@ var (
3637
count int
3738
description string
3839
gameID string
40+
tier string
3941
timestamp string
4042
charityCurrentValue int
4143
charityTargetValue int
@@ -54,9 +56,9 @@ var triggerCmd = &cobra.Command{
5456
Short: "Creates mock events that can be forwarded to a local webserver for event testing.",
5557
Long: fmt.Sprintf(`Creates mock events that can be forwarded to a local webserver for event testing.
5658
Supported:
57-
%s`, events.ValidTriggers()),
59+
%s`, types.AllEventTopics()),
5860
Args: cobra.MaximumNArgs(1),
59-
ValidArgs: events.ValidTriggers(),
61+
ValidArgs: types.AllEventTopics(),
6062
Run: triggerCmdRun,
6163
Example: `twitch event trigger subscribe`,
6264
Aliases: []string{
@@ -69,9 +71,9 @@ var verifyCmd = &cobra.Command{
6971
Short: "Mocks the subscription verification event. Can be forwarded to a local webserver for testing.",
7072
Long: fmt.Sprintf(`Mocks the subscription verification event that can be forwarded to a local webserver for testing.
7173
Supported:
72-
%s`, events.ValidTriggers()),
74+
%s`, types.AllEventTopics()),
7375
Args: cobra.MaximumNArgs(1),
74-
ValidArgs: events.ValidTriggers(),
76+
ValidArgs: types.AllEventTopics(),
7577
Run: verifyCmdRun,
7678
Example: `twitch event verify-subscription subscribe`,
7779
Aliases: []string{
@@ -121,6 +123,7 @@ func init() {
121123
triggerCmd.Flags().Int64VarP(&cost, "cost", "C", 0, "Amount of bits or channel points redeemed/used in the event.")
122124
triggerCmd.Flags().StringVarP(&description, "description", "d", "", "Title the stream should be updated with.")
123125
triggerCmd.Flags().StringVarP(&gameID, "game-id", "G", "", "Sets the game/category ID for applicable events.")
126+
triggerCmd.Flags().StringVarP(&tier, "tier", "", "", "Sets the subscription tier. Valid values are 1000, 2000, and 3000.")
124127
triggerCmd.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") // TODO: This description will need to change with https://github.com/twitchdev/twitch-cli/issues/184
125128
triggerCmd.Flags().StringVar(&timestamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.")
126129
triggerCmd.Flags().IntVar(&charityCurrentValue, "charity-current-value", 0, "Only used for \"charity-*\" events. Manually set the current dollar value for charity events.")
@@ -189,6 +192,7 @@ func triggerCmdRun(cmd *cobra.Command, args []string) {
189192
Description: description,
190193
ItemName: itemName,
191194
GameID: gameID,
195+
Tier: tier,
192196
SubscriptionStatus: subscriptionStatus,
193197
Timestamp: timestamp,
194198
CharityCurrentValue: charityCurrentValue,

docs/event.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Used to either create or send mock events for use with local webhooks testing.
7777
| `--cost` | `-C` | Amount of bits or channel points redeemed/used in the event. | `-C 250` | N |
7878
| `--description` | `-d` | Title the stream should be updated/started with. | `-d Awesome new title!` | N |
7979
| `--game-id` | `-G` | Game ID for Drop or other relevant events. | `-G 1234` | N |
80+
| `--tier` | | Tier of the subscription. | `--tier 3000` | N |
8081

8182

8283
```sh

internal/events/cmd_helpers.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33
package events
44

5-
import "sort"
6-
7-
func ValidTriggers() []string {
8-
names := []string{}
9-
10-
for name, enabled := range triggerSupported {
11-
if enabled == true {
12-
names = append(names, name)
13-
}
14-
}
15-
sort.Strings(names)
16-
17-
return names
18-
}
5+
import (
6+
"sort"
7+
)
198

209
func ValidTransports() []string {
2110
names := []string{}

internal/events/cmd_helpers_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import (
88
"github.com/twitchdev/twitch-cli/test_setup"
99
)
1010

11-
func TestValidTriggers(t *testing.T) {
12-
a := test_setup.SetupTestEnv(t)
13-
14-
t1 := ValidTriggers()
15-
a.NotEmpty(t1)
16-
}
17-
1811
func TestValidTransports(t *testing.T) {
1912
a := test_setup.SetupTestEnv(t)
2013

internal/events/event.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type MockEventParameters struct {
2222
IsPermanent bool
2323
Description string
2424
GameID string
25+
Tier string
2526
Timestamp string
2627
CharityCurrentValue int
2728
CharityTargetValue int
@@ -46,6 +47,9 @@ type MockEvent interface {
4647
// Returns whether a given event supports a supplied transport
4748
ValidTransport(transport string) bool
4849

50+
// Returns
51+
GetAllTopicsByTransport(transport string) []string
52+
4953
// Returns the string of the topic
5054
GetTopic(transport string, trigger string) string
5155

internal/events/models.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33
package events
44

5-
var triggerSupported = map[string]bool{
6-
"add-moderator": true,
7-
"add-redemption": true,
8-
"add-reward": true,
9-
"ban": true,
10-
"charity-donate": true,
11-
"charity-progress": true,
12-
"charity-start": true,
13-
"charity-stop": true,
14-
"cheer": true,
15-
"drop": true,
16-
"follow": true,
17-
"gift": true,
18-
"goal-begin": true,
19-
"goal-end": true,
20-
"goal-progress": true,
21-
"grant": true,
22-
"hype-train-begin": true,
23-
"hype-train-end": true,
24-
"hype-train-progress": true,
25-
"poll-begin": true,
26-
"poll-progress": true,
27-
"poll-end": true,
28-
"prediction-begin": true,
29-
"prediction-progress": true,
30-
"prediction-lock": true,
31-
"prediction-end": true,
32-
"raid": true,
33-
"remove-moderator": true,
34-
"remove-reward": true,
35-
"revoke": true,
36-
"shield-mode-begin": true,
37-
"shield-mode-end": true,
38-
"shoutout-create": true,
39-
"shoutout-received": true,
40-
"stream-change": true,
41-
"streamdown": true,
42-
"streamup": true,
43-
"subscribe": true,
44-
"transaction": true,
45-
"unban": true,
46-
"unsubscribe": true,
47-
"update-redemption": true,
48-
"update-reward": true,
49-
"user-update": true,
50-
}
51-
525
var transportSupported = map[string]bool{
536
"websub": false,
547
"eventsub": true,

internal/events/trigger/trigger_event.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type TriggerParameters struct {
3535
Description string
3636
ItemName string
3737
GameID string
38+
Tier string
3839
Timestamp string
3940
EventID string // Also serves as subscription ID. See https://github.com/twitchdev/twitch-cli/issues/184
4041
CharityCurrentValue int
@@ -66,6 +67,17 @@ func Fire(p TriggerParameters) (string, error) {
6667
p.GameID = fmt.Sprint(util.RandomInt(10 * 1000))
6768
}
6869

70+
switch p.Tier {
71+
case "":
72+
p.Tier = "1000"
73+
case "1000", "2000", "3000":
74+
// do nothing, these are valid values
75+
default:
76+
return "", fmt.Errorf(
77+
`Discarding event: Invalid tier provided.
78+
Valid values are 1000, 2000 or 3000`)
79+
}
80+
6981
if p.EventID == "" {
7082
p.EventID = util.RandomGUID()
7183
}
@@ -98,6 +110,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
98110
Description: p.Description,
99111
ItemName: p.ItemName,
100112
GameID: p.GameID,
113+
Tier: p.Tier,
101114
SubscriptionStatus: p.SubscriptionStatus,
102115
Timestamp: p.Timestamp,
103116
CharityCurrentValue: p.CharityCurrentValue,

internal/events/types/authorization/authorization.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ func (e Event) ValidTrigger(t string) bool {
108108
func (e Event) GetTopic(transport string, trigger string) string {
109109
return triggerMapping[transport][trigger]
110110
}
111+
func (e Event) GetAllTopicsByTransport(transport string) []string {
112+
allTopics := []string{}
113+
for _, topic := range triggerMapping[transport] {
114+
allTopics = append(allTopics, topic)
115+
}
116+
return allTopics
117+
}
111118
func (e Event) GetEventSubAlias(t string) string {
112119
// check for aliases
113120
for trigger, topic := range triggerMapping[models.TransportEventSub] {

internal/events/types/ban/ban.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ func (e Event) ValidTrigger(t string) bool {
131131
func (e Event) GetTopic(transport string, trigger string) string {
132132
return triggerMapping[transport][trigger]
133133
}
134+
func (e Event) GetAllTopicsByTransport(transport string) []string {
135+
allTopics := []string{}
136+
for _, topic := range triggerMapping[transport] {
137+
allTopics = append(allTopics, topic)
138+
}
139+
return allTopics
140+
}
134141
func (e Event) GetEventSubAlias(t string) string {
135142
// check for aliases
136143
for trigger, topic := range triggerMapping[models.TransportEventSub] {

internal/events/types/channel_points_redemption/redemption_event.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ func (e Event) ValidTrigger(t string) bool {
131131
func (e Event) GetTopic(transport string, trigger string) string {
132132
return triggerMapping[transport][trigger]
133133
}
134+
func (e Event) GetAllTopicsByTransport(transport string) []string {
135+
allTopics := []string{}
136+
for _, topic := range triggerMapping[transport] {
137+
allTopics = append(allTopics, topic)
138+
}
139+
return allTopics
140+
}
134141
func (e Event) GetEventSubAlias(t string) string {
135142
// check for aliases
136143
for trigger, topic := range triggerMapping[models.TransportEventSub] {

0 commit comments

Comments
 (0)