Skip to content

Commit

Permalink
Merge pull request #13957 from transcom/B-20473-INT
Browse files Browse the repository at this point in the history
B 20473 int
  • Loading branch information
pambecker authored Oct 24, 2024
2 parents 0a6628f + 53b02e3 commit 768bc97
Show file tree
Hide file tree
Showing 37 changed files with 451 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2721,4 +2721,4 @@ experimental:
notify:
branches:
only:
- main
- main
24 changes: 16 additions & 8 deletions pkg/gen/ghcapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/gen/ghcapi/ghcoperations/move/search_moves.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/gen/ghcmessages/p_p_m_status.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/handlers/authentication/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var TOO = RolePermissions{
"update.closeoutOffice",
"update.MTOPage",
"create.TXOShipment",
"update.cancelMoveFlag",
},
}

Expand Down Expand Up @@ -86,6 +87,7 @@ var ServicesCounselor = RolePermissions{
"update.customer",
"update.closeoutOffice",
"view.closeoutOffice",
"update.cancelMoveFlag",
},
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/services/move/move_canceler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (f *moveCanceler) CancelMove(appCtx appcontext.AppContext, moveID uuid.UUID

if shipment.PPMShipment != nil {
if shipment.PPMShipment.Status == models.PPMShipmentStatusCloseoutComplete {
return apperror.NewConflictError(move.ID, " cannot cancel move with approved shipment.")
return apperror.NewConflictError(move.ID, " cannot cancel move with a closeout complete shipment.")
}
var ppmshipment models.PPMShipment
qerr := appCtx.DB().Where("id = ?", shipment.PPMShipment.ID).First(&ppmshipment)
Expand All @@ -55,9 +55,7 @@ func (f *moveCanceler) CancelMove(appCtx appcontext.AppContext, moveID uuid.UUID
} else if err != nil {
return apperror.NewQueryError("PPM Shipment", err, "Failed to update status for ppm shipment")
}
}

if shipment.Status != models.MTOShipmentStatusApproved {
} else if shipment.Status != models.MTOShipmentStatusApproved {
verrs, err := txnAppCtx.DB().ValidateAndUpdate(&shipmentDelta)
if verrs != nil && verrs.HasAny() {
return apperror.NewInvalidInputError(shipment.ID, err, verrs, "Validation errors found while setting shipment status")
Expand Down
19 changes: 19 additions & 0 deletions pkg/services/move/move_canceler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@ func (suite *MoveServiceSuite) TestMoveCanceler() {
_, err := moveCanceler.CancelMove(suite.AppContextForTest(), move.ID)
suite.Error(err)
})

suite.Run("fails to cancel move with close complete ppm shipment", func() {
move := factory.BuildMove(suite.DB(), nil, nil)

factory.BuildPPMShipment(suite.DB(), []factory.Customization{
{
Model: move,
LinkOnly: true,
},
{
Model: models.PPMShipment{
Status: models.PPMShipmentStatusCloseoutComplete,
},
},
}, nil)

_, err := moveCanceler.CancelMove(suite.AppContextForTest(), move.ID)
suite.Error(err)
})
}
70 changes: 0 additions & 70 deletions pkg/services/mto_shipment/mto_shipment_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,76 +251,6 @@ func (suite *MTOShipmentServiceSuite) TestCreateMTOShipment() {
suite.Equal("failed to create pickup address - the country GB is not supported at this time - only US is allowed", err.Error())
})

suite.Run("If the shipment has an international address it should be returned", func() {
subtestData := suite.createSubtestData(nil)
creator := subtestData.shipmentCreator

internationalAddress := factory.BuildAddress(nil, []factory.Customization{
{
Model: models.Country{
Country: "GB",
CountryName: "UNITED KINGDOM",
},
},
}, nil)
// stubbed countries need an ID
internationalAddress.ID = uuid.Must(uuid.NewV4())

mtoShipment := factory.BuildMTOShipment(nil, []factory.Customization{
{
Model: subtestData.move,
LinkOnly: true,
},
{
Model: internationalAddress,
LinkOnly: true,
},
}, nil)

mtoShipmentClear := clearShipmentIDFields(&mtoShipment)
mtoShipmentClear.MTOServiceItems = models.MTOServiceItems{}

_, err := creator.CreateMTOShipment(suite.AppContextForTest(), mtoShipmentClear)

suite.Error(err)
suite.Equal("failed to create pickup address - the country GB is not supported at this time - only US is allowed", err.Error())
})

