forked from sundowndev/phoneinfoga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ovh_test.go
111 lines (90 loc) · 2.9 KB
/
ovh_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package scanners
import (
"testing"
"github.com/stretchr/testify/assert"
gock "gopkg.in/h2non/gock.v1"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/utils"
)
func TestOVHScanner(t *testing.T) {
assert := assert.New(t)
t.Run("should find number on OVH", func(t *testing.T) {
defer gock.Off() // Flush pending mocks after test execution
gock.New("https://api.ovh.com").
Get("/1.0/telephony/number/detailedZones").
MatchParam("country", "fr").
Reply(200).
JSON([]OVHAPIResponseNumber{
{
ZneList: []string{},
MatchingCriteria: "",
Prefix: 33,
InternationalNumber: "003336517xxxx",
Country: "fr",
ZipCode: "",
Number: "036517xxxx",
City: "Abbeville",
AskedCity: "",
},
})
number, _ := LocalScan("+33 0365179268")
result, err := ovhScanCLI(utils.LoggerService, number)
assert.Equal(result, &OVHScannerResponse{
Found: true,
NumberRange: "036517xxxx",
City: "Abbeville",
ZipCode: "",
}, "they should be equal")
assert.Equal(gock.IsDone(), true, "there should have no pending mocks")
assert.Nil(err, "they should be equal")
})
t.Run("should not find number on OVH", func(t *testing.T) {
defer gock.Off() // Flush pending mocks after test execution
gock.New("https://api.ovh.com").
Get("/1.0/telephony/number/detailedZones").
MatchParam("country", "us").
Reply(200).
JSON([]OVHAPIResponseNumber{
{
ZneList: []string{},
MatchingCriteria: "",
Prefix: 33,
InternationalNumber: "003336517xxxx",
Country: "fr",
ZipCode: "",
Number: "036517xxxx",
City: "Abbeville",
AskedCity: "",
},
})
number, _ := LocalScan("+1 718-521-2994")
result, err := OVHScan(number)
assert.Equal(err, nil, "should not be errored")
assert.Equal(result, &OVHScannerResponse{
Found: false,
NumberRange: "",
City: "",
ZipCode: "",
}, "they should be equal")
assert.Equal(gock.IsDone(), true, "there should have no pending mocks")
})
t.Run("should not find country code on OVH", func(t *testing.T) {
defer gock.Off() // Flush pending mocks after test execution
gock.New("https://api.ovh.com").
Get("/1.0/telephony/number/detailedZones").
MatchParam("country", "us").
Reply(200).
JSON(map[string]string{
"message": "[country] Given data (us) does not belong to the NumberCountryEnum enumeration",
})
number, _ := LocalScan("+1 718-521-2994")
result, err := OVHScan(number)
assert.Equal(err, nil, "should not be errored")
assert.Equal(result, &OVHScannerResponse{
Found: false,
NumberRange: "",
City: "",
ZipCode: "",
}, "they should be equal")
assert.Equal(gock.IsDone(), true, "there should have no pending mocks")
})
}