Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B 21445 too bulk data #14492

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/factory/move_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ func BuildMove(db *pop.Connection, customs []Customization, traits []Trait) mode
closeoutOffice = BuildTransportationOffice(db, tempCloseoutOfficeCustoms, nil)
}

var counselingOffice models.TransportationOffice
tempCounselingOfficeCustoms := customs
counselingOfficeResult := findValidCustomization(customs, TransportationOffices.CounselingOffice)
if counselingOfficeResult != nil {
tempCounselingOfficeCustoms = convertCustomizationInList(tempCounselingOfficeCustoms, TransportationOffices.CounselingOffice, TransportationOffice)
counselingOffice = BuildTransportationOffice(db, tempCounselingOfficeCustoms, nil)
}

var scAssignedUser models.OfficeUser
tempSCAssignedUserCustoms := customs
scAssignedUserResult := findValidCustomization(customs, OfficeUsers.SCAssignedUser)
if scAssignedUserResult != nil {
tempSCAssignedUserCustoms = convertCustomizationInList(tempSCAssignedUserCustoms, OfficeUsers.SCAssignedUser, OfficeUser)
scAssignedUser = BuildOfficeUser(db, tempSCAssignedUserCustoms, nil)
}

var defaultReferenceID string
var err error
if db != nil {
Expand Down Expand Up @@ -73,6 +89,16 @@ func BuildMove(db *pop.Connection, customs []Customization, traits []Trait) mode
move.CloseoutOfficeID = &closeoutOffice.ID
}

if counselingOfficeResult != nil {
move.CounselingOffice = &counselingOffice
move.CounselingOfficeID = &counselingOffice.ID
}

if scAssignedUserResult != nil {
move.SCAssignedUser = &scAssignedUser
move.SCAssignedID = &scAssignedUser.ID
}

// Overwrite values with those from assertions
testdatagen.MergeModels(&move, cMove)

