Skip to content

Commit

Permalink
INT-B-18881 Add Search SC (#12045)
Browse files Browse the repository at this point in the history
* added search tab to SC queue

* cleaned up css

* added test

* moved tabs from movesearch component into the ServicesCounselorQueue and removed tabs from TableQueue

* removed old css and clean up

* added status filtering based on office role

* search queue now only shows results for services counselors when appropriate

* removed empty test

* added/updated move searcher tests

* minor fix to move searcher test

* clean up

* renamed search query

* fixed filtering on services counselor

* added submitted and approved status to move searcher query for services counselor and updated tab names

* removed submitted status, shouldn't be there

* removed submitted status

* update tests to match new tab names

* fixed issue when filtering in search where you can't clear filters if there's no results, fixed pagination being blocked by QueryDevTools, added all statuses for SC search, cleaned up query for search

* readded no results text to queue

* fixed playwright test
  • Loading branch information
loganwc authored Feb 28, 2024
1 parent 629950e commit 748f738
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 129 deletions.
10 changes: 8 additions & 2 deletions pkg/gen/ghcapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/gen/ghcapi/ghcoperations/move/search_moves.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 20 additions & 15 deletions pkg/services/move/move_searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/transcom/mymove/pkg/appcontext"
"github.com/transcom/mymove/pkg/apperror"
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/models/roles"
"github.com/transcom/mymove/pkg/services"
)

Expand Down Expand Up @@ -47,21 +48,25 @@ func (s moveSearcher) SearchMoves(appCtx appcontext.AppContext, params *services
return nil, 0, err
}

query := appCtx.DB().EagerPreload(
"MTOShipments",
"Orders.ServiceMember",
"Orders.NewDutyLocation.Address",
"Orders.OriginDutyLocation.Address",
).
Join("orders", "orders.id = moves.orders_id").
Join("service_members", "service_members.id = orders.service_member_id").
LeftJoin("duty_locations as origin_duty_locations", "origin_duty_locations.id = orders.origin_duty_location_id").
Join("addresses as origin_addresses", "origin_addresses.id = origin_duty_locations.address_id").
Join("duty_locations as new_duty_locations", "new_duty_locations.id = orders.new_duty_location_id").
Join("addresses as new_addresses", "new_addresses.id = new_duty_locations.address_id").
LeftJoin("mto_shipments", "mto_shipments.move_id = moves.id AND mto_shipments.status <> 'DRAFT'").
GroupBy("moves.id", "service_members.id", "origin_addresses.id", "new_addresses.id").
Where("show = TRUE")
var query *pop.Query

if appCtx.Session().Roles.HasRole(roles.RoleTypeQaeCsr) || appCtx.Session().Roles.HasRole(roles.RoleTypeServicesCounselor) {
query = appCtx.DB().EagerPreload(
"MTOShipments",
"Orders.ServiceMember",
"Orders.NewDutyLocation.Address",
"Orders.OriginDutyLocation.Address",
).
Join("orders", "orders.id = moves.orders_id").
Join("service_members", "service_members.id = orders.service_member_id").
LeftJoin("duty_locations as origin_duty_locations", "origin_duty_locations.id = orders.origin_duty_location_id").
Join("addresses as origin_addresses", "origin_addresses.id = origin_duty_locations.address_id").
Join("duty_locations as new_duty_locations", "new_duty_locations.id = orders.new_duty_location_id").
Join("addresses as new_addresses", "new_addresses.id = new_duty_locations.address_id").
LeftJoin("mto_shipments", "mto_shipments.move_id = moves.id AND mto_shipments.status <> 'DRAFT'").
GroupBy("moves.id", "service_members.id", "origin_addresses.id", "new_addresses.id").
Where("show = TRUE")
}

customerNameQuery := customerNameSearch(params.CustomerName)
locatorQuery := locatorFilter(params.Locator)
Expand Down
102 changes: 92 additions & 10 deletions pkg/services/move/move_searcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@ package move
import (
"fmt"

"github.com/transcom/mymove/pkg/auth"
"github.com/transcom/mymove/pkg/factory"
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/models/roles"
"github.com/transcom/mymove/pkg/services"
)

func (suite *MoveServiceSuite) TestMoveSearch() {
searcher := NewMoveSearcher()

suite.Run("search with no filters should fail", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Move{
Expand All @@ -28,10 +39,19 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
},
}, nil)

_, _, err := searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{})
_, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{})
suite.Error(err)
})
suite.Run("search with valid locator", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

firstMove := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Move{
Expand All @@ -48,12 +68,21 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
},
}, nil)

