Skip to content

Commit

Permalink
Merge pull request #14051 from transcom/INT-B-21526-Added-test-from-main
Browse files Browse the repository at this point in the history
INT  - added test for b-21526
  • Loading branch information
taeJungCaci authored Oct 29, 2024
2 parents 6988a4a + 240cfff commit bcbc349
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 37 deletions.
44 changes: 22 additions & 22 deletions pkg/handlers/internalapi/internal/payloads/model_to_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,6 @@ import (
"github.com/transcom/mymove/pkg/models"
)

func (suite *PayloadsSuite) TestMarketCode() {
suite.Run("returns nil when marketCode is nil", func() {
var marketCode *models.MarketCode = nil
result := MarketCode(marketCode)
suite.Equal(result, "")
})

suite.Run("returns string when marketCode is not nil", func() {
marketCodeDomestic := models.MarketCodeDomestic
result := MarketCode(&marketCodeDomestic)
suite.NotNil(result, "Expected result to not be nil when marketCode is not nil")
suite.Equal("d", result, "Expected result to be 'd' for domestic market code")
})

suite.Run("returns string when marketCode is international", func() {
marketCodeInternational := models.MarketCodeInternational
result := MarketCode(&marketCodeInternational)
suite.NotNil(result, "Expected result to not be nil when marketCode is not nil")
suite.Equal("i", result, "Expected result to be 'i' for international market code")
})
}

func (suite *PayloadsSuite) TestFetchPPMShipment() {

ppmShipmentID, _ := uuid.NewV4()
Expand Down Expand Up @@ -88,3 +66,25 @@ func (suite *PayloadsSuite) TestFetchPPMShipment() {
suite.True(*returnedPPMShipment.IsActualExpenseReimbursement)
})
}

func (suite *PayloadsSuite) TestMarketCode() {
suite.Run("returns nil when marketCode is nil", func() {
var marketCode *models.MarketCode = nil
result := MarketCode(marketCode)
suite.Equal(result, "")
})

suite.Run("returns string when marketCode is not nil", func() {
marketCodeDomestic := models.MarketCodeDomestic
result := MarketCode(&marketCodeDomestic)
suite.NotNil(result, "Expected result to not be nil when marketCode is not nil")
suite.Equal("d", result, "Expected result to be 'd' for domestic market code")
})

suite.Run("returns string when marketCode is international", func() {
marketCodeInternational := models.MarketCodeInternational
result := MarketCode(&marketCodeInternational)
suite.NotNil(result, "Expected result to not be nil when marketCode is not nil")
suite.Equal("i", result, "Expected result to be 'i' for international market code")
})
}
122 changes: 122 additions & 0 deletions pkg/handlers/internalapi/internal/payloads/payload_to_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/transcom/mymove/pkg/gen/internalmessages"
"github.com/transcom/mymove/pkg/handlers"
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/unit"
)

func (suite *PayloadsSuite) TestAddressModel() {
Expand Down Expand Up @@ -328,3 +329,124 @@ func (suite *PayloadsSuite) TestPPMShipmentModelWithOptionalDestinationStreet1Fr
model3 := UpdatePPMShipmentModel(&ppmShipmentValidDestAddress1)
suite.Equal(model3.DestinationAddress.StreetAddress1, streetAddress1)
}

