-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2768 from AlaricWhitney/feat--breaking-out-voice-…
…calls-into-a-testable-function feat: breaking out voice calls into a testable function
- Loading branch information
Showing
4 changed files
with
379 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package twilio | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/target/goalert/notification" | ||
) | ||
|
||
func TestSetMsgParams(t *testing.T) { | ||
t.Run("Test Notification", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
err := result.setMsgParams( | ||
notification.Test{ | ||
Dest: notification.Dest{ | ||
ID: "1", | ||
Type: notification.DestTypeVoice, | ||
Value: "+16125551234", | ||
}, | ||
CallbackID: "2", | ||
}, | ||
) | ||
expected := VoiceOptions{ | ||
CallType: "test", | ||
CallbackParams: url.Values{"msgID": []string{"2"}}, | ||
Params: url.Values{"msgSubjectID": []string{"-1"}}, | ||
} | ||
|
||
assert.Equal(t, expected, *result) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("AlertBundle Notification", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
err := result.setMsgParams( | ||
notification.AlertBundle{ | ||
Dest: notification.Dest{ | ||
ID: "1", | ||
Type: notification.DestTypeVoice, | ||
Value: "+16125551234", | ||
}, | ||
CallbackID: "2", | ||
ServiceID: "3", | ||
ServiceName: "Widget", | ||
Count: 5, | ||
}, | ||
) | ||
expected := VoiceOptions{ | ||
CallType: "alert", | ||
CallbackParams: url.Values{"msgID": []string{"2"}}, | ||
Params: url.Values{ | ||
"msgBundle": []string{"1"}, | ||
"msgSubjectID": []string{"-1"}, | ||
}, | ||
} | ||
|
||
assert.Equal(t, expected, *result) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("Alert Notification", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
err := result.setMsgParams( | ||
notification.Alert{ | ||
Dest: notification.Dest{ | ||
ID: "1", | ||
Type: notification.DestTypeVoice, | ||
Value: "+16125551234", | ||
}, | ||
CallbackID: "2", | ||
AlertID: 3, | ||
Summary: "Widget is Broken", | ||
Details: "Oh No!", | ||
}, | ||
) | ||
expected := VoiceOptions{ | ||
CallType: "alert", | ||
CallbackParams: url.Values{"msgID": []string{"2"}}, | ||
Params: url.Values{"msgSubjectID": []string{"3"}}, | ||
} | ||
|
||
assert.Equal(t, expected, *result) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("AlertStatus Notification", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
err := result.setMsgParams( | ||
notification.AlertStatus{ | ||
Dest: notification.Dest{ | ||
ID: "1", | ||
Type: notification.DestTypeVoice, | ||
Value: "+16125551234", | ||
}, | ||
CallbackID: "2", | ||
AlertID: 3, | ||
Summary: "Widget is Broken", | ||
Details: "Oh No!", | ||
LogEntry: "Something is Wrong", | ||
}, | ||
) | ||
expected := VoiceOptions{ | ||
CallType: "alert-status", | ||
CallbackParams: url.Values{"msgID": []string{"2"}}, | ||
Params: url.Values{"msgSubjectID": []string{"3"}}, | ||
} | ||
|
||
assert.Equal(t, expected, *result) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("Verification Notification", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
err := result.setMsgParams( | ||
notification.Verification{ | ||
Dest: notification.Dest{ | ||
ID: "1", | ||
Type: notification.DestTypeVoice, | ||
Value: "+16125551234", | ||
}, | ||
CallbackID: "2", | ||
Code: 1234, | ||
}, | ||
) | ||
expected := VoiceOptions{ | ||
CallType: "verify", | ||
CallbackParams: url.Values{"msgID": []string{"2"}}, | ||
Params: url.Values{"msgSubjectID": []string{"-1"}}, | ||
} | ||
|
||
assert.Equal(t, expected, *result) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("Bad Type", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
err := result.setMsgParams( | ||
notification.ScheduleOnCallUsers{ | ||
Dest: notification.Dest{ | ||
ID: "1", | ||
Type: notification.DestTypeVoice, | ||
Value: "+16125551234", | ||
}, | ||
CallbackID: "2", | ||
ScheduleID: "3", | ||
ScheduleName: "4", | ||
ScheduleURL: "5", | ||
}, | ||
) | ||
expected := VoiceOptions{ | ||
CallbackParams: url.Values{}, | ||
Params: url.Values{}, | ||
} | ||
|
||
assert.Equal(t, expected, *result) | ||
assert.Equal(t, err.Error(), "unhandled message type: notification.ScheduleOnCallUsers") | ||
}) | ||
t.Run("no input", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
err := result.setMsgParams(nil) | ||
expected := VoiceOptions{ | ||
CallbackParams: url.Values{}, | ||
Params: url.Values{}, | ||
} | ||
|
||
assert.Equal(t, expected, *result) | ||
assert.Equal(t, err.Error(), "unhandled message type: <nil>") | ||
}) | ||
} | ||
|
||
func TestSetMsgBody(t *testing.T) { | ||
t.Run("Test Notification", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
result.setMsgBody("This is GoAlert with a test message.") | ||
expected := &VoiceOptions{ | ||
Params: url.Values{"msgBody": []string{b64enc.EncodeToString([]byte("This is GoAlert with a test message."))}}, | ||
} | ||
assert.Equal(t, expected, result) | ||
}) | ||
t.Run("no input", func(t *testing.T) { | ||
result := &VoiceOptions{} | ||
result.setMsgBody("") | ||
expected := &VoiceOptions{ | ||
Params: url.Values{"msgBody": []string{b64enc.EncodeToString([]byte(""))}}, | ||
} | ||
assert.Equal(t, expected, result) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.