-
Notifications
You must be signed in to change notification settings - Fork 23
/
lookup_test.go
50 lines (41 loc) · 1.23 KB
/
lookup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package plivo
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestLookupGet(t *testing.T) {
expectResponse("LookupGetResponse.json", http.StatusOK)
assert := require.New(t)
number := "+14154305555"
infoType := "carrier"
resp, err := client.Lookup.Get(number, LookupParams{
Type: infoType,
})
assert.Nil(err)
assert.NotNil(resp)
assert.NotNil(resp.Country)
assert.NotNil(resp.Carrier)
assert.NotNil(resp.Format)
assert.Equal(number, resp.PhoneNumber)
assert.Equal(number, resp.Format.E164)
assert.Equal(fmt.Sprintf("/v1/Number/%s?type=%s", number, infoType), resp.ResourceURI)
assertBaseRequest(t, http.MethodGet, "/v1/Number/%s?type=%s", number, infoType)
}
func TestLookupGetError(t *testing.T) {
expectResponse("LookupGetError.json", http.StatusNotFound)
assert := require.New(t)
number := "xxxxxxxxxxx"
infoType := "carrier"
resp, err := client.Lookup.Get(number, LookupParams{
Type: infoType,
})
assert.NotNil(err)
assert.Nil(resp)
errResp, ok := err.(*LookupError)
assert.True(ok)
assert.Equal(404, errResp.ErrorCode)
assert.Equal("Phone number is invalid or does not exist.", errResp.Message)
assertBaseRequest(t, http.MethodGet, "/v1/Number/%s?type=%s", number, infoType)
}