Expand Down Expand Up @@ -165,6 +191,8 @@ func BuildMoveWithShipment(db *pop.Connection, customs []Customization, traits [
return move
}
func BuildMoveWithPPMShipment(db *pop.Connection, customs []Customization, traits []Trait) models.Move {
// Please note this function runs BuildMove 3 times
// Once here, once in buildMTOShipmentWithBuildType, and once in BuildPPMShipment
move := BuildMove(db, customs, traits)

mtoShipment := buildMTOShipmentWithBuildType(db, customs, traits, mtoShipmentPPM)
Expand Down
18 changes: 18 additions & 0 deletions pkg/factory/move_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/models/roles"
)

func (suite *FactorySuite) TestBuildMove() {
Expand Down Expand Up @@ -258,6 +259,23 @@ func (suite *FactorySuite) TestBuildMove() {
suite.NotNil(move.AvailableToPrimeAt)
suite.NotNil(move.ApprovedAt)
})
suite.Run("Successful creation of a move with an assigned SC", func() {
officeUser := BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeServicesCounselor})

move := BuildMoveWithShipment(suite.DB(), []Customization{
{
Model: models.Move{
Status: models.MoveStatusNeedsServiceCounseling,
},
},
{
Model: officeUser,
LinkOnly: true,
Type: &OfficeUsers.SCAssignedUser,
},
}, nil)
suite.Equal(officeUser.ID, *move.SCAssignedID)
})
suite.Run("Successful creation of move with shipment", func() {
// Under test: BuildMoveWithShipment
// Set up: Create a move using BuildMoveWithShipment
Expand Down
43 changes: 40 additions & 3 deletions pkg/factory/office_user_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,25 @@ func BuildOfficeUser(db *pop.Connection, customs []Customization, traits []Trait
// Find/create the user model
user := BuildUserAndUsersRoles(db, customs, nil)

// Find/create the TransportationOffice model
transportationOffice := BuildTransportationOffice(db, customs, nil)
var transportationOffice models.TransportationOffice

tempCloseoutOfficeCustoms := customs
closeoutOfficeResult := findValidCustomization(customs, TransportationOffices.CloseoutOffice)
if closeoutOfficeResult != nil {
tempCloseoutOfficeCustoms = convertCustomizationInList(tempCloseoutOfficeCustoms, TransportationOffices.CloseoutOffice, TransportationOffice)
transportationOffice = BuildTransportationOffice(db, tempCloseoutOfficeCustoms, nil)
}

tempCounselingOfficeCustoms := customs
counselingOfficeResult := findValidCustomization(customs, TransportationOffices.CounselingOffice)
if counselingOfficeResult != nil {
tempCounselingOfficeCustoms = convertCustomizationInList(tempCounselingOfficeCustoms, TransportationOffices.CounselingOffice, TransportationOffice)
transportationOffice = BuildTransportationOffice(db, tempCounselingOfficeCustoms, nil)
}

if closeoutOfficeResult == nil && counselingOfficeResult == nil {
transportationOffice = BuildTransportationOffice(db, customs, nil)
}

// create officeuser
officeUser := models.OfficeUser{
Expand All @@ -51,6 +68,7 @@ func BuildOfficeUser(db *pop.Connection, customs []Customization, traits []Trait
TransportationOffice: transportationOffice,
TransportationOfficeID: transportationOffice.ID,
}

// Overwrite values with those from assertions
testdatagen.MergeModels(&officeUser, cOfficeUser)

Expand Down Expand Up @@ -200,7 +218,25 @@ func BuildOfficeUserWithPrivileges(db *pop.Connection, customs []Customization,
user := BuildUserAndUsersRolesAndUsersPrivileges(db, customs, nil)

// Find/create the TransportationOffice model
transportationOffice := BuildTransportationOffice(db, customs, nil)
var transportationOffice models.TransportationOffice

tempCloseoutOfficeCustoms := customs
closeoutOfficeResult := findValidCustomization(customs, TransportationOffices.CloseoutOffice)
if closeoutOfficeResult != nil {
tempCloseoutOfficeCustoms = convertCustomizationInList(tempCloseoutOfficeCustoms, TransportationOffices.CloseoutOffice, TransportationOffice)
transportationOffice = BuildTransportationOffice(db, tempCloseoutOfficeCustoms, nil)
}

tempCounselingOfficeCustoms := customs
counselingOfficeResult := findValidCustomization(customs, TransportationOffices.CounselingOffice)
if counselingOfficeResult != nil {
tempCounselingOfficeCustoms = convertCustomizationInList(tempCounselingOfficeCustoms, TransportationOffices.CounselingOffice, TransportationOffice)
transportationOffice = BuildTransportationOffice(db, tempCounselingOfficeCustoms, nil)
}

if closeoutOfficeResult == nil && counselingOfficeResult == nil {
transportationOffice = BuildTransportationOffice(db, customs, nil)
}

// create officeuser
officeUser := models.OfficeUser{
Expand All @@ -213,6 +249,7 @@ func BuildOfficeUserWithPrivileges(db *pop.Connection, customs []Customization,
TransportationOffice: transportationOffice,
TransportationOfficeID: transportationOffice.ID,
}

// Overwrite values with those from assertions
testdatagen.MergeModels(&officeUser, cOfficeUser)

Expand Down
50 changes: 50 additions & 0 deletions pkg/factory/office_user_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,54 @@ func (suite *FactorySuite) TestBuildOfficeUserExtra() {
suite.NoError(err)
suite.Equal(precountUsersRoles, countUsersRoles)
})

suite.Run("Successful creation of OfficeUser using BuildOfficeUserWithPrivileges with customizations", func() {
email := "[email protected]"
transportationOffice := BuildTransportationOffice(suite.DB(), []Customization{
{
Model: models.TransportationOffice{
ProvidesCloseout: true,
},
},
}, nil)
officeUser := BuildOfficeUserWithPrivileges(suite.DB(), []Customization{
{
Model: models.OfficeUser{
FirstName: "Riley",
Email: email,
},
},
{
Model: transportationOffice,
LinkOnly: true,
Type: &TransportationOffices.CloseoutOffice,
},
{
Model: models.User{
OktaEmail: email,
Privileges: []models.Privilege{
{
PrivilegeType: models.PrivilegeTypeSupervisor,
},
},
Roles: []roles.Role{
{
RoleType: roles.RoleTypeServicesCounselor,
},
},
},
},
}, nil)

// Check that the user has the office user role
_, hasRole := officeUser.User.Roles.GetRole(roles.RoleTypeServicesCounselor)
_, hasPrivilege := officeUser.User.Privileges.GetPrivilege(models.PrivilegeTypeSupervisor)
suite.True(hasRole)
suite.True(hasPrivilege)
// Check customizations
suite.Equal(email, officeUser.User.OktaEmail)
suite.Equal(email, officeUser.Email)
suite.Equal("Riley", officeUser.FirstName)
suite.Equal(transportationOffice.ID, officeUser.TransportationOfficeID)
})
}
10 changes: 10 additions & 0 deletions pkg/factory/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,23 @@ type transportationOfficeGroup struct {
OriginDutyLocation CustomType
NewDutyLocation CustomType
CloseoutOffice CustomType
CounselingOffice CustomType
}

// TransportationOffices is the struct to access the fields externally
var TransportationOffices = transportationOfficeGroup{
OriginDutyLocation: "OriginDutyLocationTransportationOffice",
NewDutyLocation: "NewDutyLocationTransportationOffice",
CloseoutOffice: "CloseoutOffice",
CounselingOffice: "CounselingOffice",
}

type officeUserGroup struct {
SCAssignedUser CustomType
}

var OfficeUsers = officeUserGroup{
SCAssignedUser: "SCAssignedUser",
}

// uploadGroup is a grouping of all the upload related fields
Expand Down
5 changes: 5 additions & 0 deletions pkg/gen/ghcapi/configure_mymove.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ func configureAPI(api *ghcoperations.MymoveAPI) http.Handler {
return middleware.NotImplemented("operation re_service_items.GetAllReServiceItems has not yet been implemented")
})
}
if api.QueuesGetBulkAssignmentDataHandler == nil {
api.QueuesGetBulkAssignmentDataHandler = queues.GetBulkAssignmentDataHandlerFunc(func(params queues.GetBulkAssignmentDataParams) middleware.Responder {
return middleware.NotImplemented("operation queues.GetBulkAssignmentData has not yet been implemented")
})
}
if api.CustomerGetCustomerHandler == nil {
api.CustomerGetCustomerHandler = customer.GetCustomerHandlerFunc(func(params customer.GetCustomerParams) middleware.Responder {
return middleware.NotImplemented("operation customer.GetCustomer has not yet been implemented")
Expand Down
Loading
Loading