Skip to content

Commit

Permalink
Merge branch 'integrationTesting' into b19764-int-20240506-fe-aoa-pac…
Browse files Browse the repository at this point in the history
…ket-change-text
  • Loading branch information
JamesHawks224 authored May 10, 2024
2 parents 9e980ed + 605b601 commit f305bf8
Show file tree
Hide file tree
Showing 27 changed files with 323 additions and 89 deletions.
2 changes: 2 additions & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,5 @@
20240502175909_add_lookup_valid_columns_to_tac_and_loa_tables.up.sql
20240502183613_add_support_for_standalone_payment_cap.up.sql
20240503123556_add_diversion_reason_to_mto_shipments.up.sql
20240506214039_add_submitted_columns_to_ppm_document_tables.up.sql
20240507133524_add_locked_moves_column_to_moves_table.up.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ALTER TABLE application_parameters
ADD COLUMN IF NOT EXISTS parameter_name TEXT NOT NULL,
ADD COLUMN IF NOT EXISTS parameter_value TEXT NOT NULL,
ADD COLUMN IF NOT EXISTS parameter_name TEXT,
ADD COLUMN IF NOT EXISTS parameter_value TEXT,
ALTER COLUMN validation_code DROP NOT NULL;

COMMENT ON COLUMN application_parameters.parameter_name IS 'The name of the parameter';
COMMENT ON COLUMN application_parameters.parameter_value IS 'The value of the parameter';
COMMENT ON COLUMN application_parameters.parameter_value IS 'The value of the parameter';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ALTER TABLE weight_tickets
ADD COLUMN IF NOT EXISTS submitted_empty_weight INT4 DEFAULT NULL,
ADD COLUMN IF NOT EXISTS submitted_full_weight INT4 DEFAULT NULL;

COMMENT ON COLUMN weight_tickets.submitted_empty_weight IS 'Stores the customer submitted empty_weight.';
COMMENT ON COLUMN weight_tickets.submitted_full_weight IS 'Stores the customer submitted full_weight.';

ALTER TABLE progear_weight_tickets ADD COLUMN IF NOT EXISTS submitted_weight INT4 DEFAULT NULL;

COMMENT ON COLUMN progear_weight_tickets.submitted_weight IS 'Stores the customer submitted weight.';

ALTER TABLE moving_expenses
ADD COLUMN IF NOT EXISTS submitted_amount INT4 DEFAULT NULL,
ADD COLUMN IF NOT EXISTS submitted_sit_start_date DATE DEFAULT NULL,
ADD COLUMN IF NOT EXISTS submitted_sit_end_date DATE DEFAULT NULL;

COMMENT ON COLUMN moving_expenses.submitted_amount IS 'Stores the customer submitted amount.';
COMMENT ON COLUMN moving_expenses.submitted_sit_start_date IS 'Stores the customer submitted sit_start_date.';
COMMENT ON COLUMN moving_expenses.submitted_sit_end_date IS 'Stores the customer submitted sit_end_date.';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- These column additions will handle locking a move
-- when an office user is working on them
-- Add columns if they don't exist
ALTER TABLE moves
ADD COLUMN IF NOT EXISTS locked_by UUID NULL,
ADD COLUMN IF NOT EXISTS lock_expires_at TIMESTAMP WITH TIME ZONE NULL;

-- Add foreign key constraint to office_users table
ALTER TABLE moves
ADD CONSTRAINT fk_locked_by
FOREIGN KEY (locked_by)
REFERENCES office_users(id);

-- Add comments for the columns
COMMENT ON COLUMN moves.locked_by IS 'The id of the office user that locked the move.';
COMMENT ON COLUMN moves.lock_expires_at IS 'The expiration time that a move is locked until, the default value of this will be 30 minutes from initial lock.';
1 change: 1 addition & 0 deletions pkg/factory/service_member_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func buildServiceMemberWithBuildType(db *pop.Connection, customs []Customization
PersonalEmail: &email,
ResidentialAddressID: &resAddress.ID,
ResidentialAddress: &resAddress,
CacValidated: false,
}

backupAddressResult := findValidCustomization(customs, Addresses.BackupMailingAddress)
Expand Down
12 changes: 12 additions & 0 deletions pkg/gen/ghcapi/embedded_spec.go

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

3 changes: 3 additions & 0 deletions pkg/gen/ghcmessages/customer.go

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

3 changes: 3 additions & 0 deletions pkg/gen/ghcmessages/update_customer_payload.go

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

12 changes: 8 additions & 4 deletions pkg/gen/internalapi/embedded_spec.go

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

4 changes: 2 additions & 2 deletions pkg/gen/internalmessages/application_parameters.go

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

