diff --git a/__mocks__/handlers/progresses.handler.ts b/__mocks__/handlers/progresses.handler.ts index cdf04329a..ccdfc7c8a 100644 --- a/__mocks__/handlers/progresses.handler.ts +++ b/__mocks__/handlers/progresses.handler.ts @@ -1,10 +1,23 @@ import { rest } from 'msw'; import { mockGetTaskProgress } from '../db/progresses'; - const URL = process.env.NEXT_PUBLIC_BASE_URL; export const progressHandler = [ - rest.get(`${URL}/progresses?taskId=OxYqJgf6Tyl90uci1mzs`, (_, res, ctx) => { - return res(ctx.status(200), ctx.json(mockGetTaskProgress)); - }), + rest.get( + `${URL}/progresses?taskId=OxYqJgf6Tyl90uci1mzs`, + (req, res, ctx) => { + const devFlag = req.url.searchParams.get('dev'); + + const progressData = { + ...mockGetTaskProgress, + data: mockGetTaskProgress.data.map((progress) => + devFlag === 'true' + ? { ...progress } + : { ...progress, userData: undefined } + ), + }; + + return res(ctx.status(200), ctx.json(progressData)); + } + ), ]; diff --git a/__tests__/Unit/hooks/progressesApi.test.tsx b/__tests__/Unit/hooks/progressesApi.test.tsx index 2573b33ab..662aa059f 100644 --- a/__tests__/Unit/hooks/progressesApi.test.tsx +++ b/__tests__/Unit/hooks/progressesApi.test.tsx @@ -35,6 +35,30 @@ describe('useGetProgressDetails', () => { await act(() => waitForNextUpdate()); + const nextResponse = result.current; + const taskProgressResponse = nextResponse.data; + expect(nextResponse.status).toEqual('fulfilled'); + expect(nextResponse.error).toBeUndefined(); + expect(nextResponse.isSuccess).toEqual(true); + expect(taskProgressResponse).not.toBeUndefined(); + expect(taskProgressResponse?.data[0].userData).toBeUndefined(); + }); + test('Returns Task Progress with userData in response if dev is true', async () => { + const { result, waitForNextUpdate } = renderHook( + () => + useGetProgressDetailsQuery({ + taskId: 'OxYqJgf6Tyl90uci1mzs', + dev: true, + }), + { wrapper: Wrapper } + ); + + const initialResponse = result.current; + expect(initialResponse.data).toBeUndefined(); + expect(initialResponse.isLoading).toBe(true); + + await act(() => waitForNextUpdate()); + const nextResponse = result.current; const taskProgressResponse = nextResponse.data; expect(nextResponse.status).toEqual('fulfilled'); @@ -42,5 +66,33 @@ describe('useGetProgressDetails', () => { expect(nextResponse.isSuccess).toEqual(true); expect(taskProgressResponse).not.toBeUndefined(); expect(taskProgressResponse).toEqual(mockGetTaskProgress); + expect(taskProgressResponse?.data[0].userData).toEqual( + mockGetTaskProgress.data[0].userData + ); + }); + + test('Returns userData undefined in the Task Progress if dev is false', async () => { + const { result, waitForNextUpdate } = renderHook( + () => + useGetProgressDetailsQuery({ + taskId: 'YttqJgf6Tyl35uci1mzs', + dev: false, + }), + { wrapper: Wrapper } + ); + + const initialResponse = result.current; + expect(initialResponse.data).toBeUndefined(); + expect(initialResponse.isLoading).toBe(true); + + await act(() => waitForNextUpdate()); + + const nextResponse = result.current; + const taskProgressResponse = nextResponse.data; + expect(nextResponse.status).toEqual('fulfilled'); + expect(nextResponse.error).toBeUndefined(); + expect(nextResponse.isSuccess).toEqual(true); + expect(taskProgressResponse).not.toBeUndefined(); + expect(taskProgressResponse?.data[1].userData).toBeUndefined(); }); }); diff --git a/src/app/services/progressesApi.ts b/src/app/services/progressesApi.ts index 9436a90d2..1e8b7eab9 100644 --- a/src/app/services/progressesApi.ts +++ b/src/app/services/progressesApi.ts @@ -4,6 +4,7 @@ import { progressDetails } from '@/types/standup.type'; type queryParamsType = { userId?: string; taskId?: string; + dev?: boolean; }; export const progressesApi = api.injectEndpoints({ @@ -20,10 +21,10 @@ export const progressesApi = api.injectEndpoints({ }), }), getProgressDetails: builder.query({ - query: ({ userId, taskId }: queryParamsType) => { + query: ({ userId, taskId, dev }: queryParamsType) => { return { url: '/progresses', - params: { userId, taskId }, + params: { userId, taskId, dev }, }; }, providesTags: ['Progress_Details'], diff --git a/src/components/taskDetails/index.tsx b/src/components/taskDetails/index.tsx index 51317fdb9..54f118891 100755 --- a/src/components/taskDetails/index.tsx +++ b/src/components/taskDetails/index.tsx @@ -64,6 +64,7 @@ type Props = { const TaskDetails: FC = ({ taskID }) => { const router = useRouter(); + const isDev = router.query.dev === 'true'; const { isUserAuthorized } = useUserData(); const [isEditing, setIsEditing] = useState(false); @@ -76,6 +77,7 @@ const TaskDetails: FC = ({ taskID }) => { const { data: progressData, refetch: refetchProgress } = useGetProgressDetailsQuery({ taskId: taskID, + dev: isDev, }); const isExtensionRequestPending = Boolean(