Skip to content

Commit

Permalink
Update Smoke test to support SMS opt-in (#71)
Browse files Browse the repository at this point in the history
* Update Smoke test to support SMS opt-in

* chore: Updated coverage badge.

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
harveysanders and actions-user authored Jul 21, 2023
1 parent df0a592 commit 130ae6c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"go.testEnvFile": "${workspaceFolder}/.env.smoke"
"go.testEnvFile": "${workspaceFolder}/.env.smoke",
"cSpell.words": [
"Emptyf",
"stretchr"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Session Sign Up Service

![Coverage](https://img.shields.io/badge/Coverage-54.7%25-yellow)
![Coverage](https://img.shields.io/badge/Coverage-54.4%25-yellow)

When someone signs up for an Info Session on [operationspark.org](https://operationspark.org),
this service runs a series of tasks:
Expand Down
15 changes: 10 additions & 5 deletions cmd/smoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func makeAuthenticatedReq(method string, url string, body io.Reader) (*http.Requ
return req, err
}

func fetchSMSmessage(toNum, fromNum string) (string, error) {
func fetchLastTextMessages(toNum, fromNum string, n int) ([]string, error) {
accountSID := os.Getenv("TWILIO_ACCOUNT_SID")

client := twilio.NewRestClientWithParams(twilio.ClientParams{
Expand All @@ -161,17 +161,22 @@ func fetchSMSmessage(toNum, fromNum string) (string, error) {
params.SetPathAccountSid(accountSID)
params.SetTo(toNum)
params.SetFrom(fromNum)
params.SetLimit(1)
params.SetLimit(n)

var msgBodies []string

messages, err := client.Api.ListMessage(params)
if err != nil {
return "", fmt.Errorf("fetchMessage: %w", err)
return msgBodies, fmt.Errorf("fetchMessage: %w", err)
}
if len(messages) == 0 {
return "", fmt.Errorf("no messages found sent from %q -> %q", fromNum, toNum)
return msgBodies, fmt.Errorf("no messages found sent from %q -> %q", fromNum, toNum)
}

return *messages[0].Body, nil
for _, m := range messages {
msgBodies = append(msgBodies, *m.Body)
}
return msgBodies, nil
}

// ParseSMSShortLink pulls a "ospk.org" short link out of a string.
Expand Down
27 changes: 19 additions & 8 deletions cmd/smoke/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,29 @@ func TestSmokeSignup(t *testing.T) {
err = s.postSignup(su)
require.NoError(t, err, "POST Signup to Cloud Function")

// Get expected SMS message from Twilio API
sms, err := fetchSMSmessage(s.toNum, s.fromNum)
// TODO: ** Fetch last two messages. As of this commit, Twilio is blocking our opt-in message with error 30034. They will block some number of messages until our A2P 10DLC campaign is approved. In meantime, assume the opt-in confirmation message will be blocked and the last delivered message will be the Info Session confirmation. ***
// Get the last 2 text messages from Twilio API
// The first should be the Opt-in confirmation
// The second should be the Info Session confirmation with the short link.
expectedMessageAmt := 1
msgs, err := fetchLastTextMessages(s.toNum, s.fromNum, expectedMessageAmt)
require.NoError(t, err)
require.NotEmptyf(t, sms, "no message found sent from %q -> %q", s.fromNum, s.toNum)
require.NotEmptyf(t, msgs, "no messages found sent from %q -> %q", s.fromNum, s.toNum)
require.Len(t, msgs, expectedMessageAmt, "Expected %d text messages sent", expectedMessageAmt)

// TODO: Check opt-in message once campaign approved. See above comment.
// textOptInMsg := msgs[0]
// require.Containsf(t, textOptInMsg, "opt", "expected an opt-in confirmation containing the word 'opt'\ngot:\n%q", textOptInMsg)

infoSessionConfirmation := msgs[0]
// Parse info link in SMS
link := parseSMSShortLink(sms)
link := parseSMSShortLink(infoSessionConfirmation)
// Intentionally using assert to continue running tests even if shortener fails
assert.NotEmpty(t, link, "URL Shortener service failed\nSMS: %q", sms)
assert.NotEmpty(t, link, "URL Shortener service failed\nSMS: %q", infoSessionConfirmation)

if link == "" {
// Shortener service failed, get the long link
link = parseSMSOriginalLink(sms)
link = parseSMSOriginalLink(infoSessionConfirmation)
}

// Visit link
Expand All @@ -90,7 +100,8 @@ func TestSmokeSignup(t *testing.T) {
// Zoom link
"https://us06web.zoom.us/w/8", //...
}
// conditionally check for location infomation

// conditionally check for location information
if s.selectedSession.LocationType == "HYBRID" || s.selectedSession.LocationType == "IN_PERSON" {
// Google Map link
infoHTMLtargets = append(infoHTMLtargets,
Expand Down Expand Up @@ -123,7 +134,7 @@ func TestLinkExtractors(t *testing.T) {
}

func TestCheckInfoPageContent(t *testing.T) {
t.Run("returns no error if all the target strigns are found", func(t *testing.T) {
t.Run("returns no error if all the target strings are found", func(t *testing.T) {
html := `<html><body>Henri</body></html>`
err := checkInfoPageContent(strings.NewReader(html), "Henri")
require.NoError(t, err)
Expand Down

0 comments on commit 130ae6c

Please sign in to comment.