suite.Run("If the shipment has an international address it should be returned", func() {
subtestData := suite.createSubtestData(nil)
creator := subtestData.shipmentCreator

internationalAddress := factory.BuildAddress(nil, []factory.Customization{
{
Model: models.Country{
Country: "GB",
CountryName: "UNITED KINGDOM",
},
},
}, nil)
// stubbed countries need an ID
internationalAddress.ID = uuid.Must(uuid.NewV4())

mtoShipment := factory.BuildMTOShipment(nil, []factory.Customization{
{
Model: subtestData.move,
LinkOnly: true,
},
{
Model: internationalAddress,
LinkOnly: true,
},
}, nil)

mtoShipmentClear := clearShipmentIDFields(&mtoShipment)
mtoShipmentClear.MTOServiceItems = models.MTOServiceItems{}

_, err := creator.CreateMTOShipment(suite.AppContextForTest(), mtoShipmentClear)

suite.Error(err)
suite.Equal("failed to create pickup address - the country GB is not supported at this time - only US is allowed", err.Error())
})

suite.Run("If the shipment is created successfully it should return ShipmentLocator", func() {
subtestData := suite.createSubtestData(nil)
creator := subtestData.shipmentCreator
Expand Down
45 changes: 45 additions & 0 deletions src/components/ConfirmationModals/CancelMoveConfirmationModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button } from '@trussworks/react-uswds';

import Modal, { ModalTitle, ModalClose, ModalActions, connectModal } from 'components/Modal/Modal';

export const CancelMoveConfirmationModal = ({ onClose, onSubmit, moveID, title, content, submitText, closeText }) => (
<Modal>
<ModalClose handleClick={() => onClose()} />
<ModalTitle>
<h3>{title}</h3>
</ModalTitle>
<p>{content}</p>
<ModalActions autofocus="true">
<Button data-focus="true" className="usa-button--destructive" type="submit" onClick={() => onSubmit(moveID)}>
{submitText}
</Button>
<Button className="usa-button--secondary" type="button" onClick={() => onClose()} data-testid="modalBackButton">
{closeText}
</Button>
</ModalActions>
</Modal>
);

CancelMoveConfirmationModal.propTypes = {
onClose: PropTypes.func.isRequired,
onSubmit: PropTypes.func.isRequired,

title: PropTypes.string,
content: PropTypes.string,
submitText: PropTypes.string,
closeText: PropTypes.string,
};

CancelMoveConfirmationModal.defaultProps = {
title: 'Are you sure?',
content:
'You’ll lose all the information in this move. If you want it back later, you’ll have to request a new move.',
submitText: 'Cancel move',
closeText: 'Keep move',
};

CancelMoveConfirmationModal.displayName = 'CancelMoveConfirmationModal';

export default connectModal(CancelMoveConfirmationModal);
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';

import CancelMoveConfirmationModal from './CancelMoveConfirmationModal';

export default {
title: 'Components/CancelMoveConfirmationModal',
component: CancelMoveConfirmationModal,
args: {
moveID: '111',
},
argTypes: {
onClose: { action: 'close button clicked' },
onSubmit: { action: 'submit button clicked' },
},
};

const Template = (args) => <CancelMoveConfirmationModal {...args} />;

export const Basic = Template.bind({});

export const WithOverrides = Template.bind({});
WithOverrides.args = {
title: 'This is a sample title',
content: 'Some sample description',
submitText: 'YES!',
closeText: 'NO',
};

const ConnectedTemplate = (args) => <CancelMoveConfirmationModal {...args} />;
export const ConnectedModal = ConnectedTemplate.bind({});
ConnectedModal.args = {
isOpen: true,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { CancelMoveConfirmationModal } from 'components/ConfirmationModals/CancelMoveConfirmationModal';

let onClose;
let onSubmit;
beforeEach(() => {
onClose = jest.fn();
onSubmit = jest.fn();
});

describe('CancelMoveConfirmationModal', () => {
const moveID = '123456';

it('renders the component', async () => {
render(<CancelMoveConfirmationModal onSubmit={onSubmit} onClose={onClose} moveID={moveID} />);

expect(await screen.findByRole('heading', { level: 3, name: 'Are you sure?' })).toBeInTheDocument();
});

it('closes the modal when close icon is clicked', async () => {
render(<CancelMoveConfirmationModal onSubmit={onSubmit} onClose={onClose} shipmentID={moveID} />);

const closeButton = await screen.findByTestId('modalCloseButton');

await userEvent.click(closeButton);

expect(onClose).toHaveBeenCalledTimes(1);
});

it('closes the modal when the keep button is clicked', async () => {
render(<CancelMoveConfirmationModal onSubmit={onSubmit} onClose={onClose} moveID={moveID} />);

const keepButton = await screen.findByRole('button', { name: 'Keep move' });

await userEvent.click(keepButton);

expect(onClose).toHaveBeenCalledTimes(1);
});

it('calls the submit function when cancel button is clicked', async () => {
render(<CancelMoveConfirmationModal onSubmit={onSubmit} onClose={onClose} moveID={moveID} />);

const cancelButton = await screen.findByRole('button', { name: 'Cancel move' });

await userEvent.click(cancelButton);

expect(onSubmit).toHaveBeenCalledWith(moveID);
expect(onSubmit).toHaveBeenCalledTimes(1);
});
});
Loading

0 comments on commit 768bc97

Please sign in to comment.