-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathinsurance_test.go
More file actions
112 lines (89 loc) · 3 KB
/
insurance_test.go
File metadata and controls
112 lines (89 loc) · 3 KB
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
112
package easypost
import (
"errors"
"reflect"
"strings"
)
func (c *ClientTests) TestInsuranceCreate() {
client := c.TestClient()
assert, require := c.Assert(), c.Require()
shipment, err := client.CreateShipment(c.fixture.OneCallBuyShipment())
require.NoError(err)
insuranceData := c.fixture.BasicInsurance()
insuranceData.TrackingCode = shipment.TrackingCode
insurance, err := client.CreateInsurance(insuranceData)
require.NoError(err)
assert.Equal(reflect.TypeOf(&Insurance{}), reflect.TypeOf(insurance))
assert.True(strings.HasPrefix(insurance.ID, "ins_"))
assert.Equal("100.00000", insurance.Amount)
}
func (c *ClientTests) TestInsuranceRetrieve() {
client := c.TestClient()
assert, require := c.Assert(), c.Require()
insurances, err := client.ListInsurances(
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
require.NoError(err)
retrievedInsurance, err := client.GetInsurance(insurances.Insurances[0].ID)
require.NoError(err)
assert.Equal(reflect.TypeOf(&Insurance{}), reflect.TypeOf(retrievedInsurance))
assert.Equal(insurances.Insurances[0], retrievedInsurance)
}
func (c *ClientTests) TestInsuranceAll() {
client := c.TestClient()
assert, require := c.Assert(), c.Require()
insurances, err := client.ListInsurances(
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
require.NoError(err)
insurancesList := insurances.Insurances
assert.LessOrEqual(len(insurancesList), c.fixture.pageSize())
assert.NotNil(insurances.HasMore)
for _, insurance := range insurancesList {
assert.Equal(reflect.TypeOf(&Insurance{}), reflect.TypeOf(insurance))
}
}
func (c *ClientTests) TestInsuranceGetNextPage() {
client := c.TestClient()
assert, require := c.Assert(), c.Require()
firstPage, err := client.ListInsurances(
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
require.NoError(err)
nextPage, err := client.GetNextInsurancePageWithPageSize(firstPage, c.fixture.pageSize())
defer func() {
if err == nil {
assert.True(len(nextPage.Insurances) <= c.fixture.pageSize())
lastIDOfFirstPage := firstPage.Insurances[len(firstPage.Insurances)-1].ID
firstIdOfSecondPage := nextPage.Insurances[0].ID
assert.NotEqual(lastIDOfFirstPage, firstIdOfSecondPage)
}
}()
if err != nil {
var endOfPaginationErr *EndOfPaginationError
if errors.As(err, &endOfPaginationErr) {
assert.Equal(err.Error(), endOfPaginationErr.Error())
return
}
require.NoError(err)
}
}
func (c *ClientTests) TestInsuranceRefund() {
client := c.TestClient()
assert, require := c.Assert(), c.Require()
insuranceData := c.fixture.BasicInsurance()
insuranceData.TrackingCode = "EZ1000000001"
insurance, _ := client.CreateInsurance(insuranceData)
refundInsurance, err := client.RefundInsurance(insurance.ID)
require.NoError(err)
assert.Equal(reflect.TypeOf(&Insurance{}), reflect.TypeOf(refundInsurance))
assert.True(strings.HasPrefix(refundInsurance.ID, "ins_"))
assert.Equal("cancelled", refundInsurance.Status)
assert.Equal("Insurance was cancelled by the user.", refundInsurance.Messages[0])
}