moves, _, err := searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{Locator: &firstMove.Locator})
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{Locator: &firstMove.Locator})
suite.NoError(err)
suite.Len(moves, 1)
suite.Equal(firstMove.Locator, moves[0].Locator)
})
suite.Run("search with valid DOD ID", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Move{
Expand All @@ -70,12 +99,21 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
},
}, nil)

moves, _, err := searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{DodID: secondMove.Orders.ServiceMember.Edipi})
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{DodID: secondMove.Orders.ServiceMember.Edipi})
suite.NoError(err)
suite.Len(moves, 1)
suite.Equal(secondMove.Locator, moves[0].Locator)
})
suite.Run("search with customer name", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

firstMove := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Move{
Expand All @@ -98,12 +136,20 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
},
}, nil)

moves, _, err := searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{CustomerName: models.StringPointer("Grace Griffin")})
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{CustomerName: models.StringPointer("Grace Griffin")})
suite.NoError(err)
suite.Len(moves, 1)
suite.Equal(firstMove.Locator, moves[0].Locator)
})
suite.Run("search with both DOD ID and locator filters should fail", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

firstMove := factory.BuildMove(suite.DB(), []factory.Customization{
{
Expand All @@ -122,20 +168,38 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
}, nil)

// Search for Locator of one move and DOD ID of another move
_, _, err := searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{
_, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{
Locator: &firstMove.Locator,
DodID: secondMove.Orders.ServiceMember.Edipi,
})
suite.Error(err)
})
suite.Run("search with no results", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

nonexistantLocator := "CCCCCC"
moves, _, err := searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{Locator: &nonexistantLocator})
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{Locator: &nonexistantLocator})
suite.NoError(err)
suite.Len(moves, 0)
})

suite.Run("test pagination", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

firstMove := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Move{
Expand Down Expand Up @@ -164,7 +228,7 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
},
}, nil)
// get first page
moves, totalCount, err := searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{
moves, totalCount, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{
CustomerName: models.StringPointer("grace griffin"),
PerPage: 1,
Page: 1,
Expand All @@ -175,7 +239,7 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
suite.Equal(2, totalCount)

// get second page
moves, totalCount, err = searcher.SearchMoves(suite.AppContextForTest(), &services.SearchMovesParams{
moves, totalCount, err = searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{
CustomerName: models.StringPointer("grace griffin"),
PerPage: 1,
Page: 2,
Expand Down Expand Up @@ -300,6 +364,15 @@ func (suite *MoveServiceSuite) TestMoveSearchOrdering() {
testMoves := models.Moves{}
suite.NoError(suite.DB().EagerPreload("Orders", "Orders.NewDutyLocation", "Orders.NewDutyLocation.Address").All(&testMoves))

qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

searcher := NewMoveSearcher()
columns := []string{"status", "originPostalCode", "destinationPostalCode", "branch", "shipmentsCount"}
for _, order := range []string{"asc", "desc"} {
Expand All @@ -310,7 +383,7 @@ func (suite *MoveServiceSuite) TestMoveSearchOrdering() {
Sort: &columns[ci],
Order: &order,
}
moves, _, err := searcher.SearchMoves(suite.AppContextForTest(), &params)
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &params)
suite.NoError(err)
suite.Len(moves, 2)
message := fmt.Sprintf("Sort by %s, %s failed", col, order)
Expand All @@ -329,6 +402,15 @@ func (suite *MoveServiceSuite) TestMoveSearchOrdering() {
nameToSearch := "maria johnson"
searcher := NewMoveSearcher()

qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQaeCsr})
session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

cases := []struct {
column string
value string
Expand All @@ -342,7 +424,7 @@ func (suite *MoveServiceSuite) TestMoveSearchOrdering() {
}
for _, testCase := range cases {
message := fmt.Sprintf("Filtering results of search by column %s = %s has failed", testCase.column, testCase.value)
moves, _, err := searcher.SearchMoves(suite.AppContextForTest(), &testCase.SearchMovesParams)
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &testCase.SearchMovesParams)
suite.NoError(err)
suite.Len(moves, 1, message)
suite.Equal(secondMove.Locator, moves[0].Locator, message)
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/office/qaecsr/moveSearchFlows.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ test.describe('QAE/CSR Move Search', () => {

// Verify no results
await expect(page.locator('[data-testid=table-queue] > h2')).toContainText('Results (0)');
await expect(page.locator('[data-testid=table-queue] > p')).toContainText('No results found.');
await expect(page.locator('[data-testid=table-queue] > h2')).toContainText('No results found.');
});
});
Loading

0 comments on commit 748f738

Please sign in to comment.