From 53e9237ac866dc8b389189c4763ffa9158600ecc Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Thu, 22 Aug 2024 13:59:09 +0000 Subject: [PATCH 01/14] added inclusive end date for calculateSitDays --- pkg/handlers/ghcapi/mto_shipment_test.go | 6 +++--- pkg/services/sit_status/shipment_sit_status.go | 5 +++-- .../sit_status/shipment_sit_status_test.go | 18 +++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/handlers/ghcapi/mto_shipment_test.go b/pkg/handlers/ghcapi/mto_shipment_test.go index e1d57e98e17..9b0f17e3f7e 100644 --- a/pkg/handlers/ghcapi/mto_shipment_test.go +++ b/pkg/handlers/ghcapi/mto_shipment_test.go @@ -244,9 +244,9 @@ func (suite *HandlerSuite) TestListMTOShipmentsHandler() { suite.Equal(int64(190), *payloadShipment.SitDaysAllowance) suite.Equal(sitstatus.OriginSITLocation, payloadShipment.SitStatus.CurrentSIT.Location) suite.Equal(int64(8), *payloadShipment.SitStatus.CurrentSIT.DaysInSIT) - suite.Equal(int64(175), *payloadShipment.SitStatus.TotalDaysRemaining) - suite.Equal(int64(15), *payloadShipment.SitStatus.TotalSITDaysUsed) // 7 from the previous SIT and 7 from the current - suite.Equal(int64(15), *payloadShipment.SitStatus.CalculatedTotalDaysInSIT) + suite.Equal(int64(174), *payloadShipment.SitStatus.TotalDaysRemaining) + suite.Equal(int64(16), *payloadShipment.SitStatus.TotalSITDaysUsed) // 7 from the previous SIT and 7 from the current (+2 for including last days) + suite.Equal(int64(16), *payloadShipment.SitStatus.CalculatedTotalDaysInSIT) suite.Equal(subtestData.sit.SITEntryDate.Format("2006-01-02"), payloadShipment.SitStatus.CurrentSIT.SitEntryDate.String()) suite.Equal(subtestData.sit.SITDepartureDate.Format("2006-01-02"), payloadShipment.SitStatus.CurrentSIT.SitDepartureDate.String()) diff --git a/pkg/services/sit_status/shipment_sit_status.go b/pkg/services/sit_status/shipment_sit_status.go index b60d4746ef0..63152a30d1c 100644 --- a/pkg/services/sit_status/shipment_sit_status.go +++ b/pkg/services/sit_status/shipment_sit_status.go @@ -340,10 +340,11 @@ func getCurrentSIT(shipmentSITs SortedShipmentSITs) *models.SITServiceItemGroupi // return value is Today - SITEntryDate, adding 1 to include today. func daysInSIT(sitEntryDate time.Time, sitDepartureDate *time.Time, today time.Time) int { var days int + // Per B-20967, the last day should now always be inclusive even if there is a SIT departure date if sitDepartureDate != nil && sitDepartureDate.Before(today) { - days = int(sitDepartureDate.Sub(sitEntryDate).Hours()) / 24 + days = int(sitDepartureDate.Sub(sitEntryDate).Hours())/24 + 1 } else if sitEntryDate.Before(today) || sitEntryDate.Equal(today) { - days = int(today.Sub(sitEntryDate).Hours())/24 + 1 // This is to count start and end as full days + days = int(today.Sub(sitEntryDate).Hours())/24 + 1 } return days } diff --git a/pkg/services/sit_status/shipment_sit_status_test.go b/pkg/services/sit_status/shipment_sit_status_test.go index 36980ecb724..8b9da651035 100644 --- a/pkg/services/sit_status/shipment_sit_status_test.go +++ b/pkg/services/sit_status/shipment_sit_status_test.go @@ -116,9 +116,9 @@ func (suite *SITStatusServiceSuite) TestShipmentSITStatus() { suite.NotNil(sitStatus) suite.Len(sitStatus.PastSITs, 1) suite.Equal(dofsit.ID.String(), sitStatus.PastSITs[0].ServiceItems[0].ID.String()) - suite.Equal(15, sitStatus.TotalSITDaysUsed) - suite.Equal(15, sitStatus.CalculatedTotalDaysInSIT) - suite.Equal(75, sitStatus.TotalDaysRemaining) + suite.Equal(16, sitStatus.TotalSITDaysUsed) + suite.Equal(16, sitStatus.CalculatedTotalDaysInSIT) + suite.Equal(74, sitStatus.TotalDaysRemaining) suite.Nil(sitStatus.CurrentSIT) // No current SIT since all SIT items have departed status // check that shipment values impacted by current SIT do not get updated since current SIT is nil suite.Nil(shipment.DestinationSITAuthEndDate) @@ -238,9 +238,9 @@ func (suite *SITStatusServiceSuite) TestShipmentSITStatus() { suite.NotNil(sitStatus) suite.Equal(OriginSITLocation, sitStatus.CurrentSIT.Location) - suite.Equal(23, sitStatus.TotalSITDaysUsed) // 15 days from previous SIT, 7 days from the current - suite.Equal(23, sitStatus.CalculatedTotalDaysInSIT) - suite.Equal(67, sitStatus.TotalDaysRemaining) + suite.Equal(24, sitStatus.TotalSITDaysUsed) // 15 days from previous SIT, 7 days from the current + suite.Equal(24, sitStatus.CalculatedTotalDaysInSIT) + suite.Equal(66, sitStatus.TotalDaysRemaining) suite.Equal(8, sitStatus.CurrentSIT.DaysInSIT) suite.Equal(aWeekAgo.String(), sitStatus.CurrentSIT.SITEntryDate.String()) suite.Nil(sitStatus.CurrentSIT.SITDepartureDate) @@ -315,9 +315,9 @@ func (suite *SITStatusServiceSuite) TestShipmentSITStatus() { suite.NotNil(sitStatus) suite.Equal(DestinationSITLocation, sitStatus.CurrentSIT.Location) - suite.Equal(23, sitStatus.TotalSITDaysUsed) // 15 days from previous SIT, 7 days from the current - suite.Equal(23, sitStatus.CalculatedTotalDaysInSIT) - suite.Equal(67, sitStatus.TotalDaysRemaining) + suite.Equal(24, sitStatus.TotalSITDaysUsed) // 15 days from previous SIT, 7 days from the current + suite.Equal(24, sitStatus.CalculatedTotalDaysInSIT) + suite.Equal(66, sitStatus.TotalDaysRemaining) suite.Equal(8, sitStatus.CurrentSIT.DaysInSIT) suite.Equal(aWeekAgo.String(), sitStatus.CurrentSIT.SITEntryDate.String()) suite.Nil(sitStatus.CurrentSIT.SITDepartureDate) From eeef75534e97e4408908abc7a768fc815a192750 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Thu, 22 Aug 2024 16:35:34 +0000 Subject: [PATCH 02/14] fix faulty days in sit summary calculation --- .../sit_status/shipment_sit_status.go | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/pkg/services/sit_status/shipment_sit_status.go b/pkg/services/sit_status/shipment_sit_status.go index 63152a30d1c..91bdab6bc61 100644 --- a/pkg/services/sit_status/shipment_sit_status.go +++ b/pkg/services/sit_status/shipment_sit_status.go @@ -138,23 +138,24 @@ func containsReServiceCode(validCodes []models.ReServiceCode, code models.ReServ } // Helper function to generate the SIT Summary for a group of service items +// This is where the craziest part of the SIT code should ever be (Besides the grouping section) +// Due to our service item architecture, SIT is split across many service items +// and due to existing handlers and service objects, it's possible these SIT service items +// will have discrepancies and information spread across multiple items. +// This SIT summary is to make it readable down the line, and handle all complex calculations +// in one, central location. func (f shipmentSITStatus) generateSITSummary(sit models.SITServiceItemGrouping, today time.Time) *models.SITSummary { if sit.ServiceItems == nil { // Return nil if there are no service items return nil } - // This is where the craziest part of the code should ever be (Besides the grouping section) - // Due to our service item architecture, SIT is split across many service items - // and due to existing handlers and service objects, it's possible these SIT service items - // will have discrepancies and information spread across multiple items. - // This SIT summary is to make it readable down the line, and handle all complex calculations - // in one, central location. + var earliestSITEntryDate *time.Time var earliestSITDepartureDate *time.Time var earliestSITAuthorizedEndDate *time.Time var earliestSITCustomerContacted *time.Time var earliestSITRequestedDelivery *time.Time - var calculatedTotalDaysInSIT *int + var calculatedTotalDaysInSIT int var location string var firstDaySITServiceItemID uuid.UUID @@ -191,18 +192,21 @@ func (f shipmentSITStatus) generateSITSummary(sit models.SITServiceItemGrouping, if earliestSITDepartureDate == nil || (sitServiceItem.SITDepartureDate != nil && sitServiceItem.SITDepartureDate.Before(*earliestSITDepartureDate)) { earliestSITDepartureDate = sitServiceItem.SITDepartureDate } + } - // Grab the earliest SIT Authorized End Date - // based off of the provided earliest SIT entry date - // retrieving the authorized end date requires a SIT entry date - if earliestSITAuthorizedEndDate == nil && earliestSITEntryDate != nil { - daysInSIT := daysInSIT(*earliestSITEntryDate, earliestSITDepartureDate, today) - calculatedTotalDaysInSIT = &daysInSIT - earliestSITAuthorizedEndDateValue := CalculateSITAuthorizedEndDate(len(sit.ServiceItems), daysInSIT, *earliestSITEntryDate, *calculatedTotalDaysInSIT) - earliestSITAuthorizedEndDate = &earliestSITAuthorizedEndDateValue - } + // Calculate the days in SIT based on the earliest SIT entry date and earliest SIT departure date if any were discovered from the SIT group + if earliestSITEntryDate != nil { + calculatedTotalDaysInSIT = daysInSIT(*earliestSITEntryDate, earliestSITDepartureDate, today) + } - // Grab the first Customer Contacted + // Calculate the SIT Authorized End Date + if earliestSITEntryDate != nil { + earliestSITAuthorizedEndDateValue := CalculateSITAuthorizedEndDate(len(sit.ServiceItems), calculatedTotalDaysInSIT, *earliestSITEntryDate, calculatedTotalDaysInSIT) + earliestSITAuthorizedEndDate = &earliestSITAuthorizedEndDateValue + } + + // Grab the first Customer Contacted + for _, sitServiceItem := range sit.ServiceItems { if earliestSITCustomerContacted == nil && sitServiceItem.SITCustomerContacted != nil { earliestSITCustomerContacted = sitServiceItem.SITCustomerContacted } @@ -216,7 +220,7 @@ func (f shipmentSITStatus) generateSITSummary(sit models.SITServiceItemGrouping, return &models.SITSummary{ FirstDaySITServiceItemID: firstDaySITServiceItemID, Location: location, - DaysInSIT: *calculatedTotalDaysInSIT, + DaysInSIT: calculatedTotalDaysInSIT, SITEntryDate: *earliestSITEntryDate, SITDepartureDate: earliestSITDepartureDate, SITAuthorizedEndDate: *earliestSITAuthorizedEndDate, From 18b28e5632216d53e71d613e0167225029e6c8dd Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Thu, 22 Aug 2024 16:37:26 +0000 Subject: [PATCH 03/14] fixed shipment sit display sitDaysUsed calculation --- .../Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx index 670eede75e4..9b28fdc3038 100644 --- a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx +++ b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx @@ -112,9 +112,11 @@ const SitStatusTables = ({ shipment, sitExtensions, sitStatus, openModalButton, // Previous SIT calculations and date ranges const previousDaysUsed = sitStatus.pastSITServiceItemGroupings?.map((sitGroup) => { // Build the past SIT text based off the past sit group summary rather than individual service items - const sitDaysUsed = moment(sitGroup.summary.sitDepartureDate).diff(sitGroup.summary.sitEntryDate, 'days'); + // The server provides sitDaysUsed + const sitDaysUsed = sitGroup.summary.daysInSIT || DEFAULT_EMPTY_VALUE; const location = sitGroup.summary.location === LOCATION_TYPES.ORIGIN ? 'origin' : 'destination'; + // Display the dates the server used to calculate sitDaysUsed const start = formatDate(sitGroup.summary.sitEntryDate, swaggerDateFormat, 'DD MMM YYYY'); const end = formatDate(sitGroup.summary.sitDepartureDate, swaggerDateFormat, 'DD MMM YYYY'); const text = `${sitDaysUsed} days at ${location} (${start} - ${end})`; From 0bc33c70946d43b5ca8e55b842a8538d8f3a0b85 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Thu, 22 Aug 2024 17:10:14 +0000 Subject: [PATCH 04/14] removed calculated days table and move current days calc table --- playwright/tests/office/txo/sitUpdates.spec.js | 4 ++-- .../ShipmentSITDisplay/ShipmentSITDisplay.jsx | 16 ++++++++-------- .../ShipmentSITDisplay.test.jsx | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/playwright/tests/office/txo/sitUpdates.spec.js b/playwright/tests/office/txo/sitUpdates.spec.js index 23f739b0b88..ea04b261e6f 100644 --- a/playwright/tests/office/txo/sitUpdates.spec.js +++ b/playwright/tests/office/txo/sitUpdates.spec.js @@ -24,11 +24,11 @@ test.describe('TOO user', () => { await tooFlowPage.waitForPage.moveTaskOrder(); const target = await page - .getByTestId('sitDaysAtCurrentLocation') + .getByTestId('currentSitDepartureDate') .locator('table[class="DataTable_dataTable__TGt9M table--data-point"]') .locator('tbody') .locator('td') - .nth(1) + .nth(0) .locator('div') .locator('span') .textContent(); diff --git a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx index 9b28fdc3038..dfd6f04cdc2 100644 --- a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx +++ b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx @@ -181,20 +181,20 @@ const SitStatusTables = ({ shipment, sitExtensions, sitStatus, openModalButton, {sitStatus.currentSIT && ( <>
- {/* Sit Start and End table */} + {/* Sit Start and End table with total days at current location */} {currentDaysInSIT > 0 &&

Current location: {currentLocation}

}
-
- {/* Total days at current location */} +
+ {/* Current SIT departure date */}
diff --git a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx index 0da70b8a58c..1776e4ec340 100644 --- a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx +++ b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx @@ -63,10 +63,10 @@ describe('ShipmentSITDisplay', () => { expect(screen.getByText('Current location: destination SIT')).toBeInTheDocument(); expect(screen.getByText('Total days in destination SIT')).toBeInTheDocument(); expect(screen.getByText('15')).toBeInTheDocument(); - const sitStartAndEndTable = await screen.findByTestId('sitStartAndEndTable'); - expect(sitStartAndEndTable).toBeInTheDocument(); - expect(within(sitStartAndEndTable).getByText('Calculated total SIT days')).toBeInTheDocument(); - expect(within(sitStartAndEndTable).getByText('45')).toBeInTheDocument(); + const sitStatusTable = await screen.findByTestId('sitStatusTable'); + expect(sitStatusTable).toBeInTheDocument(); + expect(within(sitStatusTable).getByText('Total days used')).toBeInTheDocument(); + expect(within(sitStatusTable).getByText('45')).toBeInTheDocument(); }); it('renders the Shipment SIT at Origin, with customer delivery info', async () => { @@ -246,12 +246,12 @@ describe('ShipmentSITDisplay', () => { expect(within(sitStartAndEndTable).queryByText('Current location')).not.toBeInTheDocument(); expect(within(sitStartAndEndTable).getByText('SIT start date')).toBeInTheDocument(); expect(within(sitStartAndEndTable).getByText('SIT authorized end date')).toBeInTheDocument(); - expect(within(sitStartAndEndTable).getByText('Calculated total SIT days')).toBeInTheDocument(); + expect(within(sitStartAndEndTable).getByText('Total days in origin SIT')).toBeInTheDocument(); expect(within(sitStartAndEndTable).getByText('0')).toBeInTheDocument(); - const sitDaysAtCurrentLocation = await screen.findByTestId('sitDaysAtCurrentLocation'); - expect(sitDaysAtCurrentLocation).toBeInTheDocument(); - expect(within(sitDaysAtCurrentLocation).getByText('Total days in origin SIT')).toBeInTheDocument(); - expect(within(sitDaysAtCurrentLocation).getByText('0')).toBeInTheDocument(); + const currentSitDepartureDate = await screen.findByTestId('currentSitDepartureDate'); + expect(currentSitDepartureDate).toBeInTheDocument(); + expect(within(currentSitDepartureDate).getByText('SIT departure date')).toBeInTheDocument(); + expect(within(currentSitDepartureDate).getByText('—')).toBeInTheDocument(); }); it('calls SIT extension callback when button clicked', async () => { From 6a6bb2498f56e3640f0f9ad6d7ca53cc5b18430d Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Fri, 23 Aug 2024 13:06:21 +0000 Subject: [PATCH 05/14] adjusted sit auth end date calculation and fixed some tests --- pkg/handlers/ghcapi/payment_request_test.go | 2 +- pkg/services/mto_shipment.go | 2 +- .../payment_request_shipments_sit_balance.go | 18 +++-- ...ment_request_shipments_sit_balance_test.go | 6 +- .../sit_status/shipment_sit_status.go | 69 +++++++++++-------- 5 files changed, 61 insertions(+), 36 deletions(-) diff --git a/pkg/handlers/ghcapi/payment_request_test.go b/pkg/handlers/ghcapi/payment_request_test.go index 994b8770708..33eb7ec946a 100644 --- a/pkg/handlers/ghcapi/payment_request_test.go +++ b/pkg/handlers/ghcapi/payment_request_test.go @@ -926,7 +926,7 @@ func (suite *HandlerSuite) TestShipmentsSITBalanceHandler() { suite.Equal(int64(120), shipmentSITBalance.TotalSITDaysAuthorized) suite.Equal(int64(60), shipmentSITBalance.PendingSITDaysInvoiced) // Since there is no departure date on one of the SITs, +1 is added to the count to count the last day - suite.Equal(int64(-61), shipmentSITBalance.TotalSITDaysRemaining) // Well over entitlement + suite.Equal(int64(-62), shipmentSITBalance.TotalSITDaysRemaining) // Well over entitlement suite.Equal(destinationPaymentEndDate.Format("2006-01-02"), shipmentSITBalance.PendingBilledEndDate.String()) suite.Equal(int64(30), *shipmentSITBalance.PreviouslyBilledDays) }) diff --git a/pkg/services/mto_shipment.go b/pkg/services/mto_shipment.go index 5c40aafaa34..a409c6db436 100644 --- a/pkg/services/mto_shipment.go +++ b/pkg/services/mto_shipment.go @@ -151,5 +151,5 @@ type ShipmentSITStatus interface { CalculateShipmentsSITStatuses(appCtx appcontext.AppContext, shipments []models.MTOShipment) map[string]SITStatus CalculateShipmentSITStatus(appCtx appcontext.AppContext, shipment models.MTOShipment) (*SITStatus, models.MTOShipment, error) CalculateShipmentSITAllowance(appCtx appcontext.AppContext, shipment models.MTOShipment) (int, error) - RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) models.SITServiceItemGroupings + RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) (models.SITServiceItemGroupings, error) } diff --git a/pkg/services/payment_request/payment_request_shipments_sit_balance.go b/pkg/services/payment_request/payment_request_shipments_sit_balance.go index 808f30163f8..43f8c9374c4 100644 --- a/pkg/services/payment_request/payment_request_shipments_sit_balance.go +++ b/pkg/services/payment_request/payment_request_shipments_sit_balance.go @@ -114,7 +114,10 @@ func calculateReviewedSITBalance(appCtx appcontext.AppContext, paymentServiceIte } // sort the SIT service items into past, current and future to aid in the upcoming calculations - shipmentSIT := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment) + shipmentSIT, err := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment) + if err != nil { + return err + } sortedShipmentSIT := sitstatus.SortShipmentSITs(shipmentSIT, today) totalSITDaysAuthorized, err := sitstatus.NewShipmentSITStatus().CalculateShipmentSITAllowance(appCtx, shipment) @@ -155,7 +158,10 @@ func calculatePendingSITBalance(appCtx appcontext.AppContext, paymentServiceItem return err } // sort the SIT service items into past, current and future to aid in the upcoming calculations - shipmentSIT := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment) + shipmentSIT, err := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment) + if err != nil { + return err + } sortedShipmentSIT := sitstatus.SortShipmentSITs(shipmentSIT, today) totalSITAllowance, err := sitstatus.NewShipmentSITStatus().CalculateShipmentSITAllowance(appCtx, shipment) if err != nil { @@ -173,7 +179,9 @@ func calculatePendingSITBalance(appCtx appcontext.AppContext, paymentServiceItem // Even though these have been set before, we should do these calculations again in order to recalculate the // totalSITEndDate using this service item's entry date. - totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT) + // Additionally retrieve the latest SIT Departure date from the current SIT if it exists. The first current SIT is chosen as there is not currently support for more than one SIT + // Per AC under B-20899 + totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT, sortedShipmentSIT.CurrentSITs[0].Summary.SITDepartureDate) shipmentSITBalance.TotalSITEndDate = totalSITEndDate shipmentsSITBalances[shipment.ID.String()] = shipmentSITBalance @@ -191,7 +199,9 @@ func calculatePendingSITBalance(appCtx appcontext.AppContext, paymentServiceItem totalSITDaysUsed := sitstatus.CalculateTotalDaysInSIT(sortedShipmentSIT, today) totalSITDaysRemaining := totalSITDaysAuthorized - totalSITDaysUsed - totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT) + // Retrieve the latest SIT Departure date from the current SIT if it exists. The first current SIT is chosen as there is not currently support for more than one SIT + // Per AC under B-20899 + totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT, sortedShipmentSIT.CurrentSITs[0].Summary.SITDepartureDate) shipmentSITBalance.TotalSITDaysAuthorized = totalSITDaysAuthorized shipmentSITBalance.TotalSITDaysRemaining = totalSITDaysRemaining diff --git a/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go b/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go index 8d238e7ff26..635ab88f58a 100644 --- a/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go +++ b/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go @@ -528,9 +528,9 @@ func (suite *PaymentRequestServiceSuite) TestListShipmentPaymentSITBalance() { suite.Equal(120, pendingSITBalance.TotalSITDaysAuthorized) // 120 total authorized - 30 from origin SIT - 60 from destination SIT = 30 SIT days remaining - suite.Equal(29, pendingSITBalance.TotalSITDaysRemaining) + suite.Equal(28, pendingSITBalance.TotalSITDaysRemaining) - suite.Equal(ddasit.SITEntryDate.AddDate(0, 0, 89).String(), pendingSITBalance.TotalSITEndDate.UTC().String()) + suite.Equal(ddasit.SITEntryDate.AddDate(0, 0, 88).String(), pendingSITBalance.TotalSITEndDate.UTC().String()) }) suite.Run("ignores including previously denied service items in SIT balance", func() { @@ -842,7 +842,7 @@ func (suite *PaymentRequestServiceSuite) TestListShipmentPaymentSITBalance() { suite.Equal(shipment.ID.String(), pendingSITBalance.ShipmentID.String()) suite.Equal(120, pendingSITBalance.TotalSITDaysAuthorized) suite.Equal(60, pendingSITBalance.PendingSITDaysInvoiced) - suite.Equal(44, pendingSITBalance.TotalSITDaysRemaining) + suite.Equal(43, pendingSITBalance.TotalSITDaysRemaining) suite.Equal(destinationPaymentEndDate.String(), pendingSITBalance.PendingBilledEndDate.String()) suite.Nil(pendingSITBalance.PreviouslyBilledDays) }) diff --git a/pkg/services/sit_status/shipment_sit_status.go b/pkg/services/sit_status/shipment_sit_status.go index 91bdab6bc61..a519fde72b4 100644 --- a/pkg/services/sit_status/shipment_sit_status.go +++ b/pkg/services/sit_status/shipment_sit_status.go @@ -30,16 +30,16 @@ func NewShipmentSITStatus() services.ShipmentSITStatus { } type SortedShipmentSITs struct { - pastSITs models.SITServiceItemGroupings - currentSITs models.SITServiceItemGroupings - futureSITs models.SITServiceItemGroupings + PastSITs models.SITServiceItemGroupings + CurrentSITs models.SITServiceItemGroupings // Takes an array but at this time only a single CurrentSIT is supported. This could potentially be used for partial delivery current SITs + FutureSITs models.SITServiceItemGroupings } func newSortedShipmentSITs() SortedShipmentSITs { return SortedShipmentSITs{ - pastSITs: make([]models.SITServiceItemGrouping, 0), - currentSITs: make([]models.SITServiceItemGrouping, 0), - futureSITs: make([]models.SITServiceItemGrouping, 0), + PastSITs: make([]models.SITServiceItemGrouping, 0), + CurrentSITs: make([]models.SITServiceItemGrouping, 0), + FutureSITs: make([]models.SITServiceItemGrouping, 0), } } @@ -48,11 +48,11 @@ func SortShipmentSITs(sitGroupings models.SITServiceItemGroupings, today time.Ti shipmentSITs := newSortedShipmentSITs() for _, sitGrouping := range sitGroupings { if sitGrouping.Summary.SITEntryDate.After(today) { - shipmentSITs.futureSITs = append(shipmentSITs.futureSITs, sitGrouping) + shipmentSITs.FutureSITs = append(shipmentSITs.FutureSITs, sitGrouping) } else if sitGrouping.Summary.SITDepartureDate != nil && sitGrouping.Summary.SITDepartureDate.Before(today) { - shipmentSITs.pastSITs = append(shipmentSITs.pastSITs, sitGrouping) + shipmentSITs.PastSITs = append(shipmentSITs.PastSITs, sitGrouping) } else { - shipmentSITs.currentSITs = append(shipmentSITs.currentSITs, sitGrouping) + shipmentSITs.CurrentSITs = append(shipmentSITs.CurrentSITs, sitGrouping) } } return shipmentSITs @@ -73,7 +73,7 @@ func Clamp(input, min, max int) (int, error) { // Retrieve the SIT service item groupings for the provided shipment // Each SIT grouping has a top-level summary of the grouped SIT -func (f shipmentSITStatus) RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) models.SITServiceItemGroupings { +func (f shipmentSITStatus) RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) (models.SITServiceItemGroupings, error) { var shipmentSITs models.SITServiceItemGroupings year, month, day := time.Now().Date() @@ -113,16 +113,22 @@ func (f shipmentSITStatus) RetrieveShipmentSIT(appCtx appcontext.AppContext, shi } } + // Get the total SIT allowance for this shipment + totalSITAllowance, err := f.CalculateShipmentSITAllowance(appCtx, shipment) + if err != nil { + return nil, err + } + // Generate summaries for each group and append them to shipmentSITs for _, group := range groupedSITs { - summary := f.generateSITSummary(*group, today) + summary := f.generateSITSummary(*group, today, totalSITAllowance) if summary != nil { group.Summary = *summary shipmentSITs = append(shipmentSITs, *group) } } - return shipmentSITs + return shipmentSITs, nil } // Helper function to take in an MTO service item's ReServiceCode and validate it @@ -144,7 +150,7 @@ func containsReServiceCode(validCodes []models.ReServiceCode, code models.ReServ // will have discrepancies and information spread across multiple items. // This SIT summary is to make it readable down the line, and handle all complex calculations // in one, central location. -func (f shipmentSITStatus) generateSITSummary(sit models.SITServiceItemGrouping, today time.Time) *models.SITSummary { +func (f shipmentSITStatus) generateSITSummary(sit models.SITServiceItemGrouping, today time.Time, totalSitAllowance int) *models.SITSummary { if sit.ServiceItems == nil { // Return nil if there are no service items return nil @@ -201,7 +207,7 @@ func (f shipmentSITStatus) generateSITSummary(sit models.SITServiceItemGrouping, // Calculate the SIT Authorized End Date if earliestSITEntryDate != nil { - earliestSITAuthorizedEndDateValue := CalculateSITAuthorizedEndDate(len(sit.ServiceItems), calculatedTotalDaysInSIT, *earliestSITEntryDate, calculatedTotalDaysInSIT) + earliestSITAuthorizedEndDateValue := CalculateSITAuthorizedEndDate(totalSitAllowance, calculatedTotalDaysInSIT, *earliestSITEntryDate, calculatedTotalDaysInSIT, earliestSITDepartureDate) earliestSITAuthorizedEndDate = &earliestSITAuthorizedEndDateValue } @@ -241,7 +247,10 @@ func (f shipmentSITStatus) CalculateShipmentSITStatus(appCtx appcontext.AppConte year, month, day := time.Now().Date() today := time.Date(year, month, day, 0, 0, 0, 0, time.UTC) - sitGroupings := f.RetrieveShipmentSIT(appCtx, shipment) + sitGroupings, err := f.RetrieveShipmentSIT(appCtx, shipment) + if err != nil { + return nil, shipment, err + } // Sort the SIT groupings into past, current, future shipmentSITGroupings := SortShipmentSITs(sitGroupings, today) @@ -251,7 +260,7 @@ func (f shipmentSITStatus) CalculateShipmentSITStatus(appCtx appcontext.AppConte currentSIT := getCurrentSIT(shipmentSITGroupings) // There were no relevant SIT service items for this shipment - if currentSIT == nil && len(shipmentSITGroupings.pastSITs) == 0 { + if currentSIT == nil && len(shipmentSITGroupings.PastSITs) == 0 { return nil, shipment, nil } @@ -267,7 +276,7 @@ func (f shipmentSITStatus) CalculateShipmentSITStatus(appCtx appcontext.AppConte shipmentSITStatus.TotalSITDaysUsed = totalSITDaysUsedClampedResult shipmentSITStatus.CalculatedTotalDaysInSIT = CalculateTotalDaysInSIT(shipmentSITGroupings, today) shipmentSITStatus.TotalDaysRemaining = totalSITAllowance - shipmentSITStatus.TotalSITDaysUsed - shipmentSITStatus.PastSITs = shipmentSITGroupings.pastSITs + shipmentSITStatus.PastSITs = shipmentSITGroupings.PastSITs if currentSIT != nil { location := currentSIT.Summary.Location @@ -275,7 +284,7 @@ func (f shipmentSITStatus) CalculateShipmentSITStatus(appCtx appcontext.AppConte daysInSIT := daysInSIT(currentSIT.Summary.SITEntryDate, currentSIT.Summary.SITDepartureDate, today) sitEntryDate := currentSIT.Summary.SITEntryDate sitDepartureDate := currentSIT.Summary.SITDepartureDate - sitAuthorizedEndDate := CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, sitEntryDate, shipmentSITStatus.CalculatedTotalDaysInSIT) + sitAuthorizedEndDate := CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, sitEntryDate, shipmentSITStatus.CalculatedTotalDaysInSIT, sitDepartureDate) var sitCustomerContacted, sitRequestedDelivery *time.Time sitCustomerContacted = currentSIT.Summary.SITCustomerContacted sitRequestedDelivery = currentSIT.Summary.SITRequestedDelivery @@ -326,10 +335,10 @@ SIT service items that have already started are prioritized, followed by SIT service items that start in the future. */ func getCurrentSIT(shipmentSITs SortedShipmentSITs) *models.SITServiceItemGrouping { - if len(shipmentSITs.currentSITs) > 0 { - return getEarliestSIT(shipmentSITs.currentSITs) - } else if len(shipmentSITs.futureSITs) > 0 { - return getEarliestSIT(shipmentSITs.futureSITs) + if len(shipmentSITs.CurrentSITs) > 0 { + return getEarliestSIT(shipmentSITs.CurrentSITs) + } else if len(shipmentSITs.FutureSITs) > 0 { + return getEarliestSIT(shipmentSITs.FutureSITs) } return nil } @@ -355,10 +364,10 @@ func daysInSIT(sitEntryDate time.Time, sitDepartureDate *time.Time, today time.T func CalculateTotalDaysInSIT(shipmentSITs SortedShipmentSITs, today time.Time) int { totalDays := 0 - for _, pastSIT := range shipmentSITs.pastSITs { + for _, pastSIT := range shipmentSITs.PastSITs { totalDays += daysInSIT(pastSIT.Summary.SITEntryDate, pastSIT.Summary.SITDepartureDate, today) } - for _, currentSIT := range shipmentSITs.currentSITs { + for _, currentSIT := range shipmentSITs.CurrentSITs { totalDays += daysInSIT(currentSIT.Summary.SITEntryDate, currentSIT.Summary.SITDepartureDate, today) } return totalDays @@ -367,14 +376,20 @@ func CalculateTotalDaysInSIT(shipmentSITs SortedShipmentSITs, today time.Time) i // adds up all the days from pastSITs func CalculateTotalPastDaysInSIT(shipmentSITs SortedShipmentSITs, today time.Time) int { totalDays := 0 - for _, pastSIT := range shipmentSITs.pastSITs { + for _, pastSIT := range shipmentSITs.PastSITs { totalDays += daysInSIT(pastSIT.Summary.SITEntryDate, pastSIT.Summary.SITDepartureDate, today) } return totalDays } -func CalculateSITAuthorizedEndDate(totalSITAllowance int, currentDaysInSIT int, sitEntryDate time.Time, calculatedTotalDaysInSIT int) time.Time { - return sitEntryDate.AddDate(0, 0, (totalSITAllowance - (calculatedTotalDaysInSIT - currentDaysInSIT))) +func CalculateSITAuthorizedEndDate(totalSITAllowance int, currentDaysInSIT int, sitEntryDate time.Time, totalDaysInSITSoFar int, sitDepartureDate *time.Time) time.Time { + sitAuthorizedEndDate := sitEntryDate.AddDate(0, 0, (totalSITAllowance - (totalDaysInSITSoFar - currentDaysInSIT))) + // If the SIT departure date is set and it is before the currently authorized end date + // then the original SIT authorized end date should be updated to the departure date + if sitDepartureDate != nil && (sitDepartureDate.Before(sitAuthorizedEndDate) && sitDepartureDate.After(sitEntryDate)) { + sitAuthorizedEndDate = *sitDepartureDate + } + return sitAuthorizedEndDate } func (f shipmentSITStatus) CalculateShipmentsSITStatuses(appCtx appcontext.AppContext, shipments []models.MTOShipment) map[string]services.SITStatus { From a67e4f6ace093143487f086377b0fb14ca52668d Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Fri, 23 Aug 2024 13:14:43 +0000 Subject: [PATCH 06/14] removed frontend sit auth end date modification --- .../Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx | 4 +--- .../Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx index dfd6f04cdc2..60a65d593e6 100644 --- a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx +++ b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx @@ -105,9 +105,7 @@ const SitStatusTables = ({ shipment, sitExtensions, sitStatus, openModalButton, sitEntryDate = moment(sitEntryDate, swaggerDateFormat); const sitStartDateElement =

{formatDate(sitEntryDate, swaggerDateFormat, 'DD MMM YYYY')}

; const sitEndDate = - formatDateForDatePicker( - moment(sitStatus.currentSIT?.sitAuthorizedEndDate, swaggerDateFormat).subtract(1, 'days'), - ) || '\u2014'; + formatDateForDatePicker(moment(sitStatus.currentSIT?.sitAuthorizedEndDate, swaggerDateFormat)) || '\u2014'; // Previous SIT calculations and date ranges const previousDaysUsed = sitStatus.pastSITServiceItemGroupings?.map((sitGroup) => { diff --git a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx index 1776e4ec340..96c6128fed9 100644 --- a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx +++ b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.test.jsx @@ -419,7 +419,7 @@ describe('ShipmentSITDisplay', () => { const sitStartAndEndTable = await screen.findByTestId('sitStartAndEndTable'); expect(sitStartAndEndTable).toBeInTheDocument(); expect(within(sitStartAndEndTable).getByText('SIT authorized end date')).toBeInTheDocument(); - expect(within(sitStartAndEndTable).getByText('27 Aug 2021')).toBeInTheDocument(); + expect(within(sitStartAndEndTable).getByText('28 Aug 2021')).toBeInTheDocument(); }); it('does not render pastSitDepartureDateTable if current sit', async () => { render( From 78ace59d00a7d82c556e7450807a96ac5bf81fc3 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Fri, 23 Aug 2024 15:32:56 +0000 Subject: [PATCH 07/14] fix playwright days calc test --- playwright/tests/office/txo/sitUpdates.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playwright/tests/office/txo/sitUpdates.spec.js b/playwright/tests/office/txo/sitUpdates.spec.js index ea04b261e6f..c407dd0ca32 100644 --- a/playwright/tests/office/txo/sitUpdates.spec.js +++ b/playwright/tests/office/txo/sitUpdates.spec.js @@ -103,8 +103,8 @@ test.describe('TOO user', () => { .textContent(); expect(daysApprovedCapture).toEqual('90'); - expect(daysUsedCapture).toEqual('61'); // 30 days in past origin sit, 31 days in destination sit - expect(daysLeftCapture).toEqual('29'); // of the 90 authorized, 61 have been used + expect(daysUsedCapture).toEqual('62'); // 31 days in past origin sit, 31 days in destination sit + expect(daysLeftCapture).toEqual('28'); // of the 90 authorized, 62 have been used }); test('is unable to decrease the SIT authorization below the number of days already used', async ({ page }) => { @@ -248,7 +248,7 @@ test.describe('TOO user', () => { await expect(page.getByText('Total days remaining')).toBeVisible(); await expect(page.getByText('SIT start date').nth(0)).toBeVisible(); await expect(page.getByText('SIT authorized end date')).toBeVisible(); - await expect(page.getByText('Calculated total SIT days')).toBeVisible(); + await expect(page.getByText('Total days in destination SIT')).toBeVisible(); }); test('is showing the SIT Departure Date section', async ({ page }) => { // navigate to MTO tab From 125c98105251f29384be3f3796c5eba5a5031d1d Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Fri, 23 Aug 2024 17:29:43 +0000 Subject: [PATCH 08/14] e2e testing for sit date fixes --- pkg/testdatagen/testharness/dispatch.go | 3 + pkg/testdatagen/testharness/make_move.go | 136 ++++++++++++++++++ .../tests/office/txo/sitUpdates.spec.js | 133 ++++++++++++++++- playwright/tests/utils/testharness.js | 8 ++ .../ShipmentSITDisplay/ShipmentSITDisplay.jsx | 2 +- 5 files changed, 280 insertions(+), 2 deletions(-) diff --git a/pkg/testdatagen/testharness/dispatch.go b/pkg/testdatagen/testharness/dispatch.go index ff91b5b0890..8033ca02825 100644 --- a/pkg/testdatagen/testharness/dispatch.go +++ b/pkg/testdatagen/testharness/dispatch.go @@ -59,6 +59,9 @@ var actionDispatcher = map[string]actionFunc{ "HHGMoveInSIT": func(appCtx appcontext.AppContext) testHarnessResponse { return MakeHHGMoveInSIT(appCtx) }, + "HHGMoveWithPastSITs": func(appCtx appcontext.AppContext) testHarnessResponse { + return HHGMoveWithPastSITs(appCtx) + }, "HHGMoveInSITNoDestinationSITOutDate": func(appCtx appcontext.AppContext) testHarnessResponse { return MakeHHGMoveInSITNoDestinationSITOutDate(appCtx) }, diff --git a/pkg/testdatagen/testharness/make_move.go b/pkg/testdatagen/testharness/make_move.go index 54fd95f67b4..29bce308263 100644 --- a/pkg/testdatagen/testharness/make_move.go +++ b/pkg/testdatagen/testharness/make_move.go @@ -5321,6 +5321,142 @@ func MakeHHGMoveInSIT(appCtx appcontext.AppContext) models.Move { return move } +// Creates an HHG move with a past Origin and Destination SIT +func HHGMoveWithPastSITs(appCtx appcontext.AppContext) models.Move { + userUploader := newUserUploader(appCtx) + userInfo := newUserInfo("customer") + + user := factory.BuildUser(appCtx.DB(), []factory.Customization{ + { + Model: models.User{ + OktaEmail: userInfo.email, + Active: true, + }, + }, + }, nil) + customer := factory.BuildExtendedServiceMember(appCtx.DB(), []factory.Customization{ + { + Model: models.ServiceMember{ + PersonalEmail: &userInfo.email, + FirstName: &userInfo.firstName, + LastName: &userInfo.lastName, + CacValidated: true, + }, + }, + { + Model: user, + LinkOnly: true, + }, + }, nil) + dependentsAuthorized := true + sitDaysAllowance := 90 + entitlements := factory.BuildEntitlement(appCtx.DB(), []factory.Customization{ + { + Model: models.Entitlement{ + DependentsAuthorized: &dependentsAuthorized, + StorageInTransit: &sitDaysAllowance, + }, + }, + }, nil) + orders := factory.BuildOrder(appCtx.DB(), []factory.Customization{ + { + Model: customer, + LinkOnly: true, + }, + { + Model: entitlements, + LinkOnly: true, + }, + { + Model: models.UserUpload{}, + ExtendedParams: &factory.UserUploadExtendedParams{ + UserUploader: userUploader, + AppContext: appCtx, + }, + }, + }, nil) + now := time.Now() + move := factory.BuildMove(appCtx.DB(), []factory.Customization{ + { + Model: orders, + LinkOnly: true, + }, + { + Model: models.Move{ + Status: models.MoveStatusAPPROVALSREQUESTED, + AvailableToPrimeAt: &now, + }, + }, + }, nil) + estimatedWeight := unit.Pound(1400) + actualWeight := unit.Pound(2000) + + requestedPickupDate := now.AddDate(0, 3, 0) + requestedDeliveryDate := requestedPickupDate.AddDate(0, 1, 0) + // pickupAddress := factory.BuildAddress(appCtx.DB(), nil, nil) + + shipment := factory.BuildMTOShipment(appCtx.DB(), []factory.Customization{ + { + Model: models.MTOShipment{ + PrimeEstimatedWeight: &estimatedWeight, + PrimeActualWeight: &actualWeight, + ShipmentType: models.MTOShipmentTypeHHG, + Status: models.MTOShipmentStatusApproved, + RequestedPickupDate: &requestedPickupDate, + RequestedDeliveryDate: &requestedDeliveryDate, + SITDaysAllowance: &sitDaysAllowance, + }, + }, + { + Model: move, + LinkOnly: true, + }, + }, nil) + + agentUserInfo := newUserInfo("agent") + factory.BuildMTOAgent(appCtx.DB(), []factory.Customization{ + { + Model: shipment, + LinkOnly: true, + }, + {Model: models.MTOAgent{ + FirstName: &agentUserInfo.firstName, + LastName: &agentUserInfo.lastName, + Email: &agentUserInfo.email, + MTOAgentType: models.MTOAgentReleasing, + }, + }, + }, nil) + + fourMonthsAgo := now.AddDate(0, 0, -120) + threeMonthsAgo := now.AddDate(0, 0, -90) + twoMonthsAgo := now.AddDate(0, 0, -60) + oneMonthAgo := now.AddDate(0, 0, -30) + factory.BuildOriginSITServiceItems(appCtx.DB(), move, shipment, &fourMonthsAgo, &threeMonthsAgo) + destSITItems := factory.BuildDestSITServiceItems(appCtx.DB(), move, shipment, &twoMonthsAgo, &oneMonthAgo) + for i := range destSITItems { + if destSITItems[i].ReService.Code == models.ReServiceCodeDDDSIT { + sitAddressUpdate := factory.BuildSITAddressUpdate(appCtx.DB(), []factory.Customization{ + { + Model: destSITItems[i], + LinkOnly: true, + }, + }, []factory.Trait{factory.GetTraitSITAddressUpdateOver50Miles}) + + originalAddress := sitAddressUpdate.OldAddress + finalAddress := sitAddressUpdate.NewAddress + destSITItems[i].SITDestinationOriginalAddressID = &originalAddress.ID + destSITItems[i].SITDestinationFinalAddressID = &finalAddress.ID + err := appCtx.DB().Update(&destSITItems[i]) + if err != nil { + log.Panic(fmt.Errorf("failed to update sit service item: %w", err)) + } + } + } + + return move +} + func MakeHHGMoveInSITNoExcessWeight(appCtx appcontext.AppContext) models.Move { userUploader := newUserUploader(appCtx) userInfo := newUserInfo("customer") diff --git a/playwright/tests/office/txo/sitUpdates.spec.js b/playwright/tests/office/txo/sitUpdates.spec.js index c407dd0ca32..f89fb28d779 100644 --- a/playwright/tests/office/txo/sitUpdates.spec.js +++ b/playwright/tests/office/txo/sitUpdates.spec.js @@ -1,5 +1,4 @@ // @ts-check - import { test, expect } from '../../utils/office/officeTest'; import { TooFlowPage } from './tooTestFixture'; @@ -8,6 +7,138 @@ test.describe('TOO user', () => { /** @type {TooFlowPage} */ let tooFlowPage; + test.describe('previewing shipment with current SIT with past SIT', () => { + test.beforeEach(async ({ officePage }) => { + // build move in SIT with 90 days authorized and without pending extension requests + // SIT entry date of 30 days ago, no departure date so it is current + const move = await officePage.testHarness.buildHHGMoveInSIT(); + await officePage.signInAsNewTOOUser(); + tooFlowPage = new TooFlowPage(officePage, move); + await tooFlowPage.waitForLoading(); + await officePage.tooNavigateToMove(tooFlowPage.moveLocator); + }); + + test('sum of days is correct between past Origin SIT and current Destination SIT', async ({ page }) => { + // navigate to MTO tab + await page.getByTestId('MoveTaskOrder-Tab').click(); + await tooFlowPage.waitForPage.moveTaskOrder(); + // assert that days authorization is 90 + await expect(page.getByTestId('sitStatusTable').getByText('90', { exact: true }).first()).toBeVisible(); + // get today + const today = new Date(); + // get 1 month ago + const oneMonthAgo = new Date(today); + oneMonthAgo.setMonth(today.getMonth() - 1); + // get 2 months ago + const twoMonthsAgo = new Date(today); + twoMonthsAgo.setMonth(today.getMonth() - 2); + // get the time diff + const timeDiff = oneMonthAgo.getTime() - twoMonthsAgo.getTime(); + // get the days, converting milliseconds to days + const daysDiff = timeDiff / (1000 * 60 * 60 * 24); + // be inclusive of the last day + const totalDaysBetweenOneMonthInclusive = daysDiff + 1; + // get sums + const totalDaysUsed = totalDaysBetweenOneMonthInclusive * 2; // Origin and Dest sit each used 1 month + const remainingDays = 90 - totalDaysUsed; + // assert that days used is the following sum + // - past origin SIT (entry 2 months ago, departure 1 month ago) + // - current destination SIT (entry 1 month ago, departure not given yet) + await expect( + page.getByTestId('sitStatusTable').getByText(`${totalDaysUsed}`, { exact: true }).first(), + ).toBeVisible(); + // assert that days remaining is authorized minus totalDaysUsed + await expect( + page.getByTestId('sitStatusTable').getByText(`${remainingDays}`, { exact: true }).first(), + ).toBeVisible(); + // assert that total days in destination sit is 1 month, inclusive of last day + await expect( + page + .getByTestId('sitStartAndEndTable') + .getByText(`${totalDaysBetweenOneMonthInclusive}`, { exact: true }) + .first(), + ).toBeVisible(); + + // get authorized end date as 90 days from the origin start date (two months ago) + const ninetyDaysFromStartDate = new Date(twoMonthsAgo); + ninetyDaysFromStartDate.setDate(ninetyDaysFromStartDate.getDate() + 90); + // format + const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(ninetyDaysFromStartDate); + const month = new Intl.DateTimeFormat('en', { month: 'short' }).format(ninetyDaysFromStartDate); + const year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(ninetyDaysFromStartDate); + const expectedAuthorizedEndDate = `${day} ${month} ${year}`; + // assert + await expect( + page.getByTestId('sitStartAndEndTable').getByText(`${expectedAuthorizedEndDate}`, { exact: true }).first(), + ).toBeVisible(); + }); + }); + + test.describe('previewing shipment with past origin and destination SIT', () => { + test.beforeEach(async ({ officePage }) => { + // build move in SIT with 90 days authorized and without pending extension requests + // Origin sit had an entry date of four months ago, departure date of three months ago + // Destination sit had an entry date of two months ago, departure date of one month ago + const move = await officePage.testHarness.buildHHGMoveWithPastSITs(); + await officePage.signInAsNewTOOUser(); + tooFlowPage = new TooFlowPage(officePage, move); + await tooFlowPage.waitForLoading(); + await officePage.tooNavigateToMove(tooFlowPage.moveLocator); + }); + + test('sum of days is correct between past Origin SIT and past Destination SIT', async ({ page }) => { + // navigate to MTO tab + await page.getByTestId('MoveTaskOrder-Tab').click(); + await tooFlowPage.waitForPage.moveTaskOrder(); + // assert that days authorization is 90 + await expect(page.getByTestId('sitStatusTable').getByText('90', { exact: true }).first()).toBeVisible(); + // get today + const today = new Date(); + // get months + const destinationDepartureDate = new Date(today); + destinationDepartureDate.setMonth(today.getMonth() - 1); + const destinationEntryDate = new Date(today); + destinationEntryDate.setMonth(today.getMonth() - 2); + const originDepartureDate = new Date(today); + originDepartureDate.setMonth(today.getMonth() - 3); + const originEntryDate = new Date(today); + originEntryDate.setMonth(today.getMonth() - 4); + // get the time diff + const destinationTimeDiff = destinationDepartureDate.getTime() - destinationEntryDate.getTime(); + const originTimeDiff = originDepartureDate.getTime() - originEntryDate.getTime(); + // get the days, converting milliseconds to days + const destinationDaysDiff = destinationTimeDiff / (1000 * 60 * 60 * 24); + const originDaysDiff = originTimeDiff / (1000 * 60 * 60 * 24); + // be inclusive of the last day + const totalDaysBetweenDestinationInclusive = destinationDaysDiff + 1; + const totalDaysBetweenOriginInclusive = originDaysDiff + 1; + // get sums + const totalDaysUsed = totalDaysBetweenDestinationInclusive + totalDaysBetweenOriginInclusive; + const remainingDays = 90 - totalDaysUsed; + // assert sums + await expect( + page.getByTestId('sitStatusTable').getByText(`${totalDaysUsed}`, { exact: true }).first(), + ).toBeVisible(); + // assert that days remaining is authorized minus totalDaysUsed + await expect( + page.getByTestId('sitStatusTable').getByText(`${remainingDays}`, { exact: true }).first(), + ).toBeVisible(); + // assert previous sit days + await expect( + page + .getByTestId('previouslyUsedSitTable') + .getByText(`${totalDaysBetweenDestinationInclusive} days at destination`, { exact: false }) + .first(), + ).toBeVisible(); + await expect( + page + .getByTestId('previouslyUsedSitTable') + .getByText(`${totalDaysBetweenOriginInclusive} days at origin`, { exact: false }) + .first(), + ).toBeVisible(); + }); + }); + test.describe('updating a move shipment in SIT', () => { test.beforeEach(async ({ officePage }) => { // build move in SIT with 90 days authorized and without pending extension requests diff --git a/playwright/tests/utils/testharness.js b/playwright/tests/utils/testharness.js index ff4d7f61dc3..1faf82f5ee5 100644 --- a/playwright/tests/utils/testharness.js +++ b/playwright/tests/utils/testharness.js @@ -177,6 +177,14 @@ export class TestHarness { return this.buildDefault('HHGMoveInSIT'); } + /** + * Use testharness to build a move with an hhg shipment with a past origin and destination SIT + * @returns {Promise} + */ + async buildHHGMoveWithPastSITs() { + return this.buildDefault('HHGMoveWithPastSITs'); + } + /** * * Use testharness to build a move with an hhg shipment in SIT without destination address * @returns {Promise} diff --git a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx index 60a65d593e6..3d6712fd034 100644 --- a/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx +++ b/src/components/Office/ShipmentSITDisplay/ShipmentSITDisplay.jsx @@ -201,7 +201,7 @@ const SitStatusTables = ({ shipment, sitExtensions, sitStatus, openModalButton, {/* Past SIT Service Items Info Section */} {sitStatus.pastSITServiceItemGroupings && ( <> -
+
{!sitStatus.currentSIT && ( From 415c97bab6222a2ad49fa3528797915c2ca3a88e Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Fri, 23 Aug 2024 18:59:07 +0000 Subject: [PATCH 09/14] fixed tests --- .../mto_service_item/mto_service_item_updater_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/services/mto_service_item/mto_service_item_updater_test.go b/pkg/services/mto_service_item/mto_service_item_updater_test.go index 495f9f53493..0068951430e 100644 --- a/pkg/services/mto_service_item/mto_service_item_updater_test.go +++ b/pkg/services/mto_service_item/mto_service_item_updater_test.go @@ -477,8 +477,8 @@ func (suite *MTOServiceItemServiceSuite) TestMTOServiceItemUpdater() { var postUpdatedServiceItemShipment models.MTOShipment suite.DB().Q().Find(&postUpdatedServiceItemShipment, shipment.ID) suite.NotNil(postUpdatedServiceItemShipment) - // Verify the departure date is before the original shipment authorized end date - suite.True(updatedServiceItem.SITDepartureDate.Before(*shipmentWithCalculatedStatus.DestinationSITAuthEndDate)) + // Verify the departure date is equal to the shipment SIT status departure date (Previously shipment SIT status would have an improper end date due to calc issues. This was fixed in B-20967) + suite.True(updatedServiceItem.SITDepartureDate.Equal(*shipmentWithCalculatedStatus.DestinationSITAuthEndDate)) // Verify the updated shipment authorized end date is equal to the departure date // Truncate to the nearest day. This is because the shipment only inherits the day, month, year from the service item, not the hour, minute, or second suite.True(updatedServiceItem.SITDepartureDate.Truncate(24 * time.Hour).Equal(postUpdatedServiceItemShipment.DestinationSITAuthEndDate.Truncate(24 * time.Hour))) @@ -605,8 +605,8 @@ func (suite *MTOServiceItemServiceSuite) TestMTOServiceItemUpdater() { var postUpdatedServiceItemShipment models.MTOShipment suite.DB().Q().Find(&postUpdatedServiceItemShipment, shipment.ID) suite.NotNil(postUpdatedServiceItemShipment) - // Verify the departure date is before the original shipment authorized end date - suite.True(updatedServiceItem.SITDepartureDate.Before(*shipmentWithCalculatedStatus.OriginSITAuthEndDate)) + // Verify the departure date is equal to the shipment SIT status departure date (Previously shipment SIT status would have an improper end date due to calc issues. This was fixed in B-20967) + suite.True(updatedServiceItem.SITDepartureDate.Equal(*shipmentWithCalculatedStatus.OriginSITAuthEndDate)) // Verify the updated shipment authorized end date is equal to the departure date // Truncate to the nearest day. This is because the shipment only inherits the day, month, year from the service item, not the hour, minute, or second suite.True(updatedServiceItem.SITDepartureDate.Truncate(24 * time.Hour).Equal(postUpdatedServiceItemShipment.OriginSITAuthEndDate.Truncate(24 * time.Hour))) From 40d3d58a00ba76120f3285ebd92994bf3976dbf1 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Wed, 28 Aug 2024 14:03:17 +0000 Subject: [PATCH 10/14] adjust sit auth end date calculation --- pkg/services/sit_status/shipment_sit_status.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/services/sit_status/shipment_sit_status.go b/pkg/services/sit_status/shipment_sit_status.go index a519fde72b4..60d96381adb 100644 --- a/pkg/services/sit_status/shipment_sit_status.go +++ b/pkg/services/sit_status/shipment_sit_status.go @@ -384,6 +384,15 @@ func CalculateTotalPastDaysInSIT(shipmentSITs SortedShipmentSITs, today time.Tim func CalculateSITAuthorizedEndDate(totalSITAllowance int, currentDaysInSIT int, sitEntryDate time.Time, totalDaysInSITSoFar int, sitDepartureDate *time.Time) time.Time { sitAuthorizedEndDate := sitEntryDate.AddDate(0, 0, (totalSITAllowance - (totalDaysInSITSoFar - currentDaysInSIT))) + // Subtract the last day to be inclusive of counting it + // Eg, this func successfully counts totalSITAllowance days from SITEntryDate, but per customer requirements, they will + // then count that last day too. So if given 90 days of allowance, we'd get Aug 20 2024 thru Nov 18 2024. 90 days as expected + // but then if you count the last day, it gets 91. Thus making the calculation incorrect. This is why we subtract a day, to be inclusive of it + sitAuthorizedEndDate = sitAuthorizedEndDate.AddDate(0, 0, -1) + // Ensure that the authorized end date does not go before the entry date + if sitAuthorizedEndDate.Before(sitEntryDate) { + sitAuthorizedEndDate = sitEntryDate + } // If the SIT departure date is set and it is before the currently authorized end date // then the original SIT authorized end date should be updated to the departure date if sitDepartureDate != nil && (sitDepartureDate.Before(sitAuthorizedEndDate) && sitDepartureDate.After(sitEntryDate)) { From 0fba66db328d602457a16fbdc19877db9bf716fd Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Wed, 28 Aug 2024 14:04:12 +0000 Subject: [PATCH 11/14] adjust tests --- .../payment_request_shipments_sit_balance_test.go | 4 ++-- playwright/tests/office/txo/sitUpdates.spec.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go b/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go index 635ab88f58a..30b8458ff31 100644 --- a/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go +++ b/pkg/services/payment_request/payment_request_shipments_sit_balance_test.go @@ -203,7 +203,7 @@ func (suite *PaymentRequestServiceSuite) TestListShipmentPaymentSITBalance() { suite.Equal(paymentEndDate.String(), pendingSITBalance.PendingBilledEndDate.String()) suite.Equal(120, pendingSITBalance.TotalSITDaysAuthorized) suite.Equal(89, pendingSITBalance.TotalSITDaysRemaining) - suite.Equal(doasit.SITEntryDate.AddDate(0, 0, 119).String(), pendingSITBalance.TotalSITEndDate.UTC().String()) + suite.Equal(doasit.SITEntryDate.AddDate(0, 0, 118).String(), pendingSITBalance.TotalSITEndDate.UTC().String()) }) suite.Run("calculates pending destination SIT balance when origin was invoiced previously", func() { @@ -530,7 +530,7 @@ func (suite *PaymentRequestServiceSuite) TestListShipmentPaymentSITBalance() { // 120 total authorized - 30 from origin SIT - 60 from destination SIT = 30 SIT days remaining suite.Equal(28, pendingSITBalance.TotalSITDaysRemaining) - suite.Equal(ddasit.SITEntryDate.AddDate(0, 0, 88).String(), pendingSITBalance.TotalSITEndDate.UTC().String()) + suite.Equal(ddasit.SITEntryDate.AddDate(0, 0, 87).String(), pendingSITBalance.TotalSITEndDate.UTC().String()) }) suite.Run("ignores including previously denied service items in SIT balance", func() { diff --git a/playwright/tests/office/txo/sitUpdates.spec.js b/playwright/tests/office/txo/sitUpdates.spec.js index f89fb28d779..96cf3b7ceed 100644 --- a/playwright/tests/office/txo/sitUpdates.spec.js +++ b/playwright/tests/office/txo/sitUpdates.spec.js @@ -60,12 +60,12 @@ test.describe('TOO user', () => { ).toBeVisible(); // get authorized end date as 90 days from the origin start date (two months ago) - const ninetyDaysFromStartDate = new Date(twoMonthsAgo); - ninetyDaysFromStartDate.setDate(ninetyDaysFromStartDate.getDate() + 90); + const ninetyDaysFromStartDateInclusive = new Date(twoMonthsAgo); + ninetyDaysFromStartDateInclusive.setDate(ninetyDaysFromStartDateInclusive.getDate() + 89); // Use 89 because the last day is counted as a whole day // format - const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(ninetyDaysFromStartDate); - const month = new Intl.DateTimeFormat('en', { month: 'short' }).format(ninetyDaysFromStartDate); - const year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(ninetyDaysFromStartDate); + const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(ninetyDaysFromStartDateInclusive); + const month = new Intl.DateTimeFormat('en', { month: 'short' }).format(ninetyDaysFromStartDateInclusive); + const year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(ninetyDaysFromStartDateInclusive); const expectedAuthorizedEndDate = `${day} ${month} ${year}`; // assert await expect( From 1aaac9f7ab9d280f8072600c35052e9228754b30 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Tue, 3 Sep 2024 11:36:11 -0400 Subject: [PATCH 12/14] fixed flaky tests in int --- .../tests/office/txo/sitUpdates.spec.js | 67 +++++++++++-------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/playwright/tests/office/txo/sitUpdates.spec.js b/playwright/tests/office/txo/sitUpdates.spec.js index 96cf3b7ceed..cc7bd670288 100644 --- a/playwright/tests/office/txo/sitUpdates.spec.js +++ b/playwright/tests/office/txo/sitUpdates.spec.js @@ -7,6 +7,20 @@ test.describe('TOO user', () => { /** @type {TooFlowPage} */ let tooFlowPage; + // Helper func to calculate days between 2 given dates + // This is to support months of 30 and 31 dayss + const calculateDaysDiff = (startDate, endDate) => { + let days = 0; + const currentDate = new Date(startDate); + + while (currentDate < endDate) { + days += 1; + currentDate.setDate(currentDate.getDate() + 1); + } + + return days; + }; + test.describe('previewing shipment with current SIT with past SIT', () => { test.beforeEach(async ({ officePage }) => { // build move in SIT with 90 days authorized and without pending extension requests @@ -32,14 +46,11 @@ test.describe('TOO user', () => { // get 2 months ago const twoMonthsAgo = new Date(today); twoMonthsAgo.setMonth(today.getMonth() - 2); - // get the time diff - const timeDiff = oneMonthAgo.getTime() - twoMonthsAgo.getTime(); - // get the days, converting milliseconds to days - const daysDiff = timeDiff / (1000 * 60 * 60 * 24); - // be inclusive of the last day - const totalDaysBetweenOneMonthInclusive = daysDiff + 1; + // get days between + const daysBetweenTwoMonthsAgoAndOneMonthAgo = calculateDaysDiff(twoMonthsAgo, oneMonthAgo); + const daysBetweenOneMonthAgoAndToday = calculateDaysDiff(oneMonthAgo, today); // get sums - const totalDaysUsed = totalDaysBetweenOneMonthInclusive * 2; // Origin and Dest sit each used 1 month + const totalDaysUsed = daysBetweenTwoMonthsAgoAndOneMonthAgo + daysBetweenOneMonthAgoAndToday; const remainingDays = 90 - totalDaysUsed; // assert that days used is the following sum // - past origin SIT (entry 2 months ago, departure 1 month ago) @@ -53,19 +64,23 @@ test.describe('TOO user', () => { ).toBeVisible(); // assert that total days in destination sit is 1 month, inclusive of last day await expect( - page - .getByTestId('sitStartAndEndTable') - .getByText(`${totalDaysBetweenOneMonthInclusive}`, { exact: true }) - .first(), + page.getByTestId('sitStartAndEndTable').getByText(`${daysBetweenOneMonthAgoAndToday}`, { exact: true }).first(), ).toBeVisible(); - // get authorized end date as 90 days from the origin start date (two months ago) - const ninetyDaysFromStartDateInclusive = new Date(twoMonthsAgo); - ninetyDaysFromStartDateInclusive.setDate(ninetyDaysFromStartDateInclusive.getDate() + 89); // Use 89 because the last day is counted as a whole day + // Get the SIT start date from the UI + const sitStartDateText = await page.getByTestId('sitStartAndEndTable').locator('td').nth(0).innerText(); + const sitStartDate = new Date(sitStartDateText); + + // Calculate the authorized end date by adding 90 days to the start date and then subtracting total days used + const authorizedEndDate = new Date(sitStartDate); + // Use 89 because the last day is counted as a whole day + // Subtract by "daysBetweenTwoMonthsAgoAndOneMonthAgo" (past SIT days) instead of total days used + // This is because the authorized end date is based on the remaining days at the start of the current SIT + authorizedEndDate.setDate(authorizedEndDate.getDate() + 89 - daysBetweenTwoMonthsAgoAndOneMonthAgo); // format - const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(ninetyDaysFromStartDateInclusive); - const month = new Intl.DateTimeFormat('en', { month: 'short' }).format(ninetyDaysFromStartDateInclusive); - const year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(ninetyDaysFromStartDateInclusive); + const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(authorizedEndDate); + const month = new Intl.DateTimeFormat('en', { month: 'short' }).format(authorizedEndDate); + const year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(authorizedEndDate); const expectedAuthorizedEndDate = `${day} ${month} ${year}`; // assert await expect( @@ -103,17 +118,11 @@ test.describe('TOO user', () => { originDepartureDate.setMonth(today.getMonth() - 3); const originEntryDate = new Date(today); originEntryDate.setMonth(today.getMonth() - 4); - // get the time diff - const destinationTimeDiff = destinationDepartureDate.getTime() - destinationEntryDate.getTime(); - const originTimeDiff = originDepartureDate.getTime() - originEntryDate.getTime(); - // get the days, converting milliseconds to days - const destinationDaysDiff = destinationTimeDiff / (1000 * 60 * 60 * 24); - const originDaysDiff = originTimeDiff / (1000 * 60 * 60 * 24); - // be inclusive of the last day - const totalDaysBetweenDestinationInclusive = destinationDaysDiff + 1; - const totalDaysBetweenOriginInclusive = originDaysDiff + 1; + // days between + const totalDaysBetweenDestination = calculateDaysDiff(destinationEntryDate, destinationDepartureDate); + const totalDaysBetweenOrigin = calculateDaysDiff(originEntryDate, originDepartureDate); // get sums - const totalDaysUsed = totalDaysBetweenDestinationInclusive + totalDaysBetweenOriginInclusive; + const totalDaysUsed = totalDaysBetweenDestination + totalDaysBetweenOrigin; const remainingDays = 90 - totalDaysUsed; // assert sums await expect( @@ -127,13 +136,13 @@ test.describe('TOO user', () => { await expect( page .getByTestId('previouslyUsedSitTable') - .getByText(`${totalDaysBetweenDestinationInclusive} days at destination`, { exact: false }) + .getByText(`${totalDaysBetweenDestination} days at destination`, { exact: false }) .first(), ).toBeVisible(); await expect( page .getByTestId('previouslyUsedSitTable') - .getByText(`${totalDaysBetweenOriginInclusive} days at origin`, { exact: false }) + .getByText(`${totalDaysBetweenOrigin} days at origin`, { exact: false }) .first(), ).toBeVisible(); }); From 2e327a9a63c06c75ec5269a49f5da00104552759 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Mon, 23 Sep 2024 14:48:41 +0000 Subject: [PATCH 13/14] manual introduction of int based merge conflict resolution --- pkg/testdatagen/testharness/make_move.go | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/pkg/testdatagen/testharness/make_move.go b/pkg/testdatagen/testharness/make_move.go index 29bce308263..23e8665a889 100644 --- a/pkg/testdatagen/testharness/make_move.go +++ b/pkg/testdatagen/testharness/make_move.go @@ -5433,26 +5433,7 @@ func HHGMoveWithPastSITs(appCtx appcontext.AppContext) models.Move { twoMonthsAgo := now.AddDate(0, 0, -60) oneMonthAgo := now.AddDate(0, 0, -30) factory.BuildOriginSITServiceItems(appCtx.DB(), move, shipment, &fourMonthsAgo, &threeMonthsAgo) - destSITItems := factory.BuildDestSITServiceItems(appCtx.DB(), move, shipment, &twoMonthsAgo, &oneMonthAgo) - for i := range destSITItems { - if destSITItems[i].ReService.Code == models.ReServiceCodeDDDSIT { - sitAddressUpdate := factory.BuildSITAddressUpdate(appCtx.DB(), []factory.Customization{ - { - Model: destSITItems[i], - LinkOnly: true, - }, - }, []factory.Trait{factory.GetTraitSITAddressUpdateOver50Miles}) - - originalAddress := sitAddressUpdate.OldAddress - finalAddress := sitAddressUpdate.NewAddress - destSITItems[i].SITDestinationOriginalAddressID = &originalAddress.ID - destSITItems[i].SITDestinationFinalAddressID = &finalAddress.ID - err := appCtx.DB().Update(&destSITItems[i]) - if err != nil { - log.Panic(fmt.Errorf("failed to update sit service item: %w", err)) - } - } - } + factory.BuildDestSITServiceItems(appCtx.DB(), move, shipment, &twoMonthsAgo, &oneMonthAgo) return move } From 451657aea46da1eca369ae443db6bc4a99370273 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Mon, 23 Sep 2024 15:46:53 +0000 Subject: [PATCH 14/14] mocks gen --- pkg/services/mocks/ShipmentSITStatus.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/services/mocks/ShipmentSITStatus.go b/pkg/services/mocks/ShipmentSITStatus.go index c9195ced409..64aff2c98cc 100644 --- a/pkg/services/mocks/ShipmentSITStatus.go +++ b/pkg/services/mocks/ShipmentSITStatus.go @@ -90,10 +90,14 @@ func (_m *ShipmentSITStatus) CalculateShipmentsSITStatuses(appCtx appcontext.App } // RetrieveShipmentSIT provides a mock function with given fields: appCtx, shipment -func (_m *ShipmentSITStatus) RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) models.SITServiceItemGroupings { +func (_m *ShipmentSITStatus) RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) (models.SITServiceItemGroupings, error) { ret := _m.Called(appCtx, shipment) var r0 models.SITServiceItemGroupings + var r1 error + if rf, ok := ret.Get(0).(func(appcontext.AppContext, models.MTOShipment) (models.SITServiceItemGroupings, error)); ok { + return rf(appCtx, shipment) + } if rf, ok := ret.Get(0).(func(appcontext.AppContext, models.MTOShipment) models.SITServiceItemGroupings); ok { r0 = rf(appCtx, shipment) } else { @@ -102,7 +106,13 @@ func (_m *ShipmentSITStatus) RetrieveShipmentSIT(appCtx appcontext.AppContext, s } } - return r0 + if rf, ok := ret.Get(1).(func(appcontext.AppContext, models.MTOShipment) error); ok { + r1 = rf(appCtx, shipment) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } // NewShipmentSITStatus creates a new instance of ShipmentSITStatus. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.