diff --git a/pkg/services/mto_service_item/mto_service_item_validators.go b/pkg/services/mto_service_item/mto_service_item_validators.go index 24f5b5de6ca..e0ebce273d7 100644 --- a/pkg/services/mto_service_item/mto_service_item_validators.go +++ b/pkg/services/mto_service_item/mto_service_item_validators.go @@ -135,7 +135,7 @@ func (v *primeUpdateMTOServiceItemValidator) validate(appCtx appcontext.AppConte } // Checks that the SITDepartureDate - // - is not later than the authorized end date + // - is not earlier than the SIT entry date err = serviceItemData.checkSITDepartureDate(appCtx) if err != nil { return err @@ -504,10 +504,10 @@ func (v *updateMTOServiceItemData) checkSITEntryDateAndFADD(_ appcontext.AppCont } // checkSITDepartureDate checks that the SITDepartureDate: -// - is not later than the authorized end date +// - is not earlier than the SIT entry date func (v *updateMTOServiceItemData) checkSITDepartureDate(_ appcontext.AppContext) error { - if v.updatedServiceItem.SITDepartureDate == nil || v.updatedServiceItem.SITDepartureDate == v.oldServiceItem.SITDepartureDate { - return nil // the SITDepartureDate isn't being updated, so we're fine here + if (v.updatedServiceItem.SITDepartureDate == nil || v.updatedServiceItem.SITDepartureDate == v.oldServiceItem.SITDepartureDate) && (v.updatedServiceItem.SITEntryDate == nil || v.updatedServiceItem.SITEntryDate == v.oldServiceItem.SITEntryDate) { + return nil // the SITDepartureDate or SITEntryDate isn't being updated, so we're fine here } if v.updatedServiceItem.SITDepartureDate != nil { @@ -524,9 +524,9 @@ func (v *updateMTOServiceItemData) checkSITDepartureDate(_ appcontext.AppContext if v.updatedServiceItem.SITEntryDate != nil { SITEntryDate = v.updatedServiceItem.SITEntryDate } - // Check that departure date is not before the current entry date - if v.updatedServiceItem.SITDepartureDate.Before(*SITEntryDate) { - v.verrs.Add("SITDepartureDate", "SIT departure date cannot be set before the SIT entry date.") + // Check that departure date is not before or equal to the current entry date + if !v.updatedServiceItem.SITDepartureDate.After(*SITEntryDate) { + v.verrs.Add("SITDepartureDate", "SIT departure date cannot be set before or equal to the SIT entry date.") } } return nil diff --git a/pkg/services/mto_service_item/mto_service_item_validators_test.go b/pkg/services/mto_service_item/mto_service_item_validators_test.go index 888c094becd..de41dc6bc9d 100644 --- a/pkg/services/mto_service_item/mto_service_item_validators_test.go +++ b/pkg/services/mto_service_item/mto_service_item_validators_test.go @@ -793,8 +793,9 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { suite.Run("SITDepartureDate - Does not error or update shipment auth end date when set after the authorized end date", func() { // Under test: checkSITDepartureDate checks that - // the SITDepartureDate is not later than the authorized end date - // Set up: Create an old and new DOPSIT and DDDSIT, with a date later than the + // the SITDepartureDate can be later than the authorized end date + // and that the authorized end dates is not updated when that occurs + // Set up: Create an old and new DOPSIT and DDDSIT, with a departure date later than the // shipment and try to update. // Expected outcome: No ERROR if departure date comes after the end date. // Shipment auth end date does not change @@ -827,7 +828,7 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { }, { Model: models.MTOServiceItem{ - SITEntryDate: &later, + SITEntryDate: &before, }, }, }, nil) @@ -842,23 +843,23 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { suite.NoError(err) suite.False(serviceItemData.verrs.HasAny()) - // Double check the shipment and ensure that the SITDepartureDate is in fact after the authorized end date + // Double check the shipment and ensure that the SITDepartureDate is after the authorized end date and does not alter the authorized end date var postUpdateShipment models.MTOShipment err = suite.DB().Find(&postUpdateShipment, mtoShipment.ID) suite.NoError(err) if tc.reServiceCode == models.ReServiceCodeDOPSIT { suite.True(mtoShipment.OriginSITAuthEndDate.Truncate(24 * time.Hour).Equal(postUpdateShipment.OriginSITAuthEndDate.Truncate(24 * time.Hour))) - suite.True(newSITServiceItem.SITEntryDate.Truncate(24 * time.Hour).After(postUpdateShipment.OriginSITAuthEndDate.Truncate(24 * time.Hour))) + suite.True(newSITServiceItem.SITDepartureDate.Truncate(24 * time.Hour).After(postUpdateShipment.OriginSITAuthEndDate.Truncate(24 * time.Hour))) } if tc.reServiceCode == models.ReServiceCodeDDDSIT { suite.True(mtoShipment.DestinationSITAuthEndDate.Truncate(24 * time.Hour).Equal(postUpdateShipment.DestinationSITAuthEndDate.Truncate(24 * time.Hour))) - suite.True(newSITServiceItem.SITEntryDate.Truncate(24 * time.Hour).After(postUpdateShipment.DestinationSITAuthEndDate.Truncate(24 * time.Hour))) + suite.True(newSITServiceItem.SITDepartureDate.Truncate(24 * time.Hour).After(postUpdateShipment.DestinationSITAuthEndDate.Truncate(24 * time.Hour))) } } }) - suite.Run("SITDepartureDate - errors when set before the SIT entry date", func() { + suite.Run("SITDepartureDate - errors when set before or equal the SIT entry date", func() { mtoShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ { Model: models.MTOShipment{OriginSITAuthEndDate: &now, @@ -903,7 +904,57 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() { suite.NoError(err) // Just verrs suite.True(serviceItemData.verrs.HasAny()) suite.Contains(serviceItemData.verrs.Keys(), "SITDepartureDate") - suite.Contains(serviceItemData.verrs.Get("SITDepartureDate"), "SIT departure date cannot be set before the SIT entry date.") + suite.Contains(serviceItemData.verrs.Get("SITDepartureDate"), "SIT departure date cannot be set before or equal to the SIT entry date.") + } + + }) + + suite.Run("SITDepartureDate - errors when set equal to the SIT entry date", func() { + mtoShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + { + Model: models.MTOShipment{OriginSITAuthEndDate: &now, + DestinationSITAuthEndDate: &now}, + }, + }, nil) + testCases := []struct { + reServiceCode models.ReServiceCode + }{ + { + reServiceCode: models.ReServiceCodeDOPSIT, + }, + { + reServiceCode: models.ReServiceCodeDDDSIT, + }, + } + for _, tc := range testCases { + oldSITServiceItem := factory.BuildMTOServiceItem(nil, []factory.Customization{ + { + Model: models.ReService{ + Code: tc.reServiceCode, + }, + }, + { + Model: mtoShipment, + LinkOnly: true, + }, + { + Model: models.MTOServiceItem{ + SITEntryDate: &now, + }, + }, + }, nil) + newSITServiceItem := oldSITServiceItem + newSITServiceItem.SITDepartureDate = &now + serviceItemData := updateMTOServiceItemData{ + updatedServiceItem: newSITServiceItem, + oldServiceItem: oldSITServiceItem, + verrs: validate.NewErrors(), + } + err := serviceItemData.checkSITDepartureDate(suite.AppContextForTest()) + suite.NoError(err) // Just verrs + suite.True(serviceItemData.verrs.HasAny()) + suite.Contains(serviceItemData.verrs.Keys(), "SITDepartureDate") + suite.Contains(serviceItemData.verrs.Get("SITDepartureDate"), "SIT departure date cannot be set before or equal to the SIT entry date.") } }) diff --git a/scripts/run-server-test b/scripts/run-server-test index 0ead8674b81..8dfc3ef3be0 100755 --- a/scripts/run-server-test +++ b/scripts/run-server-test @@ -47,6 +47,12 @@ else gotest_args+=("-parallel" "8") gotest_args+=("-failfast") fi + +## Add SKIP_FAIL_TESTS on dev machine within .envrc.local file +if [ -n "${SKIP_FAIL_TESTS+x}" ]; then + gotest_args+=("-skip" "TestGHCRateEngineImportSuite") +fi + ## mac users uncomment the following line to run tests with the classic linker, which clears a lot of warnings that fill the console, do not commit to repo uncommented #gotest_args+=("-ldflags=-extldflags=-Wl,-ld_classic") diff --git a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.jsx b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.jsx index 6ef614279da..7903fc4f494 100644 --- a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.jsx +++ b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.jsx @@ -36,6 +36,7 @@ const PrimeUIUpdateDestSITForm = ({ initialValues, onSubmit, serviceItem }) => { Here you can update specific fields for a destination SIT service item.
At this time, only the following values can be updated:
{' '} + SIT Entry Date
SIT Departure Date
SIT Requested Delivery
SIT Customer Contacted
@@ -67,8 +68,12 @@ const PrimeUIUpdateDestSITForm = ({ initialValues, onSubmit, serviceItem }) => {
+ +
+
+
{serviceItem.status === SERVICE_ITEM_STATUSES.REJECTED && ( diff --git a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.test.jsx b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.test.jsx index 60e50555bba..3e7c1c055e3 100644 --- a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.test.jsx +++ b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateDestSITForm.test.jsx @@ -26,6 +26,7 @@ const reformatPrimeApiSITDestinationAddress = fromPrimeAPIAddressFormat(shipment const destSitInitialValues = { sitDestinationFinalAddress: reformatPrimeApiSITDestinationAddress, + sitEntryDate: '25 Oct 2023', sitDepartureDate: '01 Nov 2023', sitRequestedDelivery: '01 Dec 2023', sitCustomerContacted: '15 Oct 2023', @@ -56,6 +57,7 @@ describe('PrimeUIRequestSITDestAddressChangeForm', () => { expect( screen.getByRole('heading', { name: 'DDDSIT - Domestic destination SIT delivery', level: 3 }), ).toBeInTheDocument(); + expect(await screen.findByLabelText('SIT Entry Date')).toHaveValue('25 Oct 2023'); expect(await screen.findByLabelText('SIT Departure Date')).toHaveValue('01 Nov 2023'); expect(await screen.findByLabelText('SIT Requested Delivery')).toHaveValue('01 Dec 2023'); expect(await screen.findByLabelText('SIT Customer Contacted')).toHaveValue('15 Oct 2023'); diff --git a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.jsx b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.jsx index 240eb042f39..8865706bacd 100644 --- a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.jsx +++ b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.jsx @@ -36,6 +36,7 @@ const PrimeUIUpdateOriginSITForm = ({ initialValues, onSubmit, serviceItem }) => Here you can update specific fields for an origin SIT service item.
At this time, only the following values can be updated:
{' '} + SIT Entry Date
SIT Departure Date
SIT Requested Delivery
SIT Customer Contacted
@@ -67,8 +68,12 @@ const PrimeUIUpdateOriginSITForm = ({ initialValues, onSubmit, serviceItem }) =>
+ +
+
+
{serviceItem.status === SERVICE_ITEM_STATUSES.REJECTED && ( diff --git a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.test.jsx b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.test.jsx index 317f52b16bc..8503af25088 100644 --- a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.test.jsx +++ b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateOriginSITForm.test.jsx @@ -8,6 +8,7 @@ import { renderWithProviders } from 'testUtils'; import { primeSimulatorRoutes } from 'constants/routes'; const originSitInitialValues = { + sitEntryDate: '25 Oct 2023', sitDepartureDate: '01 Nov 2023', sitRequestedDelivery: '01 Dec 2023', sitCustomerContacted: '15 Oct 2023', @@ -40,6 +41,7 @@ describe('PrimeUIRequestSITDestAddressChangeForm', () => { expect(screen.getByRole('heading', { name: 'Update Origin SIT Service Item', level: 2 })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: 'DOPSIT - Domestic origin SIT pickup', level: 3 })).toBeInTheDocument(); + expect(await screen.findByLabelText('SIT Entry Date')).toHaveValue('25 Oct 2023'); expect(await screen.findByLabelText('SIT Departure Date')).toHaveValue('01 Nov 2023'); expect(await screen.findByLabelText('SIT Requested Delivery')).toHaveValue('01 Dec 2023'); expect(await screen.findByLabelText('SIT Customer Contacted')).toHaveValue('15 Oct 2023'); diff --git a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateServiceItem.jsx b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateServiceItem.jsx index f071e573c4f..307303284f2 100644 --- a/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateServiceItem.jsx +++ b/src/pages/PrimeUI/UpdateServiceItems/PrimeUIUpdateServiceItem.jsx @@ -74,6 +74,7 @@ const PrimeUIUpdateServiceItem = ({ setFlashMessage }) => { let onSubmit; if (modelType === 'MTOServiceItemOriginSIT' || modelType === 'MTOServiceItemDestSIT') { initialValues = { + sitEntryDate: formatDateWithUTC(serviceItem.sitEntryDate, 'YYYY-MM-DD', 'DD MMM YYYY') || '', sitDepartureDate: formatDateWithUTC(serviceItem.sitDepartureDate, 'YYYY-MM-DD', 'DD MMM YYYY') || '', sitRequestedDelivery: formatDateWithUTC(serviceItem.sitRequestedDelivery, 'YYYY-MM-DD', 'DD MMM YYYY') || '', sitCustomerContacted: formatDateWithUTC(serviceItem.sitCustomerContacted, 'YYYY-MM-DD', 'DD MMM YYYY') || '', @@ -86,6 +87,7 @@ const PrimeUIUpdateServiceItem = ({ setFlashMessage }) => { onSubmit = (values) => { const { sitCustomerContacted, + sitEntryDate, sitDepartureDate, sitRequestedDelivery, updateReason, @@ -95,6 +97,7 @@ const PrimeUIUpdateServiceItem = ({ setFlashMessage }) => { } = values; const body = { + sitEntryDate: sitEntryDate === 'Invalid date' ? null : formatDateForSwagger(sitEntryDate), sitDepartureDate: sitDepartureDate === 'Invalid date' ? null : formatDateForSwagger(sitDepartureDate), sitRequestedDelivery: sitRequestedDelivery === 'Invalid date' ? null : formatDateForSwagger(sitRequestedDelivery), diff --git a/src/pages/PrimeUI/UpdateServiceItems/PrimeUpdateSitServiceItem.test.jsx b/src/pages/PrimeUI/UpdateServiceItems/PrimeUpdateSitServiceItem.test.jsx index e7f21f94309..c69825cf388 100644 --- a/src/pages/PrimeUI/UpdateServiceItems/PrimeUpdateSitServiceItem.test.jsx +++ b/src/pages/PrimeUI/UpdateServiceItems/PrimeUpdateSitServiceItem.test.jsx @@ -69,6 +69,7 @@ describe('PrimeUIUpdateSitServiceItems page', () => { renderComponent(); expect(screen.getByRole('heading', { name: 'Update Destination SIT Service Item', level: 2 })).toBeInTheDocument(); + expect(screen.getByRole('textbox', { name: 'SIT Entry Date' })).toBeInTheDocument(); expect(screen.getByRole('textbox', { name: 'SIT Departure Date' })).toBeInTheDocument(); expect(screen.getByRole('textbox', { name: 'SIT Requested Delivery' })).toBeInTheDocument(); expect(screen.getByRole('textbox', { name: 'SIT Customer Contacted' })).toBeInTheDocument(); @@ -131,6 +132,7 @@ describe('PrimeUIUpdateSitServiceItems page', () => { renderComponent(); expect(screen.getByRole('heading', { name: 'Update Origin SIT Service Item', level: 2 })).toBeInTheDocument(); + expect(screen.getByRole('textbox', { name: 'SIT Entry Date' })).toBeInTheDocument(); expect(screen.getByRole('textbox', { name: 'SIT Departure Date' })).toBeInTheDocument(); expect(screen.getByRole('textbox', { name: 'SIT Requested Delivery' })).toBeInTheDocument(); expect(screen.getByRole('textbox', { name: 'SIT Customer Contacted' })).toBeInTheDocument();