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

Main b 21506 prime port update failure #14501

Merged
merged 12 commits into from
Jan 3, 2025
Merged
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
37 changes: 12 additions & 25 deletions pkg/models/port_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,24 @@ package models
import (
"time"

"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/validate/v3"
"github.com/gobuffalo/validate/v3/validators"
"github.com/gofrs/uuid"
)

type PortLocation struct {
ID uuid.UUID `json:"id" db:"id"`
PortId uuid.UUID `json:"port_id" db:"port_id"`
Port Port `belongs_to:"port_locations" fk_id:"port_id"`
CitiesId uuid.UUID `json:"cities_id" db:"cities_id"`
City City `belongs_to:"re_cities" fk_id:"cities_id"`
UsPostRegionCitiesId uuid.UUID `json:"us_post_region_cities_id" db:"us_post_region_cities_id"`
UsPostRegionCity UsPostRegionCity `belongs_to:"us_post_region_cities" fk_id:"us_post_region_cities_id"`
CountryId uuid.UUID `json:"country_id" db:"country_id"`
Country Country `belongs_to:"re_countries" fk_id:"country_id"`
IsActive *bool `json:"is_active" db:"is_active"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
ID uuid.UUID `json:"id" db:"id" rw:"r"`
PortId uuid.UUID `json:"port_id" db:"port_id" rw:"r"`
Port Port `belongs_to:"port_locations" fk_id:"port_id" rw:"r"`
CitiesId uuid.UUID `json:"cities_id" db:"cities_id" rw:"r"`
City City `belongs_to:"re_cities" fk_id:"cities_id" rw:"r"`
UsPostRegionCitiesId uuid.UUID `json:"us_post_region_cities_id" db:"us_post_region_cities_id" rw:"r"`
UsPostRegionCity UsPostRegionCity `belongs_to:"us_post_region_cities" fk_id:"us_post_region_cities_id" rw:"r"`
CountryId uuid.UUID `json:"country_id" db:"country_id" rw:"r"`
Country Country `belongs_to:"re_countries" fk_id:"country_id" rw:"r"`
IsActive *bool `json:"is_active" db:"is_active" rw:"r"`
CreatedAt time.Time `json:"created_at" db:"created_at" rw:"r"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at" rw:"r"`
}

func (l PortLocation) TableName() string {
return "port_locations"
}

// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
func (p *PortLocation) Validate(_ *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.UUIDIsPresent{Field: p.PortId, Name: "PortID"},
&validators.UUIDIsPresent{Field: p.CitiesId, Name: "CitiesID"},
&validators.UUIDIsPresent{Field: p.UsPostRegionCitiesId, Name: "UsPostRegionCitiesID"},
&validators.UUIDIsPresent{Field: p.CountryId, Name: "CountryID"},
), nil
}
44 changes: 14 additions & 30 deletions pkg/models/port_location_test.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
package models_test

import (
"time"
"github.com/transcom/mymove/pkg/factory"
)

"github.com/gofrs/uuid"
func (suite *ModelSuite) TestPortLocation() {
suite.Run("Port location has correct fields", func() {

"github.com/transcom/mymove/pkg/models"
)
portLocation := factory.FetchPortLocation(suite.DB(), nil, nil)

func (suite *ModelSuite) TestPortLocationValidation() {
suite.Run("test valid PortLocation", func() {
validPortLocation := models.PortLocation{
ID: uuid.Must(uuid.NewV4()),
PortId: uuid.Must(uuid.NewV4()),
CitiesId: uuid.Must(uuid.NewV4()),
UsPostRegionCitiesId: uuid.Must(uuid.NewV4()),
CountryId: uuid.Must(uuid.NewV4()),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
expErrors := map[string][]string{}
suite.verifyValidationErrors(&validPortLocation, expErrors)
suite.NotNil(portLocation)
suite.Equal(portLocation.PortId, portLocation.Port.ID)
suite.Equal(portLocation.CitiesId, portLocation.City.ID)
suite.Equal(portLocation.UsPostRegionCitiesId, portLocation.UsPostRegionCity.ID)
suite.Equal(portLocation.CountryId, portLocation.Country.ID)
})

suite.Run("test missing required fields", func() {
invalidPortLocation := models.PortLocation{
ID: uuid.Must(uuid.NewV4()),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
suite.Run("Port location table name is correct", func() {

expErrors := map[string][]string{
"port_id": {"PortID can not be blank."},
"cities_id": {"CitiesID can not be blank."},
"us_post_region_cities_id": {"UsPostRegionCitiesID can not be blank."},
"country_id": {"CountryID can not be blank."},
}
portLocation := factory.FetchPortLocation(suite.DB(), nil, nil)

suite.verifyValidationErrors(&invalidPortLocation, expErrors)
suite.NotNil(portLocation)
suite.Equal("port_locations", portLocation.TableName())
})
}
Loading