Skip to content

Commit

Permalink
Merge pull request #1186 from nyaruka/optin_trigger_fix
Browse files Browse the repository at this point in the history
Fix optin triggers marshaling with type ticket
  • Loading branch information
rowanseymour authored Sep 18, 2023
2 parents ad5eb23 + 869bad6 commit 7fe22dd
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
21 changes: 20 additions & 1 deletion flows/triggers/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ var assetsJSON = `{
"schemes": ["tel"],
"roles": ["send", "receive"]
}
],
],
"optins": [
{
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
"name": "Joke Of The Day"
}
],
"ticketers": [
{
"uuid": "19dc6346-9623-4fe4-be80-538d493ecdf5",
Expand Down Expand Up @@ -184,6 +190,7 @@ func TestTriggerMarshaling(t *testing.T) {

flow := assets.NewFlowReference("7c37d7e5-6468-4b31-8109-ced2ef8b5ddc", "Registration")
channel := assets.NewChannelReference("3a05eaf5-cb1b-4246-bef1-f277419c83a7", "Nexmo")
jotd := sa.OptIns().Get("248be71d-78e9-4d71-a6c4-9981d369e5cb")
ticketer := sa.Ticketers().Get("19dc6346-9623-4fe4-be80-538d493ecdf5")
weather := sa.Topics().Get("472a7a73-96cb-4736-b567-056d987cc5b4")
user := sa.Users().Get("[email protected]")
Expand Down Expand Up @@ -277,6 +284,18 @@ func TestTriggerMarshaling(t *testing.T) {
Build(),
"msg",
},
{
triggers.NewBuilder(env, flow, contact).
OptIn(jotd, triggers.OptInEventTypeStarted).
Build(),
"optin_started",
},
{
triggers.NewBuilder(env, flow, contact).
OptIn(jotd, triggers.OptInEventTypeStopped).
Build(),
"optin_stopped",
},
{
triggers.NewBuilder(env, flow, contact).
Ticket(ticket, triggers.TicketEventTypeClosed).
Expand Down
2 changes: 1 addition & 1 deletion flows/triggers/optin.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type OptInBuilder struct {
func (b *Builder) OptIn(optIn *flows.OptIn, eventType OptInEventType) *OptInBuilder {
return &OptInBuilder{
t: &OptInTrigger{
baseTrigger: newBaseTrigger(TypeTicket, b.environment, b.flow, b.contact, nil, false, nil),
baseTrigger: newBaseTrigger(TypeOptIn, b.environment, b.flow, b.contact, nil, false, nil),
event: &OptInEvent{type_: eventType, optIn: optIn},
},
}
Expand Down
36 changes: 36 additions & 0 deletions flows/triggers/testdata/TestTriggerMarshaling_optin_started.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"type": "optin",
"environment": {
"date_format": "YYYY-MM-DD",
"time_format": "tt:mm",
"timezone": "UTC",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
"uuid": "7c37d7e5-6468-4b31-8109-ced2ef8b5ddc",
"name": "Registration"
},
"contact": {
"uuid": "c00e5d67-c275-4389-aded-7d8b151cbd5b",
"name": "Bob",
"language": "eng",
"status": "active",
"created_on": "2018-10-20T09:49:31.23456789Z",
"urns": [
"tel:+12065551212"
]
},
"triggered_on": "2018-10-20T09:49:31.23456789Z",
"event": {
"type": "started",
"optin": {
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
"name": "Joke Of The Day"
}
}
}
36 changes: 36 additions & 0 deletions flows/triggers/testdata/TestTriggerMarshaling_optin_stopped.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"type": "optin",
"environment": {
"date_format": "YYYY-MM-DD",
"time_format": "tt:mm",
"timezone": "UTC",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
"uuid": "7c37d7e5-6468-4b31-8109-ced2ef8b5ddc",
"name": "Registration"
},
"contact": {
"uuid": "c00e5d67-c275-4389-aded-7d8b151cbd5b",
"name": "Bob",
"language": "eng",
"status": "active",
"created_on": "2018-10-20T09:49:31.23456789Z",
"urns": [
"tel:+12065551212"
]
},
"triggered_on": "2018-10-20T09:49:31.23456789Z",
"event": {
"type": "stopped",
"optin": {
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
"name": "Joke Of The Day"
}
}
}

0 comments on commit 7fe22dd

Please sign in to comment.