-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_test.go
77 lines (66 loc) · 1.74 KB
/
address_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
// Copyright 2020 RetailNext, Inc.
//
// Licensed under the BSD 3-Clause License (the "License");
// you may not use this file except in compliance with the License.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package easypost
import (
"encoding/json"
"os"
"reflect"
"testing"
)
func TestValidateAddress(t *testing.T) {
setup()
address, err := testClient.VerifyAndCreateAddress(Address{
Street1: "Valid Street Name",
}, DeliveryVerification)
if err != nil {
t.Fatalf("unxepected error: %s", err)
}
f, err := os.Open("./test/addresses/valid_address.json")
if err != nil {
t.Fatal(err)
}
defer f.Close()
var expectedAddress Address
if err := json.NewDecoder(f).Decode(&expectedAddress); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(address, &expectedAddress) {
t.Fatalf("address: \nexpected %+v\n got %+v", &expectedAddress, address)
}
}
func TestInvalidAddress(t *testing.T) {
setup()
_, err := testClient.VerifyAndCreateAddress(Address{
Street1: "address",
}, DeliveryVerification)
if err == nil {
t.Fatal("error expected")
}
processingError, ok := err.(ProcessingError)
if !ok {
t.Fatalf("expected ProcessingError, got: %T(%s)", err, err)
}
var details []AddressVerificationError
if err := processingError.Details(&details); err != nil {
t.Fatal(err)
}
expectedDetails := []AddressVerificationError{
{
Code: "E.ADDRESS.NOT_FOUND",
Field: "address",
Message: "Address not found",
}, {
Code: "E.HOUSE_NUMBER.MISSING",
Field: "street1",
Message: "House number is missing",
},
}
if !reflect.DeepEqual(details, expectedDetails) {
t.Fatalf("address error: \nexpected %+v\n got %+v", expectedDetails, details)
}
}