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

INT B-21492 Secondary Transportation Office Assignment Assignable by Admin #13964

Draft
wants to merge 7 commits into
base: integrationTesting
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
67 changes: 66 additions & 1 deletion pkg/factory/office_user_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/transcom/mymove/pkg/testdatagen"
)

// BuildOfficeUser creates an OfficeUser
// BuildOfficeUser creates an OfficeUser, and a transportation office and transportation office assignment if either doesn't exist
// Params:
// - customs is a slice that will be modified by the factory
// - db can be set to nil to create a stubbed model that is not stored in DB.
Expand Down Expand Up @@ -59,6 +59,71 @@ func BuildOfficeUser(db *pop.Connection, customs []Customization, traits []Trait
mustCreate(db, &officeUser)
}

BuildPrimaryTransportationOfficeAssignment(db, []Customization{
{
Model: models.OfficeUser{
ID: officeUser.ID,
},
LinkOnly: true,
},
{
Model: models.TransportationOffice{
ID: transportationOffice.ID,
},
LinkOnly: true,
},
}, nil)

return officeUser
}

// BuildOfficeUserWithoutTransportationAssignment creates an OfficeUser
// Params:
// - customs is a slice that will be modified by the factory
// - db can be set to nil to create a stubbed model that is not stored in DB.
// Notes:
// - To build an office user with one or more roles use BuildOfficeUserWithRoles
// - There's a uniqueness constraint on office user emails so use the GetTraitOfficeUserEmail trait
// when creating a test with multiple office users
// - The OfficeUser returned won't have an ID if the db is nil. If an ID is needed for a stubbed user,
// use trait GetTraitOfficeUserWithID
func BuildOfficeUserWithoutTransportationOfficeAssignment(db *pop.Connection, customs []Customization, traits []Trait) models.OfficeUser {
customs = setupCustomizations(customs, traits)

// Find officeuser assertion and convert to models officeuser
var cOfficeUser models.OfficeUser
if result := findValidCustomization(customs, OfficeUser); result != nil {
cOfficeUser = result.Model.(models.OfficeUser)
if result.LinkOnly {
return cOfficeUser
}
}

// Find/create the user model
user := BuildUserAndUsersRoles(db, customs, nil)

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

// create officeuser
officeUser := models.OfficeUser{
UserID: &user.ID,
User: user,
FirstName: "Leo",
LastName: "Spaceman",
Email: "[email protected]",
Telephone: "415-555-1212",
TransportationOffice: transportationOffice,
TransportationOfficeID: transportationOffice.ID,
}
// Overwrite values with those from assertions
testdatagen.MergeModels(&officeUser, cOfficeUser)

// If db is false, it's a stub. No need to create in database
if db != nil {
mustCreate(db, &officeUser)
}

return officeUser
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/factory/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var SITDurationUpdate CustomType = "SITDurationUpdate"
var StorageFacility CustomType = "StorageFacility"
var TransportationAccountingCode CustomType = "TransportationAccountingCode"
var TransportationOffice CustomType = "TransportationOffice"
var TransportationOfficeAssignment CustomType = "TransportationOfficeAssignment"
var Upload CustomType = "Upload"
var UserUpload CustomType = "UserUpload"
var User CustomType = "User"
Expand Down Expand Up @@ -148,6 +149,7 @@ var defaultTypesMap = map[string]CustomType{
"models.TransportationAccountingCode": TransportationAccountingCode,
"models.UsPostRegionCity": UsPostRegionCity,
"models.TransportationOffice": TransportationOffice,
"models.TransportationOfficeAssignment": TransportationOfficeAssignment,
"models.Upload": Upload,
"models.UserUpload": UserUpload,
"models.User": User,
Expand Down
94 changes: 94 additions & 0 deletions pkg/factory/transportation_office_assignment_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package factory

import (
"github.com/gobuffalo/pop/v6"

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

// BuildPrimaryTransportationOfficeAssignment creates a Transportation Assignment, and a transportation office and officer user if either doesn't exist
// Params:
// - customs is a slice that will be modified by the factory
// - db can be set to nil to create a stubbed model that is not stored in DB.
// Notes:
// - Marks the transportation office assignment as the office user's primary transportation office,
// use BuildAlternateTransportationOfficeAssignment for non-primary transportation office.
func BuildPrimaryTransportationOfficeAssignment(db *pop.Connection, customs []Customization, traits []Trait) models.TransportationOfficeAssignment {
customs = setupCustomizations(customs, traits)

// Find TransportationAssignment assertion and convert to models.TransportationOfficeAssignment
var cTransportationOfficeAssignment models.TransportationOfficeAssignment
if result := findValidCustomization(customs, TransportationOfficeAssignment); result != nil {
cTransportationOfficeAssignment = result.Model.(models.TransportationOfficeAssignment)
if result.LinkOnly {
return cTransportationOfficeAssignment
}
}

// Find/Create the associated office user model
officeUser := BuildOfficeUser(db, customs, traits)

// Find/Create the associated transportation office model
transportationOffice := BuildTransportationOffice(db, customs, traits)

// Create transportationOffice
transportationOfficeAssignment := models.TransportationOfficeAssignment{
ID: officeUser.ID,
TransportationOfficeID: transportationOffice.ID,
TransportationOffice: transportationOffice,
PrimaryOffice: true,
}

// Overwrite values with those from customizations
testdatagen.MergeModels(&transportationOfficeAssignment, cTransportationOfficeAssignment)

// If db is false, it's a stub. No need to create in database
if db != nil {
mustCreate(db, &transportationOfficeAssignment)
}
return transportationOfficeAssignment
}

// BuildAlternateTransportationAssignment creates a Transportation Assignment, and a transportation office and officer user if either doesn't exist
// Params:
// - customs is a slice that will be modified by the factory
// - db can be set to nil to create a stubbed model that is not stored in DB.
// Notes:
// - Marks the transportation office assignment as a non-primary transportation office assignment,
// use BuildPrimaryTransportationOfficeAssignment for primary transportation office assignments.
func BuildAlternateTransportationAssignment(db *pop.Connection, customs []Customization, traits []Trait) models.TransportationOfficeAssignment {
customs = setupCustomizations(customs, traits)

// Find TransportationAssignment assertion and convert to models.TransportationAssignment
var cTransportationOfficeAssignment models.TransportationOfficeAssignment
if result := findValidCustomization(customs, TransportationOfficeAssignment); result != nil {
cTransportationOfficeAssignment = result.Model.(models.TransportationOfficeAssignment)
if result.LinkOnly {
return cTransportationOfficeAssignment
}
}

// Find/Create the associated office user model
officeUser := BuildOfficeUser(db, customs, traits)

// Find/Create the associated transportation office model
transportationOffice := BuildTransportationOffice(db, customs, traits)

// Create transportationOffice
transportationOfficeAssignment := models.TransportationOfficeAssignment{
ID: officeUser.ID,
TransportationOfficeID: transportationOffice.ID,
TransportationOffice: transportationOffice,
PrimaryOffice: false,
}

// Overwrite values with those from customizations
testdatagen.MergeModels(&transportationOfficeAssignment, cTransportationOfficeAssignment)

// If db is false, it's a stub. No need to create in database
if db != nil {
mustCreate(db, &transportationOfficeAssignment)
}
return transportationOfficeAssignment
}
Loading