Skip to content

Commit

Permalink
Merge pull request #14721 from transcom/INT-B-21943-prime_sim_resubmi…
Browse files Browse the repository at this point in the history
…t_sit

Int b 21943 prime sim resubmit sit
  • Loading branch information
brianmanley-caci authored Feb 7, 2025
2 parents ce32f0d + b16c1d0 commit 57ff1c4
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 15 deletions.
14 changes: 7 additions & 7 deletions pkg/services/mto_service_item/mto_service_item_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
67 changes: 59 additions & 8 deletions pkg/services/mto_service_item/mto_service_item_validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -827,7 +828,7 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() {
},
{
Model: models.MTOServiceItem{
SITEntryDate: &later,
SITEntryDate: &before,
},
},
}, nil)
Expand All @@ -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,
Expand Down Expand Up @@ -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.")
}

})
Expand Down
6 changes: 6 additions & 0 deletions scripts/run-server-test
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const PrimeUIUpdateDestSITForm = ({ initialValues, onSubmit, serviceItem }) => {
Here you can update specific fields for a destination SIT service item. <br />
At this time, only the following values can be updated: <br />{' '}
<strong>
SIT Entry Date <br />
SIT Departure Date <br />
SIT Requested Delivery <br />
SIT Customer Contacted <br />
Expand Down Expand Up @@ -67,8 +68,12 @@ const PrimeUIUpdateDestSITForm = ({ initialValues, onSubmit, serviceItem }) => {
</div>
</dl>
<div className={styles.sitDatePickerRow}>
<DatePickerInput name="sitEntryDate" label="SIT Entry Date" />
<DatePickerInput name="sitDepartureDate" label="SIT Departure Date" />
<DatePickerInput name="sitRequestedDelivery" label="SIT Requested Delivery" />
</div>
<br />
<div className={styles.sitDatePickerRow}>
<DatePickerInput name="sitCustomerContacted" label="SIT Customer Contacted" />
</div>
{serviceItem.status === SERVICE_ITEM_STATUSES.REJECTED && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const PrimeUIUpdateOriginSITForm = ({ initialValues, onSubmit, serviceItem }) =>
Here you can update specific fields for an origin SIT service item. <br />
At this time, only the following values can be updated: <br />{' '}
<strong>
SIT Entry Date <br />
SIT Departure Date <br />
SIT Requested Delivery <br />
SIT Customer Contacted <br />
Expand Down Expand Up @@ -67,8 +68,12 @@ const PrimeUIUpdateOriginSITForm = ({ initialValues, onSubmit, serviceItem }) =>
</div>
</dl>
<div className={styles.sitDatePickerRow}>
<DatePickerInput name="sitEntryDate" label="SIT Entry Date" />
<DatePickerInput name="sitDepartureDate" label="SIT Departure Date" />
<DatePickerInput name="sitRequestedDelivery" label="SIT Requested Delivery" />
</div>
<br />
<div className={styles.sitDatePickerRow}>
<DatePickerInput name="sitCustomerContacted" label="SIT Customer Contacted" />
</div>
{serviceItem.status === SERVICE_ITEM_STATUSES.REJECTED && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') || '',
Expand All @@ -86,6 +87,7 @@ const PrimeUIUpdateServiceItem = ({ setFlashMessage }) => {
onSubmit = (values) => {
const {
sitCustomerContacted,
sitEntryDate,
sitDepartureDate,
sitRequestedDelivery,
updateReason,
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 57ff1c4

Please sign in to comment.