Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B 17910 hal sc creates or modifies a shipment int #12035

Closed
10 changes: 8 additions & 2 deletions pkg/assets/sql_scripts/move_history_fetcher.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ WITH move AS (
move_logs AS (
SELECT
audit_history.*,
NULL AS context,
jsonb_agg(jsonb_strip_nulls(
jsonb_build_object(
'closeout_office_name',
(SELECT transportation_offices.name FROM transportation_offices WHERE transportation_offices.id = uuid(c.closeout_office_id))
))
)::TEXT AS context,
NULL AS context_id
FROM
audit_history
JOIN move ON audit_history.object_id = move.id
WHERE audit_history.table_name = 'moves'
JOIN jsonb_to_record(audit_history.changed_data) as c(closeout_office_id TEXT) on TRUE
WHERE audit_history.table_name = 'moves' group by audit_history.id
),
move_orders AS (
SELECT
Expand Down
3 changes: 3 additions & 0 deletions src/constants/MoveHistory/Database/FieldMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,8 @@ export default {
paid_with_gtcc: 'Paid with gtcc',
missing_receipt: 'Missing receipt',
ppm_type: 'PPM type',
// distance: 'Shipping distance',
// we signify miles as the unit, this may be reworded to avoid redundancy
distance: 'Distance in miles',
closeout_office_name: 'Closeout office',
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';

import a from 'constants/MoveHistory/Database/Actions';
import o from 'constants/MoveHistory/UIDisplay/Operations';
import t from 'constants/MoveHistory/Database/Tables';
import LabeledDetails from 'pages/Office/MoveHistory/LabeledDetails';
Expand All @@ -17,7 +16,7 @@ const formatChangedValues = (historyRecord) => {
};

export default {
action: a.INSERT,
action: '*',
eventName: o.createMTOShipment,
tableName: t.mto_shipments,
getEventNameDisplay: () => 'Created shipment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default {
case t.addresses:
return <> Updated shipment </>;
case t.moves:
return <> Updated move </>;
default:
return <> Updated move </>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';

import styles from 'pages/Office/MoveHistory/LabeledDetails.module.scss';
import a from 'constants/MoveHistory/Database/Actions';
import o from 'constants/MoveHistory/UIDisplay/Operations';
import t from 'constants/MoveHistory/Database/Tables';

export default {
action: a.UPDATE,
eventName: o.updateCloseoutOffice,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: (historyRecord) => {
const result = historyRecord.context?.find((e) => e.closeout_office_name);
const displayLineItem =
(result?.closeout_office_name && (
<>
<b>Closeout office</b>: {result.closeout_office_name}
</>
)) ||
'-';
return (
(historyRecord?.oldValues?.locator && (
<>
<span className={styles.shipmentType}>#{historyRecord?.oldValues?.locator}</span>
{displayLineItem}
</>
)) ||
displayLineItem
);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { render, screen } from '@testing-library/react';

import getTemplate from 'constants/MoveHistory/TemplateManager';
import e from 'constants/MoveHistory/EventTemplates/UpdateCloseoutOffice/updateCloseoutOffice';

describe('when given an updateCloseoutOffice history record', () => {
const historyRecord = {
action: 'UPDATE',
eventName: 'updateCloseoutOffice',
tableName: 'moves',
};

it('correctly matches updateCloseoutOffice template', () => {
const result = getTemplate(historyRecord);
expect(result).toMatchObject(e);
});

it('renders the default details in the details column when updateCloseoutOffice key is not present ', () => {
const template = getTemplate(historyRecord);
const ren = render(template.getDetails(historyRecord));
ren.debug();
expect(screen.getByText('-')).toBeInTheDocument();
});

it('renders the proper message in the details column when updateCloseoutOffice is present ', () => {
const newHistoryRecord = {
...historyRecord,
context: [{ closeout_office_name: 'this is the closeout_office_name' }],
};
const template = getTemplate(newHistoryRecord);
const ren = render(template.getDetails(newHistoryRecord));
ren.debug();
expect(screen.getByText('Closeout office')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,61 @@ import { render, screen } from '@testing-library/react';

import getTemplate from 'constants/MoveHistory/TemplateManager';
import e from 'constants/MoveHistory/EventTemplates/UpdateMTOShipment/updateMTOShipment';
import * as fieldDefault from 'constants/MoveHistory/Database/FieldMappings';
import {
formatCents,
formatCustomerDate,
formatWeight,
formatYesNoMoveHistoryValue,
toDollarString,
} from 'utils/formatters';
import { retrieveTextToDisplay } from 'pages/Office/MoveHistory/LabeledDetails';

const FieldMappings = fieldDefault.default;

describe('when given an mto shipment update with mto shipment table history record', () => {
const changedValues = {
destination_address_type: 'HOME_OF_SELECTION',
requested_delivery_date: '2020-04-14',
requested_pickup_date: '2020-03-23',
actual_pickup_date: '2020-04-15',
approved_date: '2020-04-21',
billable_weight_cap: '10000',
billable_weight_justification: 'Heavy items',
counselor_remarks: 'Remarks',
customer_remarks: 'Words',
diversion: 'false',
first_available_delivery_date: '2020-04-12',
id: 'b1cb1428-6d65-40fc-addd-b57f4ea120f1',
prime_actual_weight: '14000',
prime_estimated_weight: '12000',
sac_type: 'HHG',
scheduled_delivery_date: '2020-04-13',
scheduled_pickup_date: '2020-03-22',
service_order_number: '767567576',
status: 'SUBMITTED',
tac_type: 'NTS',
uses_external_vendor: 'true',

advance_amount_requested: 100,
destination_postal_code: '29102',
estimated_incentive: 2252814,
estimated_weight: 600,
expected_departure_date: '2024-02-18',
has_requested_advance: true,
pro_gear_weight: 243,
sit_estimated_cost: 11627,
sit_estimated_departure_date: '2024-02-29',
sit_estimated_entry_date: '2024-02-18',
sit_estimated_weight: 524,
spouse_pro_gear_weight: 257,
distance: 400,
};
const historyRecord = {
action: 'UPDATE',
eventName: 'updateMTOShipment',
tableName: 'mto_shipments',
changedValues: {
destination_address_type: 'HOME_OF_SELECTION',
requested_delivery_date: '2020-04-14',
requested_pickup_date: '2020-03-23',
actual_pickup_date: '2020-04-15',
approved_date: '2020-04-21',
billable_weight_cap: '10000',
billable_weight_justification: 'Heavy items',
counselor_remarks: 'Remarks',
customer_remarks: 'Words',
diversion: 'false',
first_available_delivery_date: '2020-04-12',
id: 'b1cb1428-6d65-40fc-addd-b57f4ea120f1',
prime_actual_weight: '14000',
prime_estimated_weight: '12000',
sac_type: 'HHG',
scheduled_delivery_date: '2020-04-13',
scheduled_pickup_date: '2020-03-22',
service_order_number: '767567576',
status: 'SUBMITTED',
tac_type: 'NTS',
uses_external_vendor: 'true',
},
changedValues,
context: [
{
shipment_type: 'PPM',
Expand All @@ -44,30 +70,51 @@ describe('when given an mto shipment update with mto shipment table history reco
});
describe('it correctly renders the details component for Create MTO shipments', () => {
it.each([
['Requested delivery date', ': 14 Apr 2020'],
['Status', ': SUBMITTED'],
['Requested pickup date', ': 23 Mar 2020'],
['Destination type', ': Home of selection (HOS)'],
['Departure date', ': 15 Apr 2020'],
['Approved date', ': 21 Apr 2020'],
['Billable weight', ': 10,000 lbs'],
['Billable weight remarks', ': Heavy items'],
['Counselor remarks', ': Remarks'],
['Customer remarks', ': Words'],
['Diversion', ': false'],
['First available delivery date', ': 12 Apr 2020'],
['Shipment weight', ': 14,000 lbs'],
['Prime estimated weight', ': 12,000 lbs'],
['SAC type', ': HHG'],
['Scheduled pickup date', ': 22 Mar 2020'],
['Service order number', ': 767567576'],
['TAC type', ': NTS'],
['Uses external vendor', ': true'],
[FieldMappings.status, changedValues.status],
[FieldMappings.requested_delivery_date, formatCustomerDate(changedValues.requested_delivery_date)],
[FieldMappings.requested_pickup_date, formatCustomerDate(changedValues.requested_pickup_date)],
Object.values(retrieveTextToDisplay('destination_address_type', changedValues.destination_address_type)),
[FieldMappings.actual_pickup_date, formatCustomerDate(changedValues.actual_pickup_date)],
[FieldMappings.approved_date, formatCustomerDate(changedValues.approved_date)],
[FieldMappings.billable_weight_cap, formatWeight(Number(changedValues.billable_weight_cap))],
[FieldMappings.billable_weight_justification, changedValues.billable_weight_justification],
[FieldMappings.counselor_remarks, changedValues.counselor_remarks],
[FieldMappings.customer_remarks, changedValues.customer_remarks],
[FieldMappings.diversion, changedValues.diversion],
[FieldMappings.first_available_delivery_date, formatCustomerDate(changedValues.first_available_delivery_date)],
[FieldMappings.shipment_weight, formatWeight(changedValues.shipment_weight)],
[FieldMappings.prime_estimated_weight, formatWeight(Number(changedValues.prime_estimated_weight))],
[FieldMappings.sac_type, changedValues.sac_type],
[FieldMappings.tac_type, changedValues.tac_type],
[FieldMappings.scheduled_pickup_date, formatCustomerDate(changedValues.scheduled_pickup_date)],
[FieldMappings.service_order_number, `${changedValues.service_order_number}`],
[FieldMappings.uses_external_vendor, changedValues.uses_external_vendor],
Object.values(retrieveTextToDisplay('distance', changedValues.distance)),
[FieldMappings.advance_amount_requested, toDollarString(formatCents(changedValues.advance_amount_requested))],
[FieldMappings.destination_postal_code, changedValues.destination_postal_code],
[FieldMappings.estimated_incentive, toDollarString(formatCents(changedValues.estimated_incentive))],
[FieldMappings.estimated_weight, formatWeight(Number(changedValues.estimated_weight))],
[FieldMappings.expected_departure_date, formatCustomerDate(changedValues.expected_departure_date)],
[FieldMappings.has_requested_advance, formatYesNoMoveHistoryValue(changedValues.has_requested_advance)],
[FieldMappings.pro_gear_weight, formatWeight(Number(changedValues.pro_gear_weight))],
[FieldMappings.sit_estimated_cost, toDollarString(formatCents(changedValues.sit_estimated_cost))],
[FieldMappings.sit_estimated_departure_date, formatCustomerDate(changedValues.sit_estimated_departure_date)],
[FieldMappings.sit_estimated_entry_date, formatCustomerDate(changedValues.sit_estimated_entry_date)],
[FieldMappings.sit_estimated_weight, formatWeight(Number(changedValues.sit_estimated_weight))],
[FieldMappings.spouse_pro_gear_weight, formatWeight(Number(changedValues.spouse_pro_gear_weight))],
])('displays the correct details value for %s', async (label, value) => {
const result = getTemplate(historyRecord);
render(result.getDetails(historyRecord));
expect(screen.getByText(label)).toBeInTheDocument();
expect(screen.getByText(value)).toBeInTheDocument();
const targetItem = Object.fromEntries(
Object.entries(changedValues).filter(([key]) => FieldMappings[key] === label),
);
const history = { ...historyRecord, changedValues: { ...targetItem } };
const result = getTemplate(history);
// eslint-disable-next-line no-unused-vars
const ren = render(result.getDetails(history));
const displayingElements = screen.getAllByText(label);
const displayingElement = displayingElements.find((element) => element.parentElement.textContent.includes(label));
const parent = displayingElement.parentElement;
expect(parent.textContent).toContain(label);
expect(parent.textContent).toContain(value);
});
it('displays the correct label for shipment', () => {
const result = getTemplate(historyRecord);
Expand Down
1 change: 1 addition & 0 deletions src/constants/MoveHistory/EventTemplates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export { default as updateMovingExpense } from './UpdateMovingExpense/UpdateMovi
export { default as updateWeightTicketProGear } from './UpdateWeightTicket/updateWeightTicketProGear';
export { default as createMTOShipmentPPMDetails } from './CreateMTOShipment/createMTOShipmentPPMDetails';
export { default as deleteShipmentPPM } from './DeleteShipment/DeleteShipmentPPM';
export { default as updateCloseoutOffice } from './UpdateCloseoutOffice/updateCloseoutOffice';
export { default as createWeightTicket } from './CreateWeightTicket/CreateWeightTicket';
export { default as updateWeightTicketPPMShipments } from './UpdateWeightTicket/UpdateWeightTicketPPMShipments';
export { default as deleteWeightTicket } from './DeleteWeightTicket/DeleteWeightTicket';
Expand Down
1 change: 1 addition & 0 deletions src/constants/MoveHistory/UIDisplay/Operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export default {
deleteProGearWeightTicket: 'deleteProGearWeightTicket', // internal.yaml
createMovingExpense: 'createMovingExpense', // internal.yaml
deleteMovingExpense: 'deleteMovingExpense', // internal.yaml
updateCloseoutOffice: 'updateCloseoutOffice',
};
11 changes: 8 additions & 3 deletions src/pages/Office/MoveHistory/LabeledDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ import {
toDollarString,
} from 'utils/formatters';

const retrieveTextToDisplay = (fieldName, value) => {
export const retrieveTextToDisplay = (fieldName, value) => {
const emptyValue = '—';
const displayName = fieldMappings[fieldName];
let displayValue = value;

if (displayName === fieldMappings.storage_in_transit) {
displayValue = `${displayValue} days`;
const fieldNameMap = {
[fieldMappings.distance]: (name, someValue) => `${someValue} mi`,
[fieldMappings.storage_in_transit]: (name, someValue) => `${someValue} days`,
};

if (fieldNameMap[displayName]) {
displayValue = fieldNameMap[displayName]?.call(null, displayName, value);
} else if (weightFields[fieldName]) {
// turn string value into number so it can be formatted correctly
displayValue = formatWeight(Number(displayValue));
Expand Down