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