Skip to content

Commit

Permalink
Merge branch 'main' into B-21436-Allow-AK-To-Be-Entered
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci authored Oct 14, 2024
2 parents 504f758 + 922b08d commit 8a2f5f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1001,3 +1001,4 @@
20240917165710_update_duty_locations_provides_services_counseling.up.sql
20240930171315_updatePostalCodeToGbloc233BGNC.up.sql
20241001174400_add_is_oconus_column.up.sql
20241001193619_market-code-enum.up.sql
4 changes: 4 additions & 0 deletions migrations/app/schema/20241001193619_market-code-enum.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- create and set market code
create type market_code_enum as enum ('i', 'd');
ALTER TABLE mto_shipments ADD COLUMN IF NOT EXISTS market_code market_code_enum;
COMMENT ON COLUMN mto_shipments.market_code IS 'Market code indicator for the shipment. i for international and d for destination.';
17 changes: 17 additions & 0 deletions pkg/models/mto_shipments.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ const (
NTSrRaw = "HHG_OUTOF_NTS_DOMESTIC"
)

// Market code indicator of international or domestic
type MarketCode string

const (
MarketCodeDomestic MarketCode = "d" // domestic
MarketCodeInternational MarketCode = "i" // international
)

const (
// MTOShipmentTypeHHG is an HHG Shipment Type default
MTOShipmentTypeHHG MTOShipmentType = "HHG"
Expand Down Expand Up @@ -160,6 +168,7 @@ type MTOShipment struct {
OriginSITAuthEndDate *time.Time `db:"origin_sit_auth_end_date"`
DestinationSITAuthEndDate *time.Time `db:"dest_sit_auth_end_date"`
MobileHome *MobileHome `has_one:"mobile_home" fk_id:"shipment_id"`
MarketCode *MarketCode `db:"market_code"`
}

// TableName overrides the table name used by Pop.
Expand Down Expand Up @@ -239,6 +248,14 @@ func (m *MTOShipment) Validate(_ *pop.Connection) (*validate.Errors, error) {
string(DestinationTypeOtherThanAuthorized),
}})

// Validate MarketCode if exists
if m.MarketCode != nil {
vs = append(vs, &validators.StringInclusion{Field: string(*m.MarketCode), Name: "MarketCode", List: []string{
string(MarketCodeDomestic),
string(MarketCodeInternational),
}})
}

return validate.Validate(vs...), nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/models/mto_shipments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() {
sitDaysAllowance := 90
tacType := models.LOATypeHHG
sacType := models.LOATypeHHG
marketCode := models.MarketCodeDomestic
validMTOShipment := models.MTOShipment{
MoveTaskOrderID: uuid.Must(uuid.NewV4()),
Status: models.MTOShipmentStatusApproved,
Expand All @@ -23,6 +24,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() {
SITDaysAllowance: &sitDaysAllowance,
TACType: &tacType,
SACType: &sacType,
MarketCode: &marketCode,
}
expErrors := map[string][]string{}
suite.verifyValidationErrors(&validMTOShipment, expErrors)
Expand All @@ -39,9 +41,11 @@ func (suite *ModelSuite) TestMTOShipmentValidation() {

suite.Run("test rejected MTOShipment", func() {
rejectionReason := "bad shipment"
marketCode := models.MarketCodeDomestic
rejectedMTOShipment := models.MTOShipment{
MoveTaskOrderID: uuid.Must(uuid.NewV4()),
Status: models.MTOShipmentStatusRejected,
MarketCode: &marketCode,
RejectionReason: &rejectionReason,
}
expErrors := map[string][]string{}
Expand All @@ -57,6 +61,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() {
sitDaysAllowance := -1
serviceOrderNumber := ""
tacType := models.LOAType("FAKE")
marketCode := models.MarketCode("x")
invalidMTOShipment := models.MTOShipment{
MoveTaskOrderID: uuid.Must(uuid.NewV4()),
Status: models.MTOShipmentStatusRejected,
Expand All @@ -69,6 +74,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() {
StorageFacilityID: &uuid.Nil,
TACType: &tacType,
SACType: &tacType,
MarketCode: &marketCode,
}
expErrors := map[string][]string{
"prime_estimated_weight": {"-1000 is not greater than 0."},
Expand All @@ -81,6 +87,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() {
"storage_facility_id": {"StorageFacilityID can not be blank."},
"tactype": {"TACType is not in the list [HHG, NTS]."},
"sactype": {"SACType is not in the list [HHG, NTS]."},
"market_code": {"MarketCode is not in the list [d, i]."},
}
suite.verifyValidationErrors(&invalidMTOShipment, expErrors)
})
Expand Down

0 comments on commit 8a2f5f5

Please sign in to comment.