1 change: 1 addition & 0 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func Customer(customer *models.ServiceMember) *ghcmessages.Customer {
SecondaryTelephone: customer.SecondaryTelephone,
PhoneIsPreferred: swag.BoolValue(customer.PhoneIsPreferred),
EmailIsPreferred: swag.BoolValue(customer.EmailIsPreferred),
CacValidated: swag.BoolValue(&customer.CacValidated),
}
return &payload
}
Expand Down
49 changes: 49 additions & 0 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,55 @@ func (suite *PayloadsSuite) TestProofOfServiceDoc() {
})
}

func (suite *PayloadsSuite) TestCustomer() {
id, _ := uuid.NewV4()
id2, _ := uuid.NewV4()

residentialAddress := models.Address{
StreetAddress1: "123 New St",
City: "Beverly Hills",
State: "CA",
PostalCode: "89503",
Country: models.StringPointer("United States"),
County: *models.StringPointer("WASHOE"),
}

backupAddress := models.Address{
StreetAddress1: "123 Old St",
City: "Beverly Hills",
State: "CA",
PostalCode: "89502",
Country: models.StringPointer("United States"),
County: *models.StringPointer("WASHOE"),
}

phone := "444-555-6677"

firstName := "First"
lastName := "Last"
affiliation := models.AffiliationARMY
email := "[email protected]"
cacValidated := true
customer := models.ServiceMember{
ID: id,
UserID: id2,
FirstName: &firstName,
LastName: &lastName,
Affiliation: &affiliation,
PersonalEmail: &email,
Telephone: &phone,
ResidentialAddress: &residentialAddress,
BackupMailingAddress: &backupAddress,
CacValidated: cacValidated,
}

suite.Run("Success - Returns a ghcmessages Customer payload from Customer Struct", func() {
customer := Customer(&customer)

suite.IsType(customer, &ghcmessages.Customer{})
})
}

func (suite *PayloadsSuite) TestCreateCustomer() {
id, _ := uuid.NewV4()
id2, _ := uuid.NewV4()
Expand Down
1 change: 1 addition & 0 deletions pkg/handlers/ghcapi/internal/payloads/payload_to_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func CustomerToServiceMember(payload ghcmessages.UpdateCustomerPayload) models.S
PhoneIsPreferred: &payload.PhoneIsPreferred,
EmailIsPreferred: &payload.EmailIsPreferred,
BackupMailingAddress: backupAddress,
CacValidated: payload.CacValidated,
}
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/handlers/internalapi/application_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import (
)

