Skip to content

Commit

Permalink
Merge branch 'main' into B-20532-MAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstonebraker authored Oct 28, 2024
2 parents 47d8173 + af403d2 commit f64a721
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 17 deletions.
6 changes: 4 additions & 2 deletions pkg/assets/sql_scripts/move_history_fetcher.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ WITH move AS (
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))
(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))
))
)::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) on TRUE
JOIN jsonb_to_record(audit_history.changed_data) as c(closeout_office_id TEXT, counseling_transportation_office_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
1 change: 1 addition & 0 deletions src/constants/MoveHistory/Database/FieldMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@ export default {
dest_sit_auth_end_date: 'Destination SIT authorized date',
approvals_requested_at: 'Approvals requested at',
approved_at: 'Approved at',
counseling_office_name: 'Counseling office',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';

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

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

if (historyRecord.context) {
newChangedValues = {
...newChangedValues,
...historyRecord.context[0],
};
}

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

export default {
action: a.INSERT,
eventName: o.createOrder,
tableName: t.orders,
getEventNameDisplay: () => 'Created orders',
getDetails: (historyRecord) => {
return <LabeledDetails historyRecord={formatChangedValues(historyRecord)} />;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { render, screen } from '@testing-library/react';

import getTemplate from 'constants/MoveHistory/TemplateManager';
import e from 'constants/MoveHistory/EventTemplates/CreateOrder/createOrder';

describe('When given a create order event for the orders table from the office side', () => {
const item = {
action: 'INSERT',
eventName: 'createOrder',
tableName: 'orders',
eventNameDisplay: 'Created orders',
changedValues: {
status: 'DRAFT',
report_by_date: '2022-10-18',
issue_date: '2022-10-11',
orders_type: 'PERMANENT_CHANGE_OF_STATION',
origin_duty_location_name: 'Los Angeles AFB',
new_duty_location_name: 'Fairchild AFB',
has_dependents: true,
grade: 'E_1',
},
context: [
{
new_duty_location_name: 'Fairchild AFB',
origin_duty_location_name: 'Los Angeles AFB',
},
],
};
it('correctly matches to the proper template', () => {
const result = getTemplate(item);
expect(result).toMatchObject(e);
});
describe('When given a specific set of details for created orders', () => {
it.each([
['Status', ': DRAFT'],
['Report by date', ': 18 Oct 2022'],
['Orders date', ': 11 Oct 2022'],
['Orders type', ': Permanent Change Of Station (PCS)'],
['Origin duty location name', ': Los Angeles AFB'],
['New duty location name', ': Fairchild AFB'],
['Dependents included', ': Yes'],
['Pay grade', ': E-1'],
])('displays the proper details value for %s', async (label, value) => {
const result = getTemplate(item);
render(result.getDetails(item));
expect(screen.getByText(label)).toBeInTheDocument();
expect(screen.getByText(value)).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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 a from 'constants/MoveHistory/Database/Actions';
import o from 'constants/MoveHistory/UIDisplay/Operations';
import LabeledDetails from 'pages/Office/MoveHistory/LabeledDetails';

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

import getTemplate from 'constants/MoveHistory/TemplateManager';
import e from 'constants/MoveHistory/EventTemplates/CreateOrder/createOrderCreateEntitlements';

describe('When given a created order event for the entitlements table from the office side', () => {
const item = {
action: 'INSERT',
eventName: 'createOrder',
tableName: 'entitlements',
eventNameDisplay: 'Created allowances',
changedValues: {
authorized_weight: 8000,
dependents_authorized: true,
storage_in_transit: 90,
},
};
it('correctly matches the created orders template', () => {
const result = getTemplate(item);
expect(result).toMatchObject(e);
});
describe('When given a specific set of details', () => {
it.each([
['Authorized weight', ': 8,000 lbs'],
['Storage in transit (SIT)', ': 90 days'],
['Dependents', ': Yes'],
])('displays the proper details value for %s', async (label, value) => {
const result = getTemplate(item);
render(result.getDetails(item));
expect(screen.getByText(label)).toBeInTheDocument();
expect(screen.getByText(value)).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';

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

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

if (historyRecord.context) {
newChangedValues = {
...newChangedValues,
...historyRecord.context[0],
};
}

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

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

import getTemplate from 'constants/MoveHistory/TemplateManager';
import e from 'constants/MoveHistory/EventTemplates/CreateOrder/createOrderCreateMoves';

describe('When given a create order event for the moves table from the office side', () => {
const item = {
action: 'INSERT',
eventName: 'createOrder',
tableName: 'moves',
eventNameDisplay: 'Created move',
changedValues: {
status: 'DRAFT',
},
context: [
{
counseling_office_name: 'Scott AFB',
},
],
};
it('correctly matches to the proper template', () => {
const result = getTemplate(item);
expect(result).toMatchObject(e);
});
describe('When given a specific set of details for created move', () => {
it.each([
['Status', ': DRAFT'],
['Counseling office', ': Scott AFB'],
])('displays the proper details value for %s', async (label, value) => {
const result = getTemplate(item);
render(result.getDetails(item));
expect(screen.getByText(label)).toBeInTheDocument();
expect(screen.getByText(value)).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React from 'react';

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

export default {
action: a.INSERT,
eventName: '*', // Needs wild card to handle both createOrders and createOrder
eventName: o.createOrders,
tableName: t.entitlements,
getEventNameDisplay: () => 'Created allowances',
getDetails: (historyRecord) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@ import React from 'react';

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

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

if (historyRecord.context) {
newChangedValues = {
...newChangedValues,
...historyRecord.context[0],
};
}

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

export default {
action: a.INSERT,
eventName: '*', // Needs wild card to handle both createOrders and createOrder
eventName: o.createOrders,
tableName: t.moves,
getEventNameDisplay: () => 'Created move',
getDetails: (historyRecord) => {
return <LabeledDetails historyRecord={historyRecord} />;
return <LabeledDetails historyRecord={formatChangedValues(historyRecord)} />;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ describe('When given a created orders event for the moves table', () => {
changedValues: {
status: 'DRAFT',
},
context: [
{
counseling_office_name: 'Scott AFB',
},
],
};
it('correctly matches to the proper template', () => {
const result = getTemplate(item);
expect(result).toMatchObject(e);
});
describe('When given a specific set of details for created moves', () => {
it.each([['Status', ': DRAFT']])('displays the proper details value for %s', async (label, value) => {
it.each([
['Status', ': DRAFT'],
['Counseling office', ': Scott AFB'],
])('displays the proper details value for %s', async (label, value) => {
const result = getTemplate(item);
render(result.getDetails(item));
expect(screen.getByText(label)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

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

const formatChangedValues = (historyRecord) => {
Expand All @@ -21,7 +22,7 @@ const formatChangedValues = (historyRecord) => {

export default {
action: a.INSERT,
eventName: '*', // Needs wild card to handle both createOrders and createOrder
eventName: o.createOrders,
tableName: t.orders,
getEventNameDisplay: () => 'Created orders',
getDetails: (historyRecord) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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';

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

if (newChangedValues.counseling_transportation_office_id === null) {
newChangedValues.counseling_office_name = ' - ';
}
if (historyRecord.context) {
newChangedValues = {
...newChangedValues,
...historyRecord.context[0],
};
}

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

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

import getTemplate from 'constants/MoveHistory/TemplateManager';
import e from 'constants/MoveHistory/EventTemplates/UpdateOrders/updateOrderUpdateMove';
import e from 'constants/MoveHistory/EventTemplates/UpdateOrder/updateOrderUpdateMove';

describe('when given an mto shipment update with service item status history record', () => {
describe('when given an mto shipment update for the moves table from the office side', () => {
const historyRecord = {
action: 'UPDATE',
changedValues: { status: 'APPROVED' },
Expand Down
Loading

0 comments on commit f64a721

Please sign in to comment.