Skip to content

Commit

Permalink
don't fetch office users with deleted roles
Browse files Browse the repository at this point in the history
  • Loading branch information
loganwc committed Feb 27, 2025
1 parent 7883ac2 commit 401282f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/services/office_user/office_user_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ func (o *officeUserFetcherPop) FetchOfficeUsersWithWorkloadByRoleAndOffice(appCt
office_users.last_name,
COUNT(DISTINCT moves.id) AS workload
FROM office_users
JOIN users_roles ON office_users.user_id = users_roles.user_id
JOIN users_roles
ON (
office_users.user_id = users_roles.user_id AND users_roles.deleted_at IS NULL
)
JOIN roles ON users_roles.role_id = roles.id
JOIN transportation_offices ON office_users.transportation_office_id = transportation_offices.id
LEFT JOIN moves
Expand Down
26 changes: 26 additions & 0 deletions pkg/services/office_user/office_user_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package officeuser
import (
"errors"
"reflect"
"time"

"github.com/gobuffalo/validate/v3"
"github.com/gofrs/uuid"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/transcom/mymove/pkg/models/roles"
"github.com/transcom/mymove/pkg/services"
"github.com/transcom/mymove/pkg/services/query"
"github.com/transcom/mymove/pkg/testdatagen"
)

type testOfficeUserQueryBuilder struct {
Expand Down Expand Up @@ -159,4 +161,28 @@ func (suite *OfficeUserServiceSuite) TestFetchOfficeUsersWithWorkloadByRoleAndOf
suite.IsType(apperror.NotFoundError{}, err)
suite.Equal(uuid.Nil, officeUser.ID)
})

suite.Run("does not return office users with deleted role", func() {
transportationOffice := factory.BuildTransportationOffice(suite.DB(), nil, nil)
tooRole := factory.FetchOrBuildRoleByRoleType(suite.DB(), roles.RoleTypeTOO)
officeUser := factory.BuildOfficeUser(suite.DB(), []factory.Customization{
{
Model: transportationOffice,
LinkOnly: true,
Type: &factory.TransportationOffices.CounselingOffice,
},
}, nil)
deletedAt := time.Now()
_ = testdatagen.MakeUsersRoles(suite.DB(), testdatagen.Assertions{
User: officeUser.User,
UsersRoles: models.UsersRoles{
RoleID: tooRole.ID,
DeletedAt: &deletedAt,
},
})

fetchedUsers, err := fetcher.FetchOfficeUsersByRoleAndOffice(suite.AppContextForTest(), roles.RoleTypeTOO, officeUser.TransportationOfficeID)
suite.NoError(err)
suite.Len(fetchedUsers, 0)
})
}

0 comments on commit 401282f

Please sign in to comment.