Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pambecker committed Jan 22, 2025
1 parent 2b268f9 commit 9aaa013
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ BEGIN

END IF;

-- Raise an exception if no rate area is found
IF gbloc IS NULL THEN
RAISE EXCEPTION 'GBLOC not found for address ID % for affiliation %', address_id, affiiation;
END IF;
Expand Down
13 changes: 9 additions & 4 deletions pkg/handlers/ghcapi/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,14 @@ func (h CreateOrderHandler) Handle(params orderop.CreateOrderParams) middleware.
} else {
newDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), newDutyLocation.Address.PostalCode)
if err != nil {
err = apperror.NewBadDataError("New duty location GBLOC cannot be verified")
appCtx.Logger().Error(err.Error())
return orderop.NewCreateOrderUnprocessableEntity(), err
switch err {
case sql.ErrNoRows:
return nil, apperror.NewNotFoundError(newDutyLocation.ID, "while looking for New Duty Location PostalCodeToGBLOC")
default:
err = apperror.NewBadDataError("New duty location GBLOC cannot be verified")
appCtx.Logger().Error(err.Error())
return orderop.NewCreateOrderUnprocessableEntity(), err
}
}
newDutyLocationGBLOC = &newDutyLocationGBLOCConus.GBLOC
}
Expand All @@ -239,7 +244,7 @@ func (h CreateOrderHandler) Handle(params orderop.CreateOrderParams) middleware.
if *originDutyLocation.Address.IsOconus {
originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, serviceMember)
if err != nil {
return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location Oconus GBLOC")
return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Origin Duty Location Oconus GBLOC")
}
originDutyLocationGBLOC = originDutyLocationGBLOCOconus
} else {
Expand Down
22 changes: 22 additions & 0 deletions pkg/models/gbloc_aors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package models_test

import (
"github.com/transcom/mymove/pkg/models"
)

func (suite *ModelSuite) TestFetchGblocAorsByJppsoCodeRateAreaDept() {
usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99801")
suite.NotNil(usprc)
suite.FatalNoError(err)
oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String())
suite.NotNil(oconusRateArea)
suite.NoError(err)

jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPK")
suite.NotNil(jppsoRegion)
suite.NoError(err)

gblocAors, err := models.FetchGblocAorsByJppsoCodeRateAreaDept(suite.DB(), jppsoRegion.ID, oconusRateArea.ID, models.DepartmentIndicatorARMY.String())
suite.NotNil(gblocAors)
suite.NoError(err)
}
12 changes: 12 additions & 0 deletions pkg/models/jppso_regions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package models_test

import (
"github.com/transcom/mymove/pkg/models"
)

func (suite *ModelSuite) TestFetchJppsoRegionByCode() {
jppsoRegion, err := models.FetchJppsoRegionByCode(suite.DB(), "MAPK")
suite.NotNil(jppsoRegion)
suite.NoError(err)
suite.Equal("USCG Base Ketchikan", jppsoRegion.Name)
}
14 changes: 14 additions & 0 deletions pkg/models/re_oconus_rate_areas_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package models_test

import (
"github.com/transcom/mymove/pkg/models"
)

func (suite *ModelSuite) TestFetchOconusRateAreaByCityId() {
usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), "99801")
suite.NotNil(usprc)
suite.FatalNoError(err)
oconusRateArea, err := models.FetchOconusRateAreaByCityId(suite.DB(), usprc.ID.String())
suite.NotNil(oconusRateArea)
suite.NoError(err)
}
9 changes: 9 additions & 0 deletions pkg/models/us_post_region_city_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ func (suite *ModelSuite) TestFindByZipCode() {
suite.NoError(err)
suite.Equal("LOS ANGELES", usPostRegionCity.UsprcCountyNm)
}

func (suite *ModelSuite) TestFindByZipCodeAndCity() {

// Attempt to gather 99677's County from the 99677 zip code and CORDOVA city
usPostRegionCity, err := models.FindByZipCodeAndCity(suite.DB(), "99677", "CORDOVA")
suite.NotNil(usPostRegionCity)
suite.NoError(err)
suite.Equal("CHUGACH", usPostRegionCity.UsprcCountyNm)
}

0 comments on commit 9aaa013

Please sign in to comment.