@@ -23,6 +23,7 @@ import (
23
23
"github.com/nyaruka/courier/test"
24
24
"github.com/nyaruka/gocommon/dbutil/assertdb"
25
25
"github.com/nyaruka/gocommon/httpx"
26
+ "github.com/nyaruka/gocommon/i18n"
26
27
"github.com/nyaruka/gocommon/jsonx"
27
28
"github.com/nyaruka/gocommon/urns"
28
29
"github.com/nyaruka/gocommon/uuids"
@@ -195,7 +196,7 @@ func (ts *BackendTestSuite) TestDeleteMsgByExternalID() {
195
196
func (ts * BackendTestSuite ) TestContact () {
196
197
knChannel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
197
198
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , knChannel , nil )
198
- urn , _ := urns .NewTelURNForCountry ( " 12065551518" , "US " )
199
+ urn := urns .URN ( "tel:+ 12065551518" )
199
200
200
201
ctx := context .Background ()
201
202
now := time .Now ()
@@ -220,15 +221,15 @@ func (ts *BackendTestSuite) TestContact() {
220
221
ts .True (contact2 .CreatedOn_ .Before (now2 ))
221
222
222
223
// load a contact by URN instead (this one is in our testdata)
223
- cURN , _ := urns .NewTelURNForCountry ( " +12067799192" , "US " )
224
+ cURN := urns .URN ( "tel: +12067799192" )
224
225
contact , err = contactForURN (ctx , ts .b , knChannel .OrgID (), knChannel , cURN , nil , "" , clog )
225
226
ts .NoError (err )
226
227
ts .NotNil (contact )
227
228
228
229
ts .Equal (null .String ("" ), contact .Name_ )
229
230
ts .Equal (courier .ContactUUID ("a984069d-0008-4d8c-a772-b14a8a6acccc" ), contact .UUID_ )
230
231
231
- urn , _ = urns .NewTelURNForCountry ( " 12065551519" , "US " )
232
+ urn = urns .URN ( "tel:+ 12065551519" )
232
233
233
234
// long name are truncated
234
235
@@ -243,7 +244,7 @@ func (ts *BackendTestSuite) TestContact() {
243
244
func (ts * BackendTestSuite ) TestContactRace () {
244
245
knChannel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
245
246
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , knChannel , nil )
246
- urn , _ := urns .NewTelURNForCountry ( " 12065551518" , "US " )
247
+ urn := urns .URN ( "tel:+ 12065551518" )
247
248
248
249
urnSleep = true
249
250
defer func () { urnSleep = false }()
@@ -273,8 +274,7 @@ func (ts *BackendTestSuite) TestAddAndRemoveContactURN() {
273
274
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , knChannel , nil )
274
275
ctx := context .Background ()
275
276
276
- cURN , err := urns .NewTelURNForCountry ("+12067799192" , "US" )
277
- ts .NoError (err )
277
+ cURN := urns .URN ("tel:+12067799192" )
278
278
279
279
contact , err := contactForURN (ctx , ts .b , knChannel .OrgID_ , knChannel , cURN , nil , "" , clog )
280
280
ts .NoError (err )
@@ -287,7 +287,7 @@ func (ts *BackendTestSuite) TestAddAndRemoveContactURN() {
287
287
ts .NoError (err )
288
288
ts .Equal (len (contactURNs ), 1 )
289
289
290
- urn , _ := urns .NewTelURNForCountry ( " 12065551518" , "US " )
290
+ urn := urns .URN ( "tel:+ 12065551518" )
291
291
addedURN , err := ts .b .AddURNtoContact (ctx , knChannel , contact , urn , nil )
292
292
ts .NoError (err )
293
293
ts .NotNil (addedURN )
@@ -314,7 +314,7 @@ func (ts *BackendTestSuite) TestContactURN() {
314
314
knChannel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
315
315
twChannel := ts .getChannel ("TW" , "dbc126ed-66bc-4e28-b67b-81dc3327c96a" )
316
316
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , knChannel , nil )
317
- urn , _ := urns .NewTelURNForCountry ( " 12065551515" , "US " )
317
+ urn := urns .URN ( "tel:+ 12065551515" )
318
318
319
319
ctx := context .Background ()
320
320
@@ -371,12 +371,12 @@ func (ts *BackendTestSuite) TestContactURN() {
371
371
372
372
// test that we don't use display when looking up URNs
373
373
tgChannel := ts .getChannel ("TG" , "dbc126ed-66bc-4e28-b67b-81dc3327c98a" )
374
- tgURN , _ := urns .NewTelegramURN ( 12345 , " " )
374
+ tgURN := urns .URN ( "telegram:12345 " )
375
375
376
376
tgContact , err := contactForURN (ctx , ts .b , tgChannel .OrgID_ , tgChannel , tgURN , nil , "" , clog )
377
377
ts .NoError (err )
378
378
379
- tgURNDisplay , _ := urns .NewTelegramURN ( 12345 , " Jane" )
379
+ tgURNDisplay := urns .URN ( "telegram:12345# Jane" )
380
380
displayContact , err := contactForURN (ctx , ts .b , tgChannel .OrgID_ , tgChannel , tgURNDisplay , nil , "" , clog )
381
381
382
382
ts .NoError (err )
@@ -393,7 +393,7 @@ func (ts *BackendTestSuite) TestContactURN() {
393
393
ts .Equal (null .String ("Jane" ), tgContactURN .Display )
394
394
395
395
// try to create two contacts at the same time in goroutines, this tests our transaction rollbacks
396
- urn2 , _ := urns .NewTelURNForCountry ( " 12065551616" , "US " )
396
+ urn2 := urns .URN ( "tel:+ 12065551616" )
397
397
var wait sync.WaitGroup
398
398
var contact2 , contact3 * Contact
399
399
wait .Add (2 )
@@ -419,8 +419,8 @@ func (ts *BackendTestSuite) TestContactURN() {
419
419
func (ts * BackendTestSuite ) TestContactURNPriority () {
420
420
knChannel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
421
421
twChannel := ts .getChannel ("TW" , "dbc126ed-66bc-4e28-b67b-81dc3327c96a" )
422
- knURN , _ := urns .NewTelURNForCountry ( " 12065551111" , "US " )
423
- twURN , _ := urns .NewTelURNForCountry ( " 12065552222" , "US " )
422
+ knURN := urns .URN ( "tel:+ 12065551111" )
423
+ twURN := urns .URN ( "tel:+ 12065552222" )
424
424
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , knChannel , nil )
425
425
426
426
ctx := context .Background ()
@@ -627,12 +627,12 @@ func (ts *BackendTestSuite) TestMsgStatus() {
627
627
628
628
// update URN when the new doesn't exist
629
629
tx , _ := ts .b .db .BeginTxx (ctx , nil )
630
- oldURN , _ := urns .NewWhatsAppURN ( " 55988776655" )
630
+ oldURN := urns .URN ( "whatsapp: 55988776655" )
631
631
_ = insertContactURN (tx , newContactURN (channel .OrgID_ , channel .ID_ , NilContactID , oldURN , nil ))
632
632
633
633
ts .NoError (tx .Commit ())
634
634
635
- newURN , _ := urns .NewWhatsAppURN ( " 5588776655" )
635
+ newURN := urns .URN ( "whatsapp: 5588776655" )
636
636
status = ts .b .NewStatusUpdate (channel , courier .MsgID (10000 ), courier .MsgStatusSent , clog6 )
637
637
status .SetURNUpdate (oldURN , newURN )
638
638
@@ -646,8 +646,8 @@ func (ts *BackendTestSuite) TestMsgStatus() {
646
646
ts .NoError (tx .Commit ())
647
647
648
648
// new URN already exits but don't have an associated contact
649
- oldURN , _ = urns .NewWhatsAppURN ( " 55999887766" )
650
- newURN , _ = urns .NewWhatsAppURN ( " 5599887766" )
649
+ oldURN = urns .URN ( "whatsapp: 55999887766" )
650
+ newURN = urns .URN ( "whatsapp: 5599887766" )
651
651
tx , _ = ts .b .db .BeginTxx (ctx , nil )
652
652
contact , _ := contactForURN (ctx , ts .b , channel .OrgID_ , channel , oldURN , nil , "" , clog6 )
653
653
_ = insertContactURN (tx , newContactURN (channel .OrgID_ , channel .ID_ , NilContactID , newURN , nil ))
@@ -668,8 +668,8 @@ func (ts *BackendTestSuite) TestMsgStatus() {
668
668
ts .NoError (tx .Commit ())
669
669
670
670
// new URN already exits and have an associated contact
671
- oldURN , _ = urns .NewWhatsAppURN ( " 55988776655" )
672
- newURN , _ = urns .NewWhatsAppURN ( " 5588776655" )
671
+ oldURN = urns .URN ( "whatsapp: 55988776655" )
672
+ newURN = urns .URN ( "whatsapp: 5588776655" )
673
673
tx , _ = ts .b .db .BeginTxx (ctx , nil )
674
674
_ , _ = contactForURN (ctx , ts .b , channel .OrgID_ , channel , oldURN , nil , "" , clog6 )
675
675
otherContact , _ := contactForURN (ctx , ts .b , channel .OrgID_ , channel , newURN , nil , "" , clog6 )
@@ -747,8 +747,8 @@ func (ts *BackendTestSuite) TestCheckForDuplicate() {
747
747
ctx := context .Background ()
748
748
knChannel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
749
749
twChannel := ts .getChannel ("TW" , "dbc126ed-66bc-4e28-b67b-81dc3327c96a" )
750
- urn , _ := urns .NewTelURNForCountry ( " 12065551215", knChannel . Country () )
751
- urn2 , _ := urns .NewTelURNForCountry ( " 12065551277", knChannel . Country () )
750
+ urn := urns .URN ( "tel:+ 12065551215" )
751
+ urn2 := urns .URN ( "tel:+ 12065551277" )
752
752
753
753
createAndWriteMsg := func (ch courier.Channel , u urns.URN , text , extID string ) * Msg {
754
754
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , knChannel , nil )
@@ -900,14 +900,14 @@ func (ts *BackendTestSuite) TestOutgoingQueue() {
900
900
901
901
func (ts * BackendTestSuite ) TestChannel () {
902
902
noAddress := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c99a" )
903
- ts .Equal ("US" , noAddress .Country ())
903
+ ts .Equal (i18n . Country ( "US" ) , noAddress .Country ())
904
904
ts .Equal (courier .NilChannelAddress , noAddress .ChannelAddress ())
905
905
906
906
knChannel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
907
907
908
908
ts .Equal ("2500" , knChannel .Address ())
909
909
ts .Equal (courier .ChannelAddress ("2500" ), knChannel .ChannelAddress ())
910
- ts .Equal ("RW" , knChannel .Country ())
910
+ ts .Equal (i18n . Country ( "RW" ) , knChannel .Country ())
911
911
ts .Equal ([]courier.ChannelRole {courier .ChannelRoleSend , courier .ChannelRoleReceive }, knChannel .Roles ())
912
912
ts .True (knChannel .HasRole (courier .ChannelRoleSend ))
913
913
ts .True (knChannel .HasRole (courier .ChannelRoleReceive ))
@@ -1098,7 +1098,7 @@ func (ts *BackendTestSuite) TestWriteMsg() {
1098
1098
now := time .Now ().Round (time .Microsecond ).In (time .UTC )
1099
1099
1100
1100
// create a new courier msg
1101
- urn , _ := urns .NewTelURNForCountry ( " 12065551212", knChannel . Country () )
1101
+ urn := urns .URN ( "tel:+ 12065551212" )
1102
1102
msg := ts .b .NewIncomingMsg (knChannel , urn , "test123" , "ext123" , clog ).WithReceivedOn (now ).WithContactName ("test contact" ).(* Msg )
1103
1103
1104
1104
// try to write it to our db
@@ -1197,7 +1197,7 @@ func (ts *BackendTestSuite) TestWriteMsgWithAttachments() {
1197
1197
1198
1198
knChannel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
1199
1199
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , knChannel , nil )
1200
- urn , _ := urns .NewTelURNForCountry ( " 12065551218", knChannel . Country () )
1200
+ urn := urns .URN ( "tel:+ 12065551218" )
1201
1201
1202
1202
msg := ts .b .NewIncomingMsg (knChannel , urn , "two regular attachments" , "" , clog ).(* Msg )
1203
1203
msg .WithAttachment ("http://example.com/test.jpg" )
@@ -1242,7 +1242,7 @@ func (ts *BackendTestSuite) TestPreferredChannelCheckRole() {
1242
1242
// have to round to microseconds because postgres can't store nanos
1243
1243
now := time .Now ().Round (time .Microsecond ).In (time .UTC )
1244
1244
1245
- urn , _ := urns .NewTelURNForCountry ( " 12065552020", exChannel . Country () )
1245
+ urn := urns .URN ( "tel:+ 12065552020" )
1246
1246
msg := ts .b .NewIncomingMsg (exChannel , urn , "test123" , "ext123" , clog ).WithReceivedOn (now ).WithContactName ("test contact" ).(* Msg )
1247
1247
1248
1248
// try to write it to our db
@@ -1270,7 +1270,7 @@ func (ts *BackendTestSuite) TestChannelEvent() {
1270
1270
ctx := context .Background ()
1271
1271
channel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
1272
1272
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , channel , nil )
1273
- urn , _ := urns .NewTelURNForCountry ( " 12065551616", channel . Country () )
1273
+ urn := urns .URN ( "tel:+ 12065551616" )
1274
1274
1275
1275
event := ts .b .NewChannelEvent (channel , courier .EventTypeReferral , urn , clog ).WithExtra (map [string ]string {"ref_id" : "12345" }).WithContactName ("kermit frog" )
1276
1276
err := ts .b .WriteChannelEvent (ctx , event , clog )
@@ -1319,7 +1319,7 @@ func (ts *BackendTestSuite) TestMailroomEvents() {
1319
1319
1320
1320
channel := ts .getChannel ("KN" , "dbc126ed-66bc-4e28-b67b-81dc3327c95d" )
1321
1321
clog := courier .NewChannelLog (courier .ChannelLogTypeUnknown , channel , nil )
1322
- urn , _ := urns .NewTelURNForCountry ( " 12065551616", channel . Country () )
1322
+ urn := urns .URN ( "tel:+ 12065551616" )
1323
1323
1324
1324
event := ts .b .NewChannelEvent (channel , courier .EventTypeReferral , urn , clog ).
1325
1325
WithExtra (map [string ]string {"ref_id" : "12345" }).
0 commit comments