Skip to content

Commit

Permalink
[CLD-626] Fix GEO Diary showing appointments for other negotiators (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
trankhacvy authored Dec 24, 2019
1 parent 4ec37f1 commit 191d32f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/sagas/__tests__/appointments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
selectTomorrowAppointments,
selectWeekAppointments
} from '@/selectors/appointments'
import { selectUserCode } from '@/selectors/auth'
import { cloneableGenerator } from '@redux-saga/testing-utils'

jest.mock('../../core/store')
Expand All @@ -49,6 +50,7 @@ const params2: Action<AppointmentRequestParams> = {

const mockOnlineVal = true
const mockOfflineVal = false
const mockNegotiatorId = 'JWB'

const mockHeaders = {
Authorization: '123'
Expand Down Expand Up @@ -108,12 +110,12 @@ describe('appointments should fetch data', () => {

expect(gen.next().value).toEqual(select(selectOnlineStatus))
expect(gen.next(mockOnlineVal as any).value).toEqual(put(appointmentsLoading(true)))
expect(gen.next().value).toEqual(call(initAuthorizedRequestHeaders))
expect(gen.next().value).toEqual(select(selectUserCode))
expect(gen.next(mockNegotiatorId).value).toEqual(call(initAuthorizedRequestHeaders))

expect(gen.next(mockHeaders as any).value).toEqual(
call(fetcher, {
url:
'/appointments?Start=2019-10-10T00:00:00.000Z&End=2019-10-10T23:59:59.999Z&IncludeCancelled=true&IncludeUnconfirmed=true',
url: `/appointments?NegotiatorId=${mockNegotiatorId}&Start=2019-10-10T00:00:00.000Z&End=2019-10-10T23:59:59.999Z&IncludeCancelled=true&IncludeUnconfirmed=true`,
api: process.env.PLATFORM_API_BASE_URL as string,
method: 'GET',
headers: mockHeaders
Expand Down Expand Up @@ -166,12 +168,12 @@ describe('appointments should fetch data tomowrrow', () => {

expect(gen.next().value).toEqual(select(selectOnlineStatus))
expect(gen.next(mockOnlineVal as any).value).toEqual(put(appointmentsLoading(true)))
expect(gen.next().value).toEqual(call(initAuthorizedRequestHeaders))
expect(gen.next().value).toEqual(select(selectUserCode))
expect(gen.next(mockNegotiatorId).value).toEqual(call(initAuthorizedRequestHeaders))

expect(gen.next(mockHeaders as any).value).toEqual(
call(fetcher, {
url:
'/appointments?Start=2019-10-11T00:00:00.000Z&End=2019-10-11T23:59:59.999Z&IncludeCancelled=true&IncludeUnconfirmed=true',
url: `/appointments?NegotiatorId=${mockNegotiatorId}&Start=2019-10-11T00:00:00.000Z&End=2019-10-11T23:59:59.999Z&IncludeCancelled=true&IncludeUnconfirmed=true`,
api: process.env.PLATFORM_API_BASE_URL as string,
method: 'GET',
headers: mockHeaders
Expand Down Expand Up @@ -224,12 +226,12 @@ describe('appointments should fetch data week view', () => {

expect(gen.next().value).toEqual(select(selectOnlineStatus))
expect(gen.next(mockOnlineVal as any).value).toEqual(put(appointmentsLoading(true)))
expect(gen.next().value).toEqual(call(initAuthorizedRequestHeaders))
expect(gen.next().value).toEqual(select(selectUserCode))
expect(gen.next(mockNegotiatorId).value).toEqual(call(initAuthorizedRequestHeaders))

expect(gen.next(mockHeaders as any).value).toEqual(
call(fetcher, {
url:
'/appointments?Start=2019-10-10T00:00:00.000Z&End=2019-10-16T23:59:59.999Z&IncludeCancelled=true&IncludeUnconfirmed=true',
url: `/appointments?NegotiatorId=${mockNegotiatorId}&Start=2019-10-10T00:00:00.000Z&End=2019-10-16T23:59:59.999Z&IncludeCancelled=true&IncludeUnconfirmed=true`,
api: process.env.PLATFORM_API_BASE_URL as string,
method: 'GET',
headers: mockHeaders
Expand Down
4 changes: 3 additions & 1 deletion src/sagas/appointments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { URLS } from '@/constants/api'
import { fetcher } from '@reapit/elements'
import { Action } from '@/types/core'
import { selectOnlineStatus } from '@/selectors/online'
import { selectUserCode } from '@/selectors/auth'
import { AppointmentRequestParams } from '@/actions/appointments'
import { initAuthorizedRequestHeaders } from '@/utils/api'
import { sortAppoinmentsByStartTime } from '@/utils/sortAppoinmentsByStartTime'
Expand Down Expand Up @@ -77,12 +78,13 @@ export const appointmentsDataFetch = function*({ data: { time } }: Action<Appoin
// Enable this to fetch past data if there is no data for current period
// start = dayjs().subtract(150, 'day')
// end = dayjs()
const userCode = yield select(selectUserCode)
try {
const headers = yield call(initAuthorizedRequestHeaders)
const appointments = yield call(fetcher, {
url: `${
URLS.appointments
}?Start=${start.toISOString()}&End=${end.toISOString()}&IncludeCancelled=true&IncludeUnconfirmed=true`,
}?NegotiatorId=${userCode}&Start=${start.toISOString()}&End=${end.toISOString()}&IncludeCancelled=true&IncludeUnconfirmed=true`,
api: process.env.PLATFORM_API_BASE_URL as string,
method: 'GET',
headers
Expand Down

0 comments on commit 191d32f

Please sign in to comment.