Skip to content

Commit 04081e9

Browse files
fix tests by updating queries, dates, imports
1 parent 32da88b commit 04081e9

File tree

9 files changed

+30
-28
lines changed

9 files changed

+30
-28
lines changed

frontend/__tests__/unit/data/mockProgramData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const mockPrograms = [
77
description: 'This is a summary of Program 1.',
88
startedAt: '2025-01-01',
99
endedAt: '2025-12-31',
10-
status: 'published',
10+
status: ProgramStatusEnum.Published,
1111
modules: ['Module A', 'Module B'],
1212
},
1313
]

frontend/__tests__/unit/pages/About.test.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import { useRouter } from 'next/navigation'
66
import { act } from 'react'
77
import { render } from 'wrappers/testUtil'
88
import About from 'app/about/page'
9-
import { GET_PROJECT_METADATA, GET_TOP_CONTRIBUTORS } from 'server/queries/projectQueries'
10-
import { GET_LEADER_DATA } from 'server/queries/userQueries'
9+
import {
10+
GetProjectMetadataDocument,
11+
GetTopContributorsDocument,
12+
} from 'types/__generated__/projectQueries.generated'
13+
import { GetLeaderDataDocument } from 'types/__generated__/userQueries.generated'
1114

1215
jest.mock('@apollo/client/react', () => ({
1316
...jest.requireActual('@apollo/client/react'),
@@ -116,15 +119,15 @@ describe('About Component', () => {
116119
;(useQuery as unknown as jest.Mock).mockImplementation((query, options) => {
117120
const key = options?.variables?.key
118121

119-
if (query === GET_PROJECT_METADATA) {
122+
if (query === GetProjectMetadataDocument) {
120123
if (key === 'nest') {
121124
return mockProjectData
122125
}
123-
} else if (query === GET_TOP_CONTRIBUTORS) {
126+
} else if (query === GetTopContributorsDocument) {
124127
if (key === 'nest') {
125128
return mockTopContributorsData
126129
}
127-
} else if (query === GET_LEADER_DATA) {
130+
} else if (query === GetLeaderDataDocument) {
128131
return mockUserData(key)
129132
}
130133

@@ -530,7 +533,7 @@ describe('About Component', () => {
530533

531534
test('triggers toaster error when GraphQL request fails for project', async () => {
532535
;(useQuery as unknown as jest.Mock).mockImplementation((query, options) => {
533-
if (query === GET_PROJECT_METADATA && options?.variables?.key === 'nest') {
536+
if (query === GetProjectMetadataDocument && options?.variables?.key === 'nest') {
534537
return { loading: false, data: null, error: new Error('GraphQL error') }
535538
}
536539
return {
@@ -556,7 +559,7 @@ describe('About Component', () => {
556559

557560
test('triggers toaster error when GraphQL request fails for topContributors', async () => {
558561
;(useQuery as unknown as jest.Mock).mockImplementation((query, options) => {
559-
if (query === GET_TOP_CONTRIBUTORS && options?.variables?.key === 'nest') {
562+
if (query === GetTopContributorsDocument && options?.variables?.key === 'nest') {
560563
return { loading: false, data: null, error: new Error('GraphQL error') }
561564
}
562565
return {

frontend/__tests__/unit/pages/ApiKeysPage.test.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { format, addDays } from 'date-fns'
66
import React from 'react'
77
import { render } from 'wrappers/testUtil'
88
import ApiKeysPage from 'app/settings/api-keys/page'
9-
import { CREATE_API_KEY, REVOKE_API_KEY } from 'server/queries/apiKeyQueries'
9+
import {
10+
CreateApiKeyDocument,
11+
RevokeApiKeyDocument,
12+
} from 'types/__generated__/apiKeyQueries.generated'
1013

1114
jest.mock('@apollo/client/react', () => ({
1215
...jest.requireActual('@apollo/client/react'),
@@ -65,10 +68,10 @@ describe('ApiKeysPage Component', () => {
6568
})
6669

6770
mockUseMutation.mockImplementation((mutation) => {
68-
if (mutation === CREATE_API_KEY) {
71+
if (mutation === CreateApiKeyDocument) {
6972
return [mockCreateMutation, { loading: false }]
7073
}
71-
if (mutation === REVOKE_API_KEY) {
74+
if (mutation === RevokeApiKeyDocument) {
7275
return [mockRevokeMutation, { loading: false }]
7376
}
7477
return [jest.fn(), { loading: false }]
@@ -169,7 +172,7 @@ describe('ApiKeysPage Component', () => {
169172
expect(mockCreateMutation).toHaveBeenCalledWith({
170173
variables: expect.objectContaining({
171174
name: expectedVariables.name,
172-
expiresAt: expect.any(Date),
175+
expiresAt: expect.any(String),
173176
}),
174177
})
175178
})
@@ -196,7 +199,7 @@ describe('ApiKeysPage Component', () => {
196199
expect(mockCreateMutation).toHaveBeenCalledWith({
197200
variables: {
198201
name: 'Test Key with Expiry',
199-
expiresAt: new Date('2025-12-31'),
202+
expiresAt: new Date('2025-12-31T00:00:00.000Z').toISOString(),
200203
},
201204
})
202205
})

frontend/__tests__/unit/pages/CreateModule.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { useMutation, useQuery } from '@apollo/client/react'
2-
import { useApolloClient } from '@apollo/client/react'
1+
import { useMutation, useQuery, useApolloClient } from '@apollo/client/react'
32
import { screen, fireEvent, waitFor, act } from '@testing-library/react'
43
import { useRouter, useParams } from 'next/navigation'
54
import { useSession } from 'next-auth/react'
@@ -17,7 +16,6 @@ jest.mock('next/navigation', () => ({
1716
}))
1817

1918
jest.mock('@apollo/client/react', () => ({
20-
...jest.requireActual('@apollo/client/react'),
2119
useMutation: jest.fn(),
2220
useQuery: jest.fn(),
2321
useApolloClient: jest.fn(),

frontend/__tests__/unit/pages/EditModule.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { useMutation, useQuery } from '@apollo/client/react'
2-
import { useApolloClient } from '@apollo/client/react'
1+
import { useMutation, useQuery, useApolloClient } from '@apollo/client/react'
32
import { screen, fireEvent, waitFor, act } from '@testing-library/react'
43
import { useRouter, useParams } from 'next/navigation'
54
import { useSession } from 'next-auth/react'
@@ -18,13 +17,12 @@ jest.mock('next/navigation', () => ({
1817
}))
1918

2019
jest.mock('@apollo/client/react', () => ({
21-
...jest.requireActual('@apollo/client/react'),
2220
useMutation: jest.fn(),
2321
useQuery: jest.fn(),
22+
useApolloClient: jest.fn(),
2423
}))
2524

2625
jest.mock('@apollo/client', () => ({
27-
useApolloClient: jest.fn(),
2826
gql: jest.requireActual('@apollo/client').gql,
2927
}))
3028

frontend/__tests__/unit/utils/structuredData.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('generateProfilePageStructuredData', () => {
2626
expect(result).toEqual({
2727
'@context': 'https://schema.org',
2828
'@type': 'ProfilePage',
29-
dateCreated: '1970-01-01T00:33:40.000Z',
30-
dateModified: '1970-01-01T00:33:41.000Z',
29+
dateCreated: '2020-01-01T00:00:00.000Z',
30+
dateModified: '2021-02-03T00:00:00.000Z',
3131
mainEntity: {
3232
'@type': 'Person',
3333
address: 'San Francisco, CA, USA',

frontend/src/app/mentorship/programs/[programKey]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ProgramDetailsPage = () => {
6969
}
7070

7171
const programDetails = [
72-
{ label: 'Status', value: upperFirst(program.status) },
72+
{ label: 'Status', value: upperFirst(program.status.toLowerCase()) },
7373
{ label: 'Start Date', value: formatDate(program.startedAt) },
7474
{ label: 'End Date', value: formatDate(program.endedAt) },
7575
{ label: 'Mentees Limit', value: String(program.menteesLimit) },

frontend/src/app/my/mentorship/programs/[programKey]/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const ProgramDetailsPage = () => {
8080
})
8181

8282
addToast({
83-
title: `Program status updated to ${upperFirst(newStatus)}`,
83+
title: `Program status updated to ${upperFirst(newStatus.toLowerCase())}`,
8484
description: 'The status has been successfully updated.',
8585
variant: 'solid',
8686
color: 'success',
@@ -128,9 +128,9 @@ const ProgramDetailsPage = () => {
128128
}
129129

130130
const programDetails = [
131-
{ label: 'Status', value: upperFirst(program.status) },
132-
{ label: 'Start Date', value: formatDate(program.startedAt as string) },
133-
{ label: 'End Date', value: formatDate(program.endedAt as string) },
131+
{ label: 'Status', value: upperFirst(program.status.toLowerCase()) },
132+
{ label: 'Start Date', value: formatDate(program.startedAt) },
133+
{ label: 'End Date', value: formatDate(program.endedAt) },
134134
{ label: 'Mentees Limit', value: String(program.menteesLimit) },
135135
{
136136
label: 'Experience Levels',

frontend/src/components/SingleModuleCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const SingleModuleCard: React.FC<SingleModuleCardProps> = ({
5151
}
5252

5353
const moduleDetails = [
54-
{ label: 'Experience Level', value: upperFirst(module.experienceLevel) },
54+
{ label: 'Experience Level', value: upperFirst(module.experienceLevel.toLowerCase()) },
5555
{ label: 'Start Date', value: formatDate(module.startedAt) },
5656
{ label: 'End Date', value: formatDate(module.endedAt) },
5757
{ label: 'Duration', value: getSimpleDuration(module.startedAt, module.endedAt) },

0 commit comments

Comments
 (0)