Skip to content

Commit

Permalink
Change api call and response
Browse files Browse the repository at this point in the history
  • Loading branch information
wullaski committed Jan 17, 2025
1 parent f3bc3a9 commit 81eab4c
Show file tree
Hide file tree
Showing 18 changed files with 548 additions and 270 deletions.
30 changes: 19 additions & 11 deletions src/applications/vaos/referral-appointments/ChooseDateAndTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { useLocation } from 'react-router-dom';
import ReferralLayout from './components/ReferralLayout';
// eslint-disable-next-line import/no-restricted-paths
import { getUpcomingAppointmentListInfo } from '../appointment-list/redux/selectors';
import { setFormCurrentPage, fetchProviderDetails } from './redux/actions';
import {
setFormCurrentPage,
createDraftReferralAppointment,
} from './redux/actions';
// eslint-disable-next-line import/no-restricted-paths
import { fetchFutureAppointments } from '../appointment-list/redux/actions';
import { getProviderInfo } from './redux/selectors';
import { getDraftAppointmentInfo } from './redux/selectors';
import { FETCH_STATUS } from '../utils/constants';
import { scrollAndFocus } from '../utils/scrollAndFocus';
import DateAndTimeContent from './components/DateAndTimeContent';
Expand All @@ -18,8 +21,8 @@ export const ChooseDateAndTime = props => {
const dispatch = useDispatch();
const location = useLocation();

const { provider, providerFetchStatus } = useSelector(
state => getProviderInfo(state),
const { draftAppointmentInfo, draftAppointmentCreateStatus } = useSelector(
state => getDraftAppointmentInfo(state),
shallowEqual,
);
const { futureStatus, appointmentsByMonth } = useSelector(
Expand All @@ -32,31 +35,36 @@ export const ChooseDateAndTime = props => {
useEffect(
() => {
if (
providerFetchStatus === FETCH_STATUS.notStarted ||
draftAppointmentCreateStatus === FETCH_STATUS.notStarted ||
futureStatus === FETCH_STATUS.notStarted
) {
if (providerFetchStatus === FETCH_STATUS.notStarted) {
dispatch(fetchProviderDetails(currentReferral.providerId));
if (draftAppointmentCreateStatus === FETCH_STATUS.notStarted) {
dispatch(createDraftReferralAppointment(currentReferral.providerId));
}
if (futureStatus === FETCH_STATUS.notStarted) {
dispatch(fetchFutureAppointments({ includeRequests: false }));
}
} else if (
providerFetchStatus === FETCH_STATUS.succeeded &&
draftAppointmentCreateStatus === FETCH_STATUS.succeeded &&
futureStatus === FETCH_STATUS.succeeded
) {
setLoading(false);
scrollAndFocus('h1');
} else if (
providerFetchStatus === FETCH_STATUS.failed ||
draftAppointmentCreateStatus === FETCH_STATUS.failed ||
futureStatus === FETCH_STATUS.failed
) {
setLoading(false);
setFailed(true);
scrollAndFocus('h1');
}
},
[currentReferral.providerId, dispatch, providerFetchStatus, futureStatus],
[
currentReferral.providerId,
dispatch,
draftAppointmentCreateStatus,
futureStatus,
],
);
useEffect(
() => {
Expand All @@ -80,7 +88,7 @@ export const ChooseDateAndTime = props => {
heading="Schedule an appointment with your provider"
>
<DateAndTimeContent
provider={provider}
draftAppointmentInfo={draftAppointmentInfo}
currentReferral={currentReferral}
appointmentsByMonth={appointmentsByMonth}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from '../tests/mocks/setup';
import ChooseDateAndTime from './ChooseDateAndTime';
import { createReferral } from './utils/referrals';
import { createProviderDetails } from './utils/provider';
import { createDraftAppointmentInfo } from './utils/provider';
import confirmedV2 from '../services/mocks/v2/confirmed.json';
import * as getProviderByIdModule from '../services/referral';
import * as postDraftReferralAppointmentModule from '../services/referral';
import * as fetchAppointmentsModule from '../services/appointment';
import { FETCH_STATUS } from '../utils/constants';

Expand Down Expand Up @@ -94,8 +94,8 @@ describe('VAOS ChoseDateAndTime component', () => {
vaOnlineSchedulingCCDirectScheduling: true,
},
referral: {
selectedProvider: createProviderDetails(1),
providerFetchStatus: FETCH_STATUS.succeeded,
draftAppointmentInfo: createDraftAppointmentInfo(1),
draftAppointmentCreateStatus: FETCH_STATUS.succeeded,
},
appointments: {
confirmed,
Expand All @@ -107,8 +107,8 @@ describe('VAOS ChoseDateAndTime component', () => {
vaOnlineSchedulingCCDirectScheduling: true,
},
referral: {
selectedProvider: [],
providerFetchStatus: FETCH_STATUS.notStarted,
draftAppointmentInfo: {},
draftAppointmentCreateStatus: FETCH_STATUS.notStarted,
},
appointments: {
confirmed: [],
Expand All @@ -120,8 +120,8 @@ describe('VAOS ChoseDateAndTime component', () => {
vaOnlineSchedulingCCDirectScheduling: true,
},
referral: {
selectedProvider: [],
providerFetchStatus: FETCH_STATUS.failed,
draftAppointmentInfo: {},
draftAppointmentCreateStatus: FETCH_STATUS.failed,
},
appointments: {
confirmed,
Expand All @@ -131,8 +131,8 @@ describe('VAOS ChoseDateAndTime component', () => {
beforeEach(() => {
global.XMLHttpRequest = sinon.useFakeXMLHttpRequest();
sandbox
.stub(getProviderByIdModule, 'getProviderById')
.resolves({ data: createProviderDetails(1) });
.stub(postDraftReferralAppointmentModule, 'postDraftReferralAppointment')
.resolves({ data: createDraftAppointmentInfo(1) });
sandbox
.stub(fetchAppointmentsModule, 'fetchAppointments')
.resolves(confirmedV2);
Expand All @@ -149,7 +149,9 @@ describe('VAOS ChoseDateAndTime component', () => {
store: createTestStore(initialFullState),
},
);
sandbox.assert.notCalled(getProviderByIdModule.getProviderById);
sandbox.assert.notCalled(
postDraftReferralAppointmentModule.postDraftReferralAppointment,
);
sandbox.assert.notCalled(fetchAppointmentsModule.fetchAppointments);
});
it('should call API for provider or appointment data if not in store', async () => {
Expand All @@ -162,7 +164,9 @@ describe('VAOS ChoseDateAndTime component', () => {
},
);
expect(await screen.getByTestId('loading')).to.exist;
sandbox.assert.calledOnce(getProviderByIdModule.getProviderById);
sandbox.assert.calledOnce(
postDraftReferralAppointmentModule.postDraftReferralAppointment,
);
sandbox.assert.calledOnce(fetchAppointmentsModule.fetchAppointments);
});
it('should show error if any fetch fails', async () => {
Expand Down
42 changes: 24 additions & 18 deletions src/applications/vaos/referral-appointments/ReviewAndConfirm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import PropTypes from 'prop-types';
import { useHistory } from 'react-router-dom';
import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import { scrollAndFocus } from '../utils/scrollAndFocus';
import { getProviderInfo, getSelectedSlot } from './redux/selectors';
import { getDraftAppointmentInfo, getSelectedSlot } from './redux/selectors';
import { FETCH_STATUS } from '../utils/constants';
import {
fetchProviderDetails,
createDraftReferralAppointment,
setFormCurrentPage,
setSelectedSlot,
} from './redux/actions';
Expand All @@ -30,13 +30,16 @@ const ReviewAndConfirm = props => {
const dispatch = useDispatch();
const history = useHistory();
const selectedSlot = useSelector(state => getSelectedSlot(state));
const { provider, providerFetchStatus } = useSelector(
state => getProviderInfo(state),
const { draftAppointmentInfo, draftAppointmentCreateStatus } = useSelector(
state => getDraftAppointmentInfo(state),
shallowEqual,
);
const [loading, setLoading] = useState(true);
const [failed, setFailed] = useState(false);
const slotDetails = getSlotById(provider.slots, selectedSlot);
const slotDetails = getSlotById(
draftAppointmentInfo.slots.slots,
selectedSlot,
);
const facilityTimeZone = getTimezoneByFacilityId(
currentReferral.ReferringFacilityInfo.FacilityCode,
);
Expand All @@ -60,28 +63,31 @@ const ReviewAndConfirm = props => {

useEffect(
() => {
if (providerFetchStatus === FETCH_STATUS.notStarted) {
dispatch(fetchProviderDetails(currentReferral.providerId));
} else if (providerFetchStatus === FETCH_STATUS.succeeded) {
if (draftAppointmentCreateStatus === FETCH_STATUS.notStarted) {
dispatch(createDraftReferralAppointment(currentReferral.id));
} else if (draftAppointmentCreateStatus === FETCH_STATUS.succeeded) {
setLoading(false);
scrollAndFocus('h1');
} else if (providerFetchStatus === FETCH_STATUS.failed) {
} else if (draftAppointmentCreateStatus === FETCH_STATUS.failed) {
setLoading(false);
setFailed(true);
scrollAndFocus('h2');
}
},
[currentReferral.providerId, dispatch, providerFetchStatus],
[currentReferral.id, dispatch, draftAppointmentCreateStatus],
);

useEffect(
() => {
if (
!selectedSlot &&
savedSelectedSlot &&
providerFetchStatus === FETCH_STATUS.succeeded
draftAppointmentCreateStatus === FETCH_STATUS.succeeded
) {
const savedSlot = getSlotById(provider.slots, savedSelectedSlot);
const savedSlot = getSlotById(
draftAppointmentInfo.slots.slots,
savedSelectedSlot,
);
if (!savedSlot) {
routeToCCPage(history, 'scheduleReferral');
}
Expand All @@ -91,9 +97,9 @@ const ReviewAndConfirm = props => {
[
dispatch,
savedSelectedSlot,
provider.slots,
draftAppointmentInfo.slots,
history,
providerFetchStatus,
draftAppointmentCreateStatus,
selectedSlot,
],
);
Expand Down Expand Up @@ -134,12 +140,12 @@ const ReviewAndConfirm = props => {
</div>
</div>
<p className="vads-u-margin--0">
{provider.providerName} <br />
{provider.orgName}
{draftAppointmentInfo.provider.name} <br />
{draftAppointmentInfo.provider.providerOrganization.name}
</p>
<ProviderAddress
address={provider.orgAddress}
phone={provider.orgPhone}
address={currentReferral.ReferringFacilityInfo.Address}
phone={currentReferral.ReferringFacilityInfo.Phone}
/>
<hr className="vads-u-margin-y--2" />
<div className=" vads-l-grid-container vads-u-padding--0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import {
} from '../tests/mocks/setup';
import { createReferral, getReferralSlotKey } from './utils/referrals';
import { FETCH_STATUS } from '../utils/constants';
import { createProviderDetails } from './utils/provider';
import * as getProviderByIdModule from '../services/referral';
import { createDraftAppointmentInfo } from './utils/provider';
import * as postDraftReferralAppointmentModule from '../services/referral';

describe('VAOS Component: ReviewAndConfirm', () => {
const sandbox = sinon.createSandbox();
const providerDetails = createProviderDetails(1);
providerDetails.slots[0].start = '2024-09-09T16:00:00.000Z';
const draftAppointmentInfo = createDraftAppointmentInfo(1);
draftAppointmentInfo.slots.slots[0].start = '2024-09-09T16:00:00.000Z';
const initialFullState = {
featureToggles: {
vaOnlineSchedulingCCDirectScheduling: true,
},
referral: {
selectedProvider: providerDetails,
providerFetchStatus: FETCH_STATUS.succeeded,
draftAppointmentInfo,
draftAppointmentCreateStatus: FETCH_STATUS.succeeded,
selectedSlot: '0',
currentPage: 'reviewAndConfirm',
},
Expand All @@ -31,15 +31,15 @@ describe('VAOS Component: ReviewAndConfirm', () => {
vaOnlineSchedulingCCDirectScheduling: true,
},
referral: {
selectedProvider: {},
providerFetchStatus: FETCH_STATUS.notStarted,
draftAppointmentInfo: {},
draftAppointmentCreateStatus: FETCH_STATUS.notStarted,
},
};
beforeEach(() => {
global.XMLHttpRequest = sinon.useFakeXMLHttpRequest();
sandbox
.stub(getProviderByIdModule, 'getProviderById')
.resolves(providerDetails);
.stub(postDraftReferralAppointmentModule, 'postDraftReferralAppointment')
.resolves(draftAppointmentInfo);
});
afterEach(() => {
sandbox.restore();
Expand All @@ -55,11 +55,16 @@ describe('VAOS Component: ReviewAndConfirm', () => {
},
);
expect(await screen.getByTestId('referral-layout-heading')).to.exist;
sandbox.assert.notCalled(getProviderByIdModule.getProviderById);
sandbox.assert.notCalled(
postDraftReferralAppointmentModule.postDraftReferralAppointment,
);
});
it('should fetch provider if not in redux', async () => {
const selectedSlotKey = getReferralSlotKey('UUID');
sessionStorage.setItem(selectedSlotKey, '0');
sessionStorage.setItem(
selectedSlotKey,
'5vuTac8v-practitioner-1-role-2|e43a19a8-b0cb-4dcf-befa-8cc511c3999b|2025-01-02T15:30:00Z|30m0s|1736636444704|ov0',
);
const screen = renderWithStoreAndRouter(
<ReviewAndConfirm
currentReferral={createReferral('2024-09-09', 'UUID')}
Expand All @@ -69,11 +74,16 @@ describe('VAOS Component: ReviewAndConfirm', () => {
},
);
expect(await screen.getByTestId('loading')).to.exist;
sandbox.assert.calledOnce(getProviderByIdModule.getProviderById);
sandbox.assert.calledOnce(
postDraftReferralAppointmentModule.postDraftReferralAppointment,
);
});
it('should get selected slot from session storage if not in redux', async () => {
const selectedSlotKey = getReferralSlotKey('UUID');
sessionStorage.setItem(selectedSlotKey, '0');
sessionStorage.setItem(
selectedSlotKey,
'5vuTac8v-practitioner-1-role-2|e43a19a8-b0cb-4dcf-befa-8cc511c3999b|2025-01-02T15:30:00Z|30m0s|1736636444704|ov0',
);
const noSelectState = {
...initialFullState,
...{ referral: { ...initialFullState.referral, selectedSlot: '' } },
Expand All @@ -93,7 +103,9 @@ describe('VAOS Component: ReviewAndConfirm', () => {
expect(await screen.getByTestId('slot-day-time')).to.contain.text(
'12:00 p.m. Eastern time (ET)',
);
sandbox.assert.notCalled(getProviderByIdModule.getProviderById);
sandbox.assert.notCalled(
postDraftReferralAppointmentModule.postDraftReferralAppointment,
);
});
it('should route to scheduleReferral if no slot selected', async () => {
const selectedSlotKey = getReferralSlotKey('UUID');
Expand All @@ -111,7 +123,9 @@ describe('VAOS Component: ReviewAndConfirm', () => {
path: '/schedule-referral/date-time',
},
);
sandbox.assert.notCalled(getProviderByIdModule.getProviderById);
sandbox.assert.notCalled(
postDraftReferralAppointmentModule.postDraftReferralAppointment,
);
expect(screen.history.push.calledWith('/schedule-referral?id=UUID')).to.be
.true;
});
Expand Down
Loading

0 comments on commit 81eab4c

Please sign in to comment.