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

(fix) O3-4260 fix error when starting a visit immediately after ending one #2147

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import styles from './end-visit-dialog.scss';
interface EndVisitDialogProps {
patientUuid: string;
closeModal: () => void;

// for test mock only
stopDatetime?: Date;
}

const EndVisitDialog: React.FC<EndVisitDialogProps> = ({ patientUuid, closeModal }) => {
const EndVisitDialog: React.FC<EndVisitDialogProps> = ({ patientUuid, closeModal, stopDatetime = new Date() }) => {
const { t } = useTranslation();
const { currentVisit, currentVisitIsRetrospective, mutate } = useVisit(patientUuid);
const { queueEntry } = useVisitQueueEntry(patientUuid, currentVisit?.uuid);
Expand All @@ -21,9 +24,9 @@ const EndVisitDialog: React.FC<EndVisitDialogProps> = ({ patientUuid, closeModal
setCurrentVisit(null, null);
closeModal();
} else {
const endVisitPayload = {
stopDatetime: new Date(),
};
const stopDatetimeTruncated = new Date(stopDatetime);
stopDatetimeTruncated.setSeconds(0, 0);
const endVisitPayload = { stopDatetime: stopDatetimeTruncated };

const abortController = new AbortController();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { showSnackbar, updateVisit, useVisit, type Visit, type FetchResponse } f
import { mockCurrentVisit } from '__mocks__';
import EndVisitDialog from './end-visit-dialog.component';

const endVisitPayload = {
stopDatetime: expect.any(Date),
};

const mockCloseModal = jest.fn();
const mockMutate = jest.fn();
const mockShowSnackbar = jest.mocked(showSnackbar);
Expand All @@ -30,7 +26,8 @@ describe('End visit dialog', () => {

test('displays a success snackbar when the visit is ended successfully', async () => {
const user = userEvent.setup();

const mockCurrentTime = new Date('2024-12-11T01:20:25.1234');
const mockCurrentTimeTruncated = new Date('2024-12-11T01:20:00');
mockUpdateVisit.mockResolvedValue({
status: 200,
data: {
Expand All @@ -40,7 +37,13 @@ describe('End visit dialog', () => {
},
} as unknown as FetchResponse<Visit>);

render(<EndVisitDialog patientUuid="some-patient-uuid" closeModal={mockCloseModal} />);
const expectedEndVisitPayload = {
stopDatetime: mockCurrentTimeTruncated,
};

render(
<EndVisitDialog patientUuid="some-patient-uuid" closeModal={mockCloseModal} stopDatetime={mockCurrentTime} />,
);

const closeModalButton = screen.getByRole('button', { name: /close/i });
const cancelButton = screen.getByRole('button', { name: /cancel/i });
Expand All @@ -60,7 +63,7 @@ describe('End visit dialog', () => {

await user.click(endVisitButton);

expect(updateVisit).toHaveBeenCalledWith(mockCurrentVisit.uuid, endVisitPayload, expect.anything());
expect(updateVisit).toHaveBeenCalledWith(mockCurrentVisit.uuid, expectedEndVisitPayload, expect.anything());

expect(mockShowSnackbar).toHaveBeenCalledWith({
isLowContrast: true,
Expand All @@ -81,6 +84,10 @@ describe('End visit dialog', () => {
},
};

const expectedEndVisitPayload = {
stopDatetime: expect.any(Date),
};

mockUpdateVisit.mockRejectedValue(error);

render(<EndVisitDialog patientUuid="some-patient-uuid" closeModal={mockCloseModal} />);
Expand All @@ -96,7 +103,7 @@ describe('End visit dialog', () => {

await user.click(endVisitButton);

expect(updateVisit).toHaveBeenCalledWith(mockCurrentVisit.uuid, endVisitPayload, new AbortController());
expect(updateVisit).toHaveBeenCalledWith(mockCurrentVisit.uuid, expectedEndVisitPayload, new AbortController());
expect(mockShowSnackbar).toHaveBeenCalledWith({
subtitle: 'Internal error message',
kind: 'error',
Expand Down
Loading