Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Feb 10, 2020
1 parent b08d868 commit 89f7eaa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions models/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestContacts(t *testing.T) {
if len(contacts) == 3 {
assert.Equal(t, "Cathy", contacts[0].Name())
assert.Equal(t, len(contacts[0].URNs()), 1)
assert.Equal(t, contacts[0].URNs()[0].String(), "tel:+250700000001?id=10000&priority=50")
assert.Equal(t, contacts[0].URNs()[0].String(), "tel:+16055741111?id=10000&priority=50")
assert.Equal(t, 1, contacts[0].Groups().Count())

assert.Equal(t, "Sokoto", contacts[0].Fields()["state"].QueryValue())
Expand All @@ -196,7 +196,7 @@ func TestContacts(t *testing.T) {
assert.NotNil(t, contacts[1].Fields()["joined"].QueryValue())
assert.Equal(t, 2, len(contacts[1].URNs()))
assert.Equal(t, contacts[1].URNs()[0].String(), "whatsapp:250788373373?id=20121&priority=100")
assert.Equal(t, contacts[1].URNs()[1].String(), "tel:+250700000002?id=10001&priority=50")
assert.Equal(t, contacts[1].URNs()[1].String(), "tel:+16055742222?id=10001&priority=50")
assert.Equal(t, 0, contacts[1].Groups().Count())

assert.Equal(t, "George", contacts[2].Name())
Expand All @@ -212,7 +212,7 @@ func TestContacts(t *testing.T) {

bob, err := modelContacts[1].FlowContact(org, session)
assert.NoError(t, err)
assert.Equal(t, "tel:+250700000002?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=1000", bob.URNs()[0].String())
assert.Equal(t, "tel:+16055742222?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=1000", bob.URNs()[0].String())
assert.Equal(t, "whatsapp:250788373373?id=20121&priority=999", bob.URNs()[1].String())

// add another tel urn to bob
Expand All @@ -231,7 +231,7 @@ func TestContacts(t *testing.T) {
bob, err = modelContacts[0].FlowContact(org, session)
assert.NoError(t, err)
assert.Equal(t, "tel:+250788373393?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=20122&priority=1000", bob.URNs()[0].String())
assert.Equal(t, "tel:+250700000002?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=999", bob.URNs()[1].String())
assert.Equal(t, "tel:+16055742222?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=999", bob.URNs()[1].String())
assert.Equal(t, "whatsapp:250788373373?id=20121&priority=998", bob.URNs()[2].String())

// no op this time
Expand All @@ -241,7 +241,7 @@ func TestContacts(t *testing.T) {
bob, err = modelContacts[0].FlowContact(org, session)
assert.NoError(t, err)
assert.Equal(t, "tel:+250788373393?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=20122&priority=1000", bob.URNs()[0].String())
assert.Equal(t, "tel:+250700000002?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=999", bob.URNs()[1].String())
assert.Equal(t, "tel:+16055742222?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=999", bob.URNs()[1].String())
assert.Equal(t, "whatsapp:250788373373?id=20121&priority=998", bob.URNs()[2].String())

// calling with no channel is a noop on the channel
Expand All @@ -251,7 +251,7 @@ func TestContacts(t *testing.T) {
bob, err = modelContacts[0].FlowContact(org, session)
assert.NoError(t, err)
assert.Equal(t, "tel:+250788373393?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=20122&priority=1000", bob.URNs()[0].String())
assert.Equal(t, "tel:+250700000002?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=999", bob.URNs()[1].String())
assert.Equal(t, "tel:+16055742222?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=10001&priority=999", bob.URNs()[1].String())
assert.Equal(t, "whatsapp:250788373373?id=20121&priority=998", bob.URNs()[2].String())
}

Expand Down
2 changes: 1 addition & 1 deletion models/schedules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestGetExpired(t *testing.T) {
assert.Equal(t, Org1, bcast.OrgID())
assert.Equal(t, []ContactID{CathyID, GeorgeID}, bcast.ContactIDs())
assert.Equal(t, []GroupID{DoctorsGroupID}, bcast.GroupIDs())
assert.Equal(t, []urns.URN{urns.URN("tel:+250700000001?id=10000")}, bcast.URNs())
assert.Equal(t, []urns.URN{urns.URN("tel:+16055741111?id=10000")}, bcast.URNs())
}

func TestNextFire(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions models/test_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ var TwitterChannelUUID = assets.ChannelUUID("0f661e8b-ea9d-4bd3-9953-d368340acf9

var CathyID = ContactID(10000)
var CathyUUID = flows.ContactUUID("6393abc0-283d-4c9b-a1b3-641a035c34bf")
var CathyURN = urns.URN("tel:+250700000001")
var CathyURN = urns.URN("tel:+16055741111")
var CathyURNID = URNID(10000)

var BobID = ContactID(10001)
var BobUUID = flows.ContactUUID("b699a406-7e44-49be-9f01-1a82893e8a10")
var BobURN = urns.URN("tel:+250700000002")
var BobURN = urns.URN("tel:+16055742222")
var BobURNID = URNID(10001)
var GeorgeID = ContactID(10002)
var GeorgeUUID = flows.ContactUUID("8d024bcd-f473-4719-a00a-bd0bb1190135")
var GeorgeURN = urns.URN("tel:+250700000003")
var GeorgeURN = urns.URN("tel:+16055743333")
var GeorgeURNID = URNID(10002)

var AlexandriaID = ContactID(10003)
var AlexandriaUUID = flows.ContactUUID("9709c157-4606-4d41-9df3-9e9c9b4ae2d4")
var AlexandriaURN = urns.URN("tel:+250700000004")
var AlexandriaURN = urns.URN("tel:+16055744444")
var AlexandriaURNID = URNID(10003)

var FavoritesFlowID = FlowID(10000)
Expand Down
10 changes: 5 additions & 5 deletions web/ivr/ivr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func TestTwilioIVR(t *testing.T) {
logrus.WithField("method", r.Method).WithField("url", r.URL.String()).WithField("form", r.Form).Info("test server called")
if strings.HasSuffix(r.URL.String(), "Calls.json") {
to := r.Form.Get("To")
if to == "+250700000001" {
if to == "+16055741111" {
w.WriteHeader(http.StatusCreated)
w.Write([]byte(`{"sid": "Call1"}`))
} else if to == "+250700000003" {
} else if to == "+16055743333" {
w.WriteHeader(http.StatusCreated)
w.Write([]byte(`{"sid": "Call2"}`))
} else {
Expand All @@ -68,7 +68,7 @@ func TestTwilioIVR(t *testing.T) {
db.MustExec(`UPDATE channels_channel SET config = '{"auth_token": "token", "account_sid": "sid", "callback_domain": "localhost:8090"}' WHERE id = $1`, models.TwilioChannelID)

// create a flow start for cathy and george
parentSummary := json.RawMessage(`{"flow": {"name": "IVR Flow", "uuid": "2f81d0ea-4d75-4843-9371-3f7465311cce"}, "uuid": "8bc73097-ac57-47fb-82e5-184f8ec6dbef", "status": "active", "contact": {"id": 10000, "name": "Cathy", "urns": ["tel:+250700000001?id=10000&priority=50"], "uuid": "6393abc0-283d-4c9b-a1b3-641a035c34bf", "fields": {"gender": {"text": "F"}}, "groups": [{"name": "Doctors", "uuid": "c153e265-f7c9-4539-9dbc-9b358714b638"}], "timezone": "America/Los_Angeles", "created_on": "2019-07-23T09:35:01.439614-07:00"}, "results": {}}`)
parentSummary := json.RawMessage(`{"flow": {"name": "IVR Flow", "uuid": "2f81d0ea-4d75-4843-9371-3f7465311cce"}, "uuid": "8bc73097-ac57-47fb-82e5-184f8ec6dbef", "status": "active", "contact": {"id": 10000, "name": "Cathy", "urns": ["tel:+16055741111?id=10000&priority=50"], "uuid": "6393abc0-283d-4c9b-a1b3-641a035c34bf", "fields": {"gender": {"text": "F"}}, "groups": [{"name": "Doctors", "uuid": "c153e265-f7c9-4539-9dbc-9b358714b638"}], "timezone": "America/Los_Angeles", "created_on": "2019-07-23T09:35:01.439614-07:00"}, "results": {}}`)

start := models.NewFlowStart(models.Org1, models.IVRFlow, models.IVRFlowID, models.DoRestartParticipants, models.DoIncludeActive).
WithContactIDs([]models.ContactID{models.CathyID, models.GeorgeID}).
Expand Down Expand Up @@ -350,10 +350,10 @@ func TestNexmoIVR(t *testing.T) {
logrus.WithField("method", r.Method).WithField("url", r.URL.String()).WithField("body", string(body)).Info("test server called")
form := &CallForm{}
json.Unmarshal(body, form)
if form.To[0].Number == 250700000001 {
if form.To[0].Number == 16055741111 {
w.WriteHeader(http.StatusCreated)
w.Write([]byte(`{ "uuid": "Call1","status": "started","direction": "outbound","conversation_uuid": "Conversation1"}`))
} else if form.To[0].Number == 250700000003 {
} else if form.To[0].Number == 16055743333 {
w.WriteHeader(http.StatusCreated)
w.Write([]byte(`{ "uuid": "Call2","status": "started","direction": "outbound","conversation_uuid": "Conversation2"}`))
} else {
Expand Down

0 comments on commit 89f7eaa

Please sign in to comment.