Path: blob/master/lib/remote/suppliers/ovh_test.go
994 views
package suppliers12import (3"errors"4"github.com/stretchr/testify/assert"5"github.com/sundowndev/phoneinfoga/v2/lib/number"6"gopkg.in/h2non/gock.v1"7"net/url"8"testing"9)1011func TestOVHSupplierSuccess(t *testing.T) {12defer gock.Off() // Flush pending mocks after test execution1314num, _ := number.NewNumber("33365172812")1516gock.New("https://api.ovh.com").17Get("/1.0/telephony/number/detailedZones").18MatchParam("country", "fr").19Reply(200).20JSON([]OVHAPIResponseNumber{21{22ZneList: []string{},23MatchingCriteria: "",24Prefix: 33,25InternationalNumber: "003336517xxxx",26Country: "fr",27ZipCode: "",28Number: "036517xxxx",29City: "Abbeville",30AskedCity: "",31},32})3334s := NewOVHSupplier()3536got, err := s.Search(*num)37assert.Nil(t, err)3839expectedResult := &OVHScannerResponse{40Found: true,41NumberRange: "036517xxxx",42City: "Abbeville",43}4445assert.Equal(t, expectedResult, got)46}4748func TestOVHSupplierError(t *testing.T) {49defer gock.Off() // Flush pending mocks after test execution5051num, _ := number.NewNumber("33365172812")5253dummyError := errors.New("test")5455gock.New("https://api.ovh.com").56Get("/1.0/telephony/number/detailedZones").57MatchParam("country", "fr").58ReplyError(dummyError)5960s := NewOVHSupplier()6162got, err := s.Search(*num)63assert.Nil(t, got)64assert.Equal(t, &url.Error{65Op: "Get",66URL: "https://api.ovh.com/1.0/telephony/number/detailedZones?country=fr",67Err: dummyError,68}, err)69}7071func TestOVHSupplierCountryCodeError(t *testing.T) {72defer gock.Off() // Flush pending mocks after test execution7374gock.New("https://api.ovh.com").75Get("/1.0/telephony/number/detailedZones").76MatchParam("country", "co").77Reply(400).78JSON(OVHAPIErrorResponse{Message: "[country] Given data (co) does not belong to the NumberCountryEnum enumeration"})7980num, err := number.NewNumber("+575556661212")81if err != nil {82t.Fatal(err)83}8485s := NewOVHSupplier()8687got, err := s.Search(*num)88assert.Nil(t, got)89assert.EqualError(t, err, "[country] Given data (co) does not belong to the NumberCountryEnum enumeration")90}919293