func (suite *PayloadsSuite) TestPPMShipmentModelFromUpdate() {
time := time.Now()
expectedDepartureDate := handlers.FmtDatePtr(&time)
estimatedWeight := int64(5000)
proGearWeight := int64(500)
spouseProGearWeight := int64(50)

address := models.Address{
StreetAddress1: "some address",
City: "city",
State: "state",
PostalCode: "12345",
Country: &models.Country{Country: "US"},
}
address2 := models.Address{
StreetAddress1: "some address",
City: "city",
State: "state",
PostalCode: "11111",
}
address3 := models.Address{
StreetAddress1: "some address",
City: "city",
State: "state",
PostalCode: "54321",
}

var pickupAddress internalmessages.Address
var secondaryPickupAddress internalmessages.Address
var tertiaryPickupAddress internalmessages.Address
var destinationAddress internalmessages.PPMDestinationAddress
var secondaryDestinationAddress internalmessages.Address
var tertiaryDestinationAddress internalmessages.Address

pickupAddress = internalmessages.Address{
City: &address.City,
Country: &address.Country.Country,
PostalCode: &address.PostalCode,
State: &address.State,
StreetAddress1: &address.StreetAddress1,
StreetAddress2: address.StreetAddress2,
StreetAddress3: address.StreetAddress3,
}
destinationAddress = internalmessages.PPMDestinationAddress{
City: &address.City,
Country: &address.Country.Country,
PostalCode: &address.PostalCode,
State: &address.State,
StreetAddress1: &address.StreetAddress1,
StreetAddress2: address.StreetAddress2,
StreetAddress3: address.StreetAddress3,
}
secondaryPickupAddress = internalmessages.Address{
City: &address2.City,
Country: &address.Country.Country,
PostalCode: &address2.PostalCode,
State: &address2.State,
StreetAddress1: &address2.StreetAddress1,
StreetAddress2: address2.StreetAddress2,
StreetAddress3: address2.StreetAddress3,
}
secondaryDestinationAddress = internalmessages.Address{
City: &address2.City,
Country: &address.Country.Country,
PostalCode: &address2.PostalCode,
State: &address2.State,
StreetAddress1: &address2.StreetAddress1,
StreetAddress2: address2.StreetAddress2,
StreetAddress3: address2.StreetAddress3,
}
tertiaryPickupAddress = internalmessages.Address{
City: &address3.City,
Country: &address.Country.Country,
PostalCode: &address3.PostalCode,
State: &address3.State,
StreetAddress1: &address3.StreetAddress1,
StreetAddress2: address3.StreetAddress2,
StreetAddress3: address3.StreetAddress3,
}
tertiaryDestinationAddress = internalmessages.Address{
City: &address3.City,
Country: &address.Country.Country,
PostalCode: &address3.PostalCode,
State: &address3.State,
StreetAddress1: &address3.StreetAddress1,
StreetAddress2: address3.StreetAddress2,
StreetAddress3: address3.StreetAddress3,
}

ppmShipment := internalmessages.UpdatePPMShipment{
ExpectedDepartureDate: expectedDepartureDate,
PickupAddress: &pickupAddress,
SecondaryPickupAddress: &secondaryPickupAddress,
TertiaryPickupAddress: &tertiaryPickupAddress,
DestinationAddress: &destinationAddress,
SecondaryDestinationAddress: &secondaryDestinationAddress,
TertiaryDestinationAddress: &tertiaryDestinationAddress,
SitExpected: models.BoolPointer(true),
EstimatedWeight: &estimatedWeight,
HasProGear: models.BoolPointer(true),
ProGearWeight: &proGearWeight,
SpouseProGearWeight: &spouseProGearWeight,
IsActualExpenseReimbursement: models.BoolPointer(true),
}

model := UpdatePPMShipmentModel(&ppmShipment)

suite.NotNil(model)
suite.True(*model.SITExpected)
suite.Equal(unit.Pound(estimatedWeight), *model.EstimatedWeight)
suite.True(*model.HasProGear)
suite.Equal(unit.Pound(proGearWeight), *model.ProGearWeight)
suite.Equal(unit.Pound(spouseProGearWeight), *model.SpouseProGearWeight)
suite.Nil(model.HasSecondaryPickupAddress)
suite.Nil(model.HasSecondaryDestinationAddress)
suite.Nil(model.HasTertiaryPickupAddress)
suite.Nil(model.HasTertiaryDestinationAddress)
suite.True(*model.IsActualExpenseReimbursement)
suite.NotNil(model)
}
43 changes: 37 additions & 6 deletions pkg/handlers/primeapi/payloads/payload_to_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,13 @@ func (suite *PayloadsSuite) TestPPMShipmentModelFromCreate() {
spouseProGearWeight := int64(50)

ppmShipment := primemessages.CreatePPMShipment{
ExpectedDepartureDate: expectedDepartureDate,
SitExpected: &sitExpected,
EstimatedWeight: &estimatedWeight,
HasProGear: &hasProGear,
ProGearWeight: &proGearWeight,
SpouseProGearWeight: &spouseProGearWeight,
ExpectedDepartureDate: expectedDepartureDate,
SitExpected: &sitExpected,
EstimatedWeight: &estimatedWeight,
HasProGear: &hasProGear,
ProGearWeight: &proGearWeight,
SpouseProGearWeight: &spouseProGearWeight,
IsActualExpenseReimbursement: models.BoolPointer(true),
}

model := PPMShipmentModelFromCreate(&ppmShipment)
Expand All @@ -518,6 +519,36 @@ func (suite *PayloadsSuite) TestPPMShipmentModelFromCreate() {
suite.True(*model.HasProGear)
suite.Equal(unit.Pound(proGearWeight), *model.ProGearWeight)
suite.Equal(unit.Pound(spouseProGearWeight), *model.SpouseProGearWeight)
suite.True(*model.IsActualExpenseReimbursement)
}

func (suite *PayloadsSuite) TestPPMShipmentModelFromUpdate() {
time := time.Now()
expectedDepartureDate := handlers.FmtDatePtr(&time)
estimatedWeight := int64(5000)
proGearWeight := int64(500)
spouseProGearWeight := int64(50)

ppmShipment := primemessages.UpdatePPMShipment{
ExpectedDepartureDate: expectedDepartureDate,
SitExpected: models.BoolPointer(true),
EstimatedWeight: &estimatedWeight,
HasProGear: models.BoolPointer(true),
ProGearWeight: &proGearWeight,
SpouseProGearWeight: &spouseProGearWeight,
IsActualExpenseReimbursement: models.BoolPointer(true),
}

model := PPMShipmentModelFromUpdate(&ppmShipment)

suite.NotNil(model)
suite.True(*model.SITExpected)
suite.Equal(unit.Pound(estimatedWeight), *model.EstimatedWeight)
suite.True(*model.HasProGear)
suite.Equal(unit.Pound(proGearWeight), *model.ProGearWeight)
suite.Equal(unit.Pound(spouseProGearWeight), *model.SpouseProGearWeight)
suite.True(*model.IsActualExpenseReimbursement)
suite.NotNil(model)
}

func (suite *PayloadsSuite) TestCountryModel_WithValidCountry() {
Expand Down
43 changes: 37 additions & 6 deletions pkg/handlers/primeapiv2/payloads/payload_to_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,13 @@ func (suite *PayloadsSuite) TestPPMShipmentModelFromCreate() {
spouseProGearWeight := int64(50)

ppmShipment := primev2messages.CreatePPMShipment{
ExpectedDepartureDate: expectedDepartureDate,
SitExpected: &sitExpected,
EstimatedWeight: &estimatedWeight,
HasProGear: &hasProGear,
ProGearWeight: &proGearWeight,
SpouseProGearWeight: &spouseProGearWeight,
ExpectedDepartureDate: expectedDepartureDate,
SitExpected: &sitExpected,
EstimatedWeight: &estimatedWeight,
HasProGear: &hasProGear,
ProGearWeight: &proGearWeight,
SpouseProGearWeight: &spouseProGearWeight,
IsActualExpenseReimbursement: models.BoolPointer(true),
}

model := PPMShipmentModelFromCreate(&ppmShipment)
Expand All @@ -486,6 +487,36 @@ func (suite *PayloadsSuite) TestPPMShipmentModelFromCreate() {
suite.True(*model.HasProGear)
suite.Equal(unit.Pound(proGearWeight), *model.ProGearWeight)
suite.Equal(unit.Pound(spouseProGearWeight), *model.SpouseProGearWeight)
suite.True(*model.IsActualExpenseReimbursement)
}

func (suite *PayloadsSuite) TestPPMShipmentModelFromUpdate() {
time := time.Now()
expectedDepartureDate := handlers.FmtDatePtr(&time)
estimatedWeight := int64(5000)
proGearWeight := int64(500)
spouseProGearWeight := int64(50)

ppmShipment := primev2messages.UpdatePPMShipment{
ExpectedDepartureDate: expectedDepartureDate,
SitExpected: models.BoolPointer(true),
EstimatedWeight: &estimatedWeight,
HasProGear: models.BoolPointer(true),
ProGearWeight: &proGearWeight,
SpouseProGearWeight: &spouseProGearWeight,
IsActualExpenseReimbursement: models.BoolPointer(true),
}

model := PPMShipmentModelFromUpdate(&ppmShipment)

suite.NotNil(model)
suite.True(*model.SITExpected)
suite.Equal(unit.Pound(estimatedWeight), *model.EstimatedWeight)
suite.True(*model.HasProGear)
suite.Equal(unit.Pound(proGearWeight), *model.ProGearWeight)
suite.Equal(unit.Pound(spouseProGearWeight), *model.SpouseProGearWeight)
suite.True(*model.IsActualExpenseReimbursement)
suite.NotNil(model)
}

func (suite *PayloadsSuite) TestCountryModel_WithValidCountry() {
Expand Down
Loading

0 comments on commit bcbc349

Please sign in to comment.