-
Notifications
You must be signed in to change notification settings - Fork 38
/
dtod_planner_test.go
129 lines (110 loc) · 3.83 KB
/
dtod_planner_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//RA Summary: gosec - errcheck - Unchecked return value
//RA: Linter flags errcheck error: Ignoring a method's return value can cause the program to overlook unexpected states and conditions.
//RA: Functions with unchecked return values in the file are used fetch data and assign data to a variable that is checked later on
//RA: Given the return value is being checked in a different line and the functions that are flagged by the linter are being used to assign variables
//RA: in a unit test, then there is no risk
//RA Developer Status: Mitigated
//RA Validator Status: Mitigated
//RA Modified Severity: N/A
// nolint:errcheck
package route
import (
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/route/ghcmocks"
"github.com/transcom/mymove/pkg/testdatagen"
"github.com/transcom/mymove/pkg/testingsuite"
)
const (
fakeUsername = "fake_username"
fakePassword = "fake_password"
)
type GHCTestSuite struct {
*testingsuite.PopTestSuite
}
func TestGHCTestSuite(t *testing.T) {
ts := &GHCTestSuite{
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage(), testingsuite.WithPerTestTransaction()),
}
suite.Run(t, ts)
ts.PopTestSuite.TearDown()
}
func (suite *GHCTestSuite) TestDTODTransitDistance() {
sourceAddress := models.Address{
StreetAddress1: "7 Q St",
City: "Augusta",
State: "GA",
PostalCode: "30907",
}
destinationAddress := models.Address{
StreetAddress1: "17 8th St",
City: "San Antonio",
State: "TX",
PostalCode: "78234",
}
panicFunc := func() {
planner := NewHHGPlanner(&ghcmocks.SoapCaller{}, fakeUsername, fakePassword)
planner.TransitDistance(suite.AppContextForTest(), &sourceAddress, &destinationAddress)
}
suite.Panics(panicFunc)
}
func (suite *GHCTestSuite) TestDTODLatLongTransitDistance() {
sourceLatLong := LatLong{
Latitude: 33.502697,
Longitude: -82.022616,
}
destinationLatLong := LatLong{
Latitude: 29.455854,
Longitude: -98.438823,
}
panicFunc := func() {
planner := NewDtodPlanner(&ghcmocks.SoapCaller{}, fakeUsername, fakePassword)
planner.LatLongTransitDistance(suite.AppContextForTest(), sourceLatLong, destinationLatLong)
}
suite.Panics(panicFunc)
}
func (suite *GHCTestSuite) TestDtodZip5TransitDistanceLineHaul() {
sourceZip5 := "30907"
destinationZip5 := "78234"
panicFunc := func() {
planner := NewHHGPlanner(&ghcmocks.SoapCaller{}, fakeUsername, fakePassword)
planner.Zip5TransitDistanceLineHaul(suite.AppContextForTest(), sourceZip5, destinationZip5)
}
suite.Panics(panicFunc)
}
func (suite *GHCTestSuite) TestDtodZipTransitDistance() {
suite.T().Run("fake DTOD returns a distance", func(t *testing.T) {
testSoapClient := &ghcmocks.SoapCaller{}
testSoapClient.On("Call",
mock.Anything,
mock.Anything,
).Return(soapResponseForDistance("150.33"), nil)
sourceZip3 := "303"
destinationZip3 := "309"
testdatagen.MakeZip3Distance(suite.DB(), testdatagen.Assertions{
Zip3Distance: models.Zip3Distance{
FromZip3: sourceZip3,
ToZip3: destinationZip3,
DistanceMiles: 150,
},
})
planner := NewDtodPlanner(testSoapClient, fakeUsername, fakePassword)
distance, err := planner.ZipTransitDistance(suite.AppContextForTest(), "30907", "30301")
suite.NoError(err)
suite.Equal(150, distance)
})
suite.T().Run("fake DTOD returns an error", func(t *testing.T) {
testSoapClient := &ghcmocks.SoapCaller{}
testSoapClient.On("Call",
mock.Anything,
mock.Anything,
).Return(soapResponseForDistance("150.33"), errors.New("some error"))
planner := NewDtodPlanner(testSoapClient, fakeUsername, fakePassword)
distance, err := planner.ZipTransitDistance(suite.AppContextForTest(), "30907", "30901")
suite.Error(err)
suite.Equal(0, distance)
})
}