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-20536 add queue management tracking to move history #14535

Merged
merged 12 commits into from
Feb 6, 2025
8 changes: 6 additions & 2 deletions pkg/assets/sql_scripts/move_history_fetcher.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ WITH move AS (
'closeout_office_name',
(SELECT transportation_offices.name FROM transportation_offices WHERE transportation_offices.id = uuid(c.closeout_office_id)),
'counseling_office_name',
(SELECT transportation_offices.name FROM transportation_offices WHERE transportation_offices.id = uuid(c.counseling_transportation_office_id))
(SELECT transportation_offices.name FROM transportation_offices WHERE transportation_offices.id = uuid(c.counseling_transportation_office_id)),
'assigned_office_user_first_name',
(SELECT office_users.first_name FROM office_users WHERE office_users.id IN (uuid(c.sc_assigned_id), uuid(c.too_assigned_id), uuid(c.tio_assigned_id))),
'assigned_office_user_last_name',
(SELECT office_users.last_name FROM office_users WHERE office_users.id IN (uuid(c.sc_assigned_id), uuid(c.too_assigned_id), uuid(c.tio_assigned_id)))
))
)::TEXT AS context,
NULL AS context_id
FROM
audit_history
JOIN move ON audit_history.object_id = move.id
JOIN jsonb_to_record(audit_history.changed_data) as c(closeout_office_id TEXT, counseling_transportation_office_id TEXT) on TRUE
JOIN jsonb_to_record(audit_history.changed_data) as c(closeout_office_id TEXT, counseling_transportation_office_id TEXT, sc_assigned_id TEXT, too_assigned_id TEXT, tio_assigned_id TEXT) ON TRUE
WHERE audit_history.table_name = 'moves'
-- Remove log for when shipment_seq_num updates
AND NOT (audit_history.event_name = NULL AND audit_history.changed_data::TEXT LIKE '%shipment_seq_num%' AND LENGTH(audit_history.changed_data::TEXT) < 25)
Expand Down
6 changes: 6 additions & 0 deletions src/constants/MoveHistory/Database/FieldMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,11 @@ export default {
approvals_requested_at: 'Approvals requested at',
approved_at: 'Approved at',
counseling_office_name: 'Counseling office',
assigned_sc: 'Counselor assigned',
assigned_too: 'Task ordering officer assigned',
assigned_tio: 'Task invoicing officer assigned',
re_assigned_sc: 'Counselor reassigned',
re_assigned_too: 'Task ordering officer reassigned',
re_assigned_tio: 'Task invoicing officer reassigned',
available_to_prime_at: 'Available to Prime at',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import o from 'constants/MoveHistory/UIDisplay/Operations';
import a from 'constants/MoveHistory/Database/Actions';
import t from 'constants/MoveHistory/Database/Tables';

export default {
action: a.UPDATE,
eventName: o.finishDocumentReview,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: ({ changedValues }) => (
<>
<div>PPM Closeout Complete</div>
{changedValues?.sc_assigned_id !== undefined ? <div>Closeout Counselor Unassigned</div> : null}
</>
),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { screen, render } from '@testing-library/react';

import e from 'constants/MoveHistory/EventTemplates/FinishDocumentReview/FinishDocumentReviewMoves';
import getTemplate from 'constants/MoveHistory/TemplateManager';

describe('When given a completed services counseling for a move', () => {
const historyRecord = {
action: 'UPDATE',
eventName: 'finishDocumentReview',
tableName: 'moves',
};
it('correctly matches the update mto status services counseling completed event to the proper template', () => {
const template = getTemplate(historyRecord);
expect(template).toMatchObject(e);
});

it('displays the proper name in the event name display column', () => {
const template = getTemplate(historyRecord);

render(template.getEventNameDisplay(historyRecord));
expect(screen.getByText('Updated move')).toBeInTheDocument();
});

it('displays default when SC ID is not present', () => {
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('PPM Closeout Complete')).toBeInTheDocument();
expect(screen.queryByText('Closeout Counselor Unassigned')).not.toBeInTheDocument();
});

it('displays correct details when a SC is unassigned', () => {
historyRecord.changedValues = {
...historyRecord.changedValues,
sc_assigned_id: null,
};
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('PPM Closeout Complete')).toBeInTheDocument();
expect(screen.getByText('Closeout Counselor Unassigned')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import o from 'constants/MoveHistory/UIDisplay/Operations';
import a from 'constants/MoveHistory/Database/Actions';
import t from 'constants/MoveHistory/Database/Tables';

export default {
action: a.UPDATE,
eventName: o.deleteAssignedOfficeUser,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: ({ changedValues }) => {
if (changedValues.sc_assigned_id === null) return <>Counselor unassigned</>;
if (changedValues.too_assigned_id === null) return <>Task ordering officer unassigned</>;
if (changedValues.tio_assigned_id === null) return <>Task invoicing officer unassigned</>;
return <>Unassigned</>;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { screen, render } from '@testing-library/react';

import e from 'constants/MoveHistory/EventTemplates/UpdateAssignedOfficeUser/DeleteAssignedOfficeUser';
import getTemplate from 'constants/MoveHistory/TemplateManager';

describe('When given a move that has been unassigned', () => {
const historyRecord = {
action: 'UPDATE',
eventName: 'deleteAssignedOfficeUser',
tableName: 'moves',
changedValues: {
sc_assigned_id: null,
},
};

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

it('displays the proper name in the event name display column', () => {
const template = getTemplate(historyRecord);

render(template.getEventNameDisplay(historyRecord));
expect(screen.getByText('Updated move')).toBeInTheDocument();
});

describe('displays the proper details for', () => {
it('services counselor', () => {
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Counselor unassigned')).toBeInTheDocument();
});
it('task ordering officer', () => {
historyRecord.changedValues = { too_assigned_id: null };
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Task ordering officer unassigned')).toBeInTheDocument();
});
it('task invoicing officer', () => {
historyRecord.changedValues = { tio_assigned_id: null };
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Task invoicing officer unassigned')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

import o from 'constants/MoveHistory/UIDisplay/Operations';
import a from 'constants/MoveHistory/Database/Actions';
import t from 'constants/MoveHistory/Database/Tables';
import LabeledDetails from 'pages/Office/MoveHistory/LabeledDetails';
import { formatAssignedOfficeUserFromContext } from 'utils/formatters';

const formatChangedValues = (historyRecord) => {
const newChangedValues = {
...formatAssignedOfficeUserFromContext(historyRecord),
};

return { ...historyRecord, changedValues: newChangedValues };
};

export default {
action: a.UPDATE,
eventName: o.updateAssignedOfficeUser,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: (historyRecord) => <LabeledDetails historyRecord={formatChangedValues(historyRecord)} />,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { screen, render } from '@testing-library/react';

import e from 'constants/MoveHistory/EventTemplates/UpdateAssignedOfficeUser/UpdateAssignedOfficeUser';
import getTemplate from 'constants/MoveHistory/TemplateManager';

describe('When given a move that has been assigned', () => {
const historyRecord = {
action: 'UPDATE',
eventName: 'updateAssignedOfficeUser',
tableName: 'moves',
changedValues: {
sc_assigned_id: 'fb625e3c-067c-49d7-8fd9-88ef040e6137',
},
oldValues: {
sc_assigned_id: null,
},
context: [{ assigned_office_user_last_name: 'Daniels', assigned_office_user_first_name: 'Jayden' }],
};

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

it('displays the proper name in the event name display column', () => {
const template = getTemplate(historyRecord);

render(template.getEventNameDisplay(historyRecord));
expect(screen.getByText('Updated move')).toBeInTheDocument();
});

describe('displays the proper details for', () => {
it('services counselor', () => {
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Counselor assigned')).toBeInTheDocument();
expect(screen.getByText(': Daniels, Jayden')).toBeInTheDocument();
});
it('task ordering officer', () => {
historyRecord.changedValues = { too_assigned_id: 'fb625e3c-067c-49d7-8fd9-88ef040e6137' };
historyRecord.oldValues = { too_assigned_id: null };
historyRecord.context = [
{ assigned_office_user_last_name: 'Robinson', assigned_office_user_first_name: 'Brian' },
];

const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Task ordering officer assigned')).toBeInTheDocument();
expect(screen.getByText(': Robinson, Brian')).toBeInTheDocument();
});
it('task invoicing officer', () => {
historyRecord.changedValues = { tio_assigned_id: 'fb625e3c-067c-49d7-8fd9-88ef040e6137' };
historyRecord.oldValues = { tio_assigned_id: null };
historyRecord.context = [{ assigned_office_user_last_name: 'Luvu', assigned_office_user_first_name: 'Frankie' }];

const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Task invoicing officer assigned')).toBeInTheDocument();
expect(screen.getByText(': Luvu, Frankie')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ export default {
eventName: o.updateMTOStatusServiceCounselingCompleted,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: () => <> Counseling Completed </>,
getDetails: ({ changedValues }) => {
return (
<>
<div> Counseling Completed </div>
{changedValues?.sc_assigned_id !== undefined ? <div> Counselor Unassigned </div> : null}
</>
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ describe('When given a completed services counseling for a move', () => {
render(template.getEventNameDisplay(historyRecord));
expect(screen.getByText('Updated move')).toBeInTheDocument();
});
it('displays correct details when an SC is unassigned', () => {
historyRecord.changedValues = {
...historyRecord.changedValues,
sc_assigned_id: null,
};
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Counseling Completed')).toBeInTheDocument();
expect(screen.getByText('Counselor Unassigned')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ export default {
eventName: o.updateMoveTaskOrderStatus,
tableName: t.moves,
getEventNameDisplay: () => 'Approved move',
getDetails: () => <> Created Move Task Order (MTO) </>,
getDetails: ({ changedValues }) => {
return (
<>
<div> Created Move Task Order (MTO) </div>
{changedValues?.too_assigned_id !== undefined ? <div> Task Ordering Officer Unassigned </div> : null}
</>
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ describe('when given a Move approved history record', () => {
expect(screen.getByText('Approved move'));
expect(screen.getByText('Created Move Task Order (MTO)'));
});

it('displays correct details when a TOO is unassigned', () => {
historyRecord.changedValues = {
...historyRecord.changedValues,
too_assigned_id: null,
};

const template = getTemplate(historyRecord);
render(template.getDetails(historyRecord));
expect(screen.getByText('Created Move Task Order (MTO)'));
expect(screen.getByText('Task Ordering Officer Unassigned'));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import o from 'constants/MoveHistory/UIDisplay/Operations';
import a from 'constants/MoveHistory/Database/Actions';
import t from 'constants/MoveHistory/Database/Tables';

export default {
action: a.UPDATE,
eventName: o.updatePaymentRequestStatus,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: ({ changedValues }) => (
<>
<div>Payment Requests Addressed</div>
{changedValues?.tio_assigned_id !== undefined ? <div>Task Invoicing Officer Unassigned</div> : null}
</>
),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { screen, render } from '@testing-library/react';

import e from 'constants/MoveHistory/EventTemplates/UpdatePaymentRequestStatus/UpdatePaymentRequestStatusMoves';
import getTemplate from 'constants/MoveHistory/TemplateManager';

describe('When given a completed services counseling for a move', () => {
const historyRecord = {
action: 'UPDATE',
eventName: 'updatePaymentRequestStatus',
tableName: 'moves',
};
it('correctly matches the update mto status services counseling completed event to the proper template', () => {
const template = getTemplate(historyRecord);
expect(template).toMatchObject(e);
});

it('displays the proper name in the event name display column', () => {
const template = getTemplate(historyRecord);

render(template.getEventNameDisplay(historyRecord));
expect(screen.getByText('Updated move')).toBeInTheDocument();
});

it('displays default when TIO ID is not present', () => {
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Payment Requests Addressed')).toBeInTheDocument();
});

it('displays correct details when a TIO is unassigned', () => {
historyRecord.changedValues = {
...historyRecord.changedValues,
tio_assigned_id: null,
};
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Payment Requests Addressed')).toBeInTheDocument();
expect(screen.getByText('Task Invoicing Officer Unassigned')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,17 @@ export default {
eventName: o.updateMTOServiceItemStatus,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: (historyRecord) => <LabeledDetails historyRecord={historyRecord} />,
getDetails: (historyRecord) => {
return (
<>
<LabeledDetails historyRecord={historyRecord} />
{historyRecord?.changedValues?.too_assigned_id !== undefined ? (
<>
<div>Service Items Addressed</div>
<div>Task Ordering Officer Unassigned</div>
</>
) : null}
</>
);
},
};
Loading
Loading