func payloadForApplicationParametersModel(v models.ApplicationParameters) internalmessages.ApplicationParameters {

parameterValue := v.ParameterValue
parameterName := v.ParameterName

payload := internalmessages.ApplicationParameters{
ParameterValue: *handlers.FmtString(v.ParameterValue),
ParameterName: *handlers.FmtString(v.ParameterName),
ParameterValue: parameterValue,
ParameterName: parameterName,
}
return payload
}
Expand All @@ -34,7 +38,7 @@ func (h ApplicationParametersValidateHandler) Handle(params application_paramete
name := params.Body.ParameterName

// fetch the value, if not found it will be an empty string
result, _ := models.FetchParameterValue(appCtx.DB(), value, name)
result, _ := models.FetchParameterValue(appCtx.DB(), *name, *value)

parameterValuePayload := payloadForApplicationParametersModel(result)

Expand Down
6 changes: 4 additions & 2 deletions pkg/handlers/internalapi/application_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ func (suite *HandlerSuite) TestApplicationParametersValidateHandler() {
req := httptest.NewRequest("POST", "/application_parameters", nil)
req = suite.AuthenticateUserRequest(req, user)

validationCode := "validation_code"
testCode := "Testcode123123"
body := internalmessages.ApplicationParameters{
ParameterValue: "TestCode123123",
ParameterName: "validation_code",
ParameterName: &validationCode,
ParameterValue: &testCode,
}

params := application_parameters.ValidateParams{
Expand Down
12 changes: 6 additions & 6 deletions pkg/models/application_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
type ApplicationParameters struct {
ID uuid.UUID `json:"id" db:"id"`
ValidationCode *string `json:"validation_code" db:"validation_code"`
ParameterName string `json:"parameter_name" db:"parameter_name"`
ParameterValue string `json:"parameter_value" db:"parameter_value"`
ParameterName *string `json:"parameter_name" db:"parameter_name"`
ParameterValue *string `json:"parameter_value" db:"parameter_value"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
Expand All @@ -23,9 +23,9 @@ func (a ApplicationParameters) TableName() string {
}

// FetchParameterValue returns a specific parameter value from the db
func FetchParameterValue(db *pop.Connection, code string, value string) (ApplicationParameters, error) {
var parameterValue ApplicationParameters
err := db.Q().Where(`parameter_value=$1 AND parameter_name=$2`, code, value).First(&parameterValue)
func FetchParameterValue(db *pop.Connection, param string, value string) (ApplicationParameters, error) {
var parameter ApplicationParameters
err := db.Q().Where(`parameter_name=$1 AND parameter_value=$2`, param, value).First(&parameter)
// if it isn't found, we'll return an empty object
if err != nil {
if errors.Cause(err).Error() == RecordNotFoundErrorString {
Expand All @@ -34,5 +34,5 @@ func FetchParameterValue(db *pop.Connection, code string, value string) (Applica
return ApplicationParameters{}, err
}

return parameterValue, nil
return parameter, nil
}
14 changes: 9 additions & 5 deletions pkg/models/application_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import (
)

func (suite *ModelSuite) Test_FetchParameterValue() {
param := "validation_code"
value := "Testcode123123"
parameterValue := models.ApplicationParameters{
ID: uuid.Must(uuid.NewV4()),
ParameterName: "validation_code",
ParameterValue: "TestCode123123",
ParameterName: &param,
ParameterValue: &value,
}
suite.MustCreate(&parameterValue)

// if the value is found, it should return the same code provided
shouldHaveValue, err := models.FetchParameterValue(suite.DB(), "TestCode123123", "validation_code")
shouldHaveValue, err := models.FetchParameterValue(suite.DB(), param, value)
suite.NoError(err)
suite.Equal(parameterValue.ParameterValue, shouldHaveValue.ParameterValue)

// if the value is not found, it should return an empty string
shouldNotHaveValue, err := models.FetchParameterValue(suite.DB(), "TestCode123456", "validation_code")
wrongValue := "Testcode123456"
var nilString *string = nil
shouldNotHaveValue, err := models.FetchParameterValue(suite.DB(), param, wrongValue)
suite.NoError(err)
suite.Equal("", shouldNotHaveValue.ParameterValue)
suite.Equal(nilString, shouldNotHaveValue.ParameterValue)
}
3 changes: 3 additions & 0 deletions pkg/models/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ type Move struct {
CloseoutOffice *TransportationOffice `belongs_to:"transportation_offices" fk_id:"closeout_office_id"`
ApprovalsRequestedAt *time.Time `db:"approvals_requested_at"`
ShipmentSeqNum *int `db:"shipment_seq_num"`
LockedByOfficeUserID *uuid.UUID `json:"locked_by" db:"locked_by"`
LockedByOfficeUser *OfficeUser `belongs_to:"office_users" fk_id:"locked_by"`
LockExpiresAt *time.Time `json:"lock_expires_at" db:"lock_expires_at"`
}

// TableName overrides the table name used by Pop.
Expand Down
4 changes: 4 additions & 0 deletions pkg/services/office_user/customer/customer_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (s *customerUpdater) UpdateCustomer(appCtx appcontext.AppContext, eTag stri
}
}

if customer.CacValidated != existingCustomer.CacValidated {
existingCustomer.CacValidated = customer.CacValidated
}

// optimistic locking handled before transaction block
verrs, updateErr := txnAppCtx.DB().ValidateAndUpdate(existingCustomer)

Expand Down
2 changes: 2 additions & 0 deletions pkg/services/office_user/customer/customer_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (suite *CustomerServiceSuite) TestCustomerUpdater() {
PostalCode: "12345",
},
BackupContacts: backupContacts,
CacValidated: true,
}

expectedETag := etag.GenerateEtag(defaultCustomer.UpdatedAt)
Expand All @@ -66,5 +67,6 @@ func (suite *CustomerServiceSuite) TestCustomerUpdater() {
suite.Equal(updatedCustomer.BackupContacts[0].Name, actualCustomer.BackupContacts[0].Name)
suite.Equal(updatedCustomer.BackupContacts[0].Phone, actualCustomer.BackupContacts[0].Phone)
suite.Equal(updatedCustomer.BackupContacts[0].Email, actualCustomer.BackupContacts[0].Email)
suite.Equal(updatedCustomer.CacValidated, actualCustomer.CacValidated)
})
}
4 changes: 4 additions & 0 deletions pkg/services/order/order_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/transcom/mymove/pkg/apperror"
"github.com/transcom/mymove/pkg/db/utilities"
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/models/roles"
"github.com/transcom/mymove/pkg/services"
)

Expand Down Expand Up @@ -159,6 +160,9 @@ func (f orderFetcher) ListOrders(appCtx appcontext.AppContext, officeUserID uuid
Where("(ppm_shipments.status IS NULL OR ppm_shipments.status NOT IN (?))", models.PPMShipmentStatusWaitingOnCustomer, models.PPMShipmentStatusNeedsPaymentApproval, models.PPMShipmentStatusPaymentApproved)
}
} else {
if appCtx.Session().Roles.HasRole(roles.RoleTypeTOO) {
query.Where("(moves.ppm_type = 'PARTIAL' or (moves.ppm_type = 'FULL' and origin_dl.provides_services_counseling = 'false'))")
}
// TODO not sure we'll need this once we're in a situation where closeout param is always passed
query.LeftJoin("ppm_shipments", "ppm_shipments.shipment_id = mto_shipments.id")
}
Expand Down
Loading

0 comments on commit f305bf8

Please sign in to comment.