Skip to content

Commit

Permalink
Updated filter & test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JonSpight committed Feb 28, 2025
1 parent 7fa7ca7 commit a727373
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 77 deletions.
74 changes: 0 additions & 74 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,87 +863,13 @@ func (suite *PayloadsSuite) TestSearchMoves() {
},
}, nil)

moveWithShipmentsOfEveryStatus := factory.BuildMove(suite.DB(), nil, nil)
shipmentWithSubmittedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusSubmitted,
},
},
}, nil)
shipmentWithCanceledStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusCanceled,
},
},
}, nil)
rejectionReason := "bad shipment"
shipmentWithRejectedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusRejected,
RejectionReason: &rejectionReason,
},
},
}, nil)
shipmentWithCancellationRequestedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusCancellationRequested,
},
},
}, nil)
shipmentWithApprovedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusApproved,
},
},
}, nil)
moveWithShipmentsOfEveryStatus.MTOShipments = models.MTOShipments{
shipmentWithSubmittedStatus,
shipmentWithCanceledStatus,
shipmentWithRejectedStatus,
shipmentWithCancellationRequestedStatus,
shipmentWithApprovedStatus,
}

moves := models.Moves{moveUSMC}
movesWithShipments := models.Moves{moveWithShipmentsOfEveryStatus}
suite.Run("Success - Returns a ghcmessages Upload payload from Upload Struct Marine move with no shipments", func() {
payload := SearchMoves(appCtx, moves)

suite.IsType(payload, &ghcmessages.SearchMoves{})
suite.NotNil(payload)
})
suite.Run("Success - Returns a ghcmessages Upload payload from Upload Struct Marine move with shipments", func() {
payload := SearchMoves(appCtx, movesWithShipments)

suite.IsType(payload, &ghcmessages.SearchMoves{})
suite.NotNil(payload)
suite.Equal(&(*payload)[0].ShipmentsCount, handlers.FmtInt64(2))
})
}

func (suite *PayloadsSuite) TestMarketCode() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/models/mto_shipments.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ func FetchShipmentByID(db *pop.Connection, shipmentID uuid.UUID) (*MTOShipment,

// filters the returned MtoShipments for each move.
// Ignoring mto shipments that have been deleted, cancelled, rejected, or cancelled requested.
func FilterMtoShipments(unfilteredShipments MTOShipments) MTOShipments {
//filter
func FilterDeletedRejectedCancelledMtoShipments(unfilteredShipments MTOShipments) MTOShipments {
if len(unfilteredShipments) == 0 {
return unfilteredShipments
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/move/move_searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s moveSearcher) SearchMoves(appCtx appcontext.AppContext, params *services

for i := range moves {
if moves[i].MTOShipments != nil {
moves[i].MTOShipments = models.FilterMtoShipments(moves[i].MTOShipments)
moves[i].MTOShipments = models.FilterDeletedRejectedCancelledMtoShipments(moves[i].MTOShipments)
}
}
return moves, query.Paginator.TotalEntriesSize, nil
Expand Down
91 changes: 91 additions & 0 deletions pkg/services/move/move_searcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,97 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
suite.Equal(secondMove.Locator, moves[0].Locator)
suite.Equal(2, totalCount)
})
suite.Run("filtering mto shipments search results", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQae})

session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

moveWithShipmentsOfEveryStatus := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Move{
Locator: "AAAAAA",
},
},
}, nil)

shipmentWithSubmittedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusSubmitted,
},
},
}, nil)
shipmentWithCanceledStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusCanceled,
},
},
}, nil)
rejectionReason := "bad shipment"
shipmentWithRejectedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusRejected,
RejectionReason: &rejectionReason,
},
},
}, nil)
shipmentWithCancellationRequestedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusCancellationRequested,
},
},
}, nil)
shipmentWithApprovedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusApproved,
},
},
}, nil)
moveWithShipmentsOfEveryStatus.MTOShipments = models.MTOShipments{
shipmentWithSubmittedStatus,
shipmentWithCanceledStatus,
shipmentWithRejectedStatus,
shipmentWithCancellationRequestedStatus,
shipmentWithApprovedStatus,
}
filteredShipments := models.FilterDeletedRejectedCancelledMtoShipments(moveWithShipmentsOfEveryStatus.MTOShipments)
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{Locator: &moveWithShipmentsOfEveryStatus.Locator})
suite.NoError(err)
suite.Len(moves, 1)
suite.Len(moves[0].MTOShipments, 2)
suite.Equal(len(filteredShipments), 2)

})
}

func setupTestData(suite *MoveServiceSuite) (models.Move, models.Move, models.MTOShipment) {
Expand Down

0 comments on commit a727373

Please sign in to comment.