|
| 1 | +package messagebird |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +var lookupObject []byte = []byte(`{ |
| 6 | + "href":"https://rest.messagebird.com/lookup/31624971134", |
| 7 | + "countryCode":"NL", |
| 8 | + "countryPrefix":31, |
| 9 | + "phoneNumber":31624971134, |
| 10 | + "type":"mobile", |
| 11 | + "formats":{ |
| 12 | + "e164":"+31624971134", |
| 13 | + "international":"+31 6 24971134", |
| 14 | + "national":"06 24971134", |
| 15 | + "rfc3966":"tel:+31-6-24971134" |
| 16 | + }, |
| 17 | + "hlr":{ |
| 18 | + "id":"6118d3f06566fcd0cdc8962h65065907", |
| 19 | + "network":20416, |
| 20 | + "reference":"yoloswag2000", |
| 21 | + "status":"active", |
| 22 | + "createdDatetime":"2015-12-15T08:19:24+00:00", |
| 23 | + "statusDatetime":"2015-12-15T08:19:25+00:00" |
| 24 | + } |
| 25 | +}`) |
| 26 | + |
| 27 | +var lookupHLRObject []byte = []byte(`{ |
| 28 | + "id":"6118d3f06566fcd0cdc8962h65065907", |
| 29 | + "network":20416, |
| 30 | + "reference":"yoloswag2000", |
| 31 | + "status":"active", |
| 32 | + "createdDatetime":"2015-12-15T08:19:24+00:00", |
| 33 | + "statusDatetime":"2015-12-15T08:19:25+00:00" |
| 34 | +}`) |
| 35 | + |
| 36 | +func TestLookup(t *testing.T) { |
| 37 | + SetServerResponse(200, lookupObject) |
| 38 | + |
| 39 | + phoneNumber := 31624971134 |
| 40 | + lookup, err := mbClient.Lookup(phoneNumber, "NL") |
| 41 | + if err != nil { |
| 42 | + t.Fatalf("Didn't expect error while doing the lookup: %s", err) |
| 43 | + } |
| 44 | + |
| 45 | + if lookup.Href != "https://rest.messagebird.com/lookup/31624971134" { |
| 46 | + t.Errorf("Unexpected lookup href: %s", lookup.Href) |
| 47 | + } |
| 48 | + if lookup.PhoneNumber != phoneNumber { |
| 49 | + t.Errorf("Unexpected lookup phoneNumber: %s", lookup.PhoneNumber) |
| 50 | + } |
| 51 | + if lookup.Formats != nil { |
| 52 | + if lookup.Formats.International != "+31 6 24971134" { |
| 53 | + t.Errorf("Unexpected International format: %s", lookup.HLR.Reference) |
| 54 | + } |
| 55 | + } else { |
| 56 | + t.Errorf("Unexpected empty Formats object") |
| 57 | + } |
| 58 | + if lookup.HLR != nil { |
| 59 | + if lookup.HLR.Reference != "yoloswag2000" { |
| 60 | + t.Errorf("Unexpected hlr reference: %s", lookup.HLR.Reference) |
| 61 | + } |
| 62 | + } else { |
| 63 | + t.Errorf("Unexpected empty hlr") |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +func checkHLR(t *testing.T, hlr *HLR) { |
| 68 | + if hlr.Id != "6118d3f06566fcd0cdc8962h65065907" { |
| 69 | + t.Errorf("Unexpected hlr id: %s", hlr.Id) |
| 70 | + } |
| 71 | + if hlr.Network != 20416 { |
| 72 | + t.Errorf("Unexpected hlr network: %d", hlr.Network) |
| 73 | + } |
| 74 | + if hlr.Reference != "yoloswag2000" { |
| 75 | + t.Errorf("Unexpected hlr reference: %s", hlr.Reference) |
| 76 | + } |
| 77 | + if hlr.Status != "active" { |
| 78 | + t.Errorf("Unexpected hlr status: %s", hlr.Status) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +func TestHLRLookup(t *testing.T) { |
| 83 | + SetServerResponse(200, lookupHLRObject) |
| 84 | + |
| 85 | + hlr, err := mbClient.HLRLookup(31624971134, "NL") |
| 86 | + if err != nil { |
| 87 | + t.Fatalf("Didn't expect error while doing the lookup: %s", err) |
| 88 | + } |
| 89 | + checkHLR(t, hlr) |
| 90 | +} |
| 91 | + |
| 92 | +func TestNewHLRLookup(t *testing.T) { |
| 93 | + SetServerResponse(201, lookupHLRObject) |
| 94 | + |
| 95 | + hlr, err := mbClient.NewHLRLookup(31624971134, "NL", "yoloswag2000") |
| 96 | + if err != nil { |
| 97 | + t.Fatalf("Didn't expect error while doing the lookup: %s", err) |
| 98 | + } |
| 99 | + |
| 100 | + checkHLR(t, hlr) |
| 101 | +} |
0 commit comments