Skip to content

Commit 9136ccd

Browse files
authored
fix: Initial set of parsing errors (#3774)
1 parent 822d109 commit 9136ccd

File tree

9 files changed

+80
-58
lines changed

9 files changed

+80
-58
lines changed

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ describe('CurrentOrgPlan', () => {
318318
describe('when plan value is not provided', () => {
319319
beforeEach(() => {
320320
setup({
321-
accountDetails: { ...mockedAccountDetails },
321+
accountDetails: mockedAccountDetails as z.infer<
322+
typeof AccountDetailsSchema
323+
>,
322324
})
323325
})
324326

src/pages/RepoPage/CoverageTab/OverviewTab/subroute/FileExplorer/FileExplorer.test.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const server = setupServer()
3232
const mockListData = {
3333
username: 'nicholas-codecov',
3434
repository: {
35+
__typename: 'Repository',
3536
branch: {
3637
head: {
3738
pathContents: {
@@ -57,6 +58,7 @@ const mockListData = {
5758
const mockUnknownPath = {
5859
username: 'nicholas-codecov',
5960
repository: {
61+
__typename: 'Repository',
6062
branch: {
6163
head: {
6264
pathContents: {
@@ -71,6 +73,7 @@ const mockUnknownPath = {
7173
const mockMissingCoverage = {
7274
username: 'nicholas-codecov',
7375
repository: {
76+
__typename: 'Repository',
7477
branch: {
7578
head: {
7679
pathContents: {
@@ -85,6 +88,7 @@ const mockMissingCoverage = {
8588
const mockTreeData = {
8689
username: 'nicholas-codecov',
8790
repository: {
91+
__typename: 'Repository',
8892
branch: {
8993
head: {
9094
pathContents: {

src/pages/RepoPage/CoverageTab/OverviewTab/subroute/Sunburst/Sunburst.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Sunburst() {
2929
return <Placeholder />
3030
}
3131

32-
if (isError) {
32+
if (isError || !data) {
3333
return <p>The sunburst chart failed to load.</p>
3434
}
3535

src/pages/RepoPage/CoverageTab/OverviewTab/subroute/Sunburst/Sunburst.test.jsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const treeMock = [
5757
},
5858
]
5959

60+
const mockNullTree = null
61+
6062
const overviewMock = {
6163
owner: {
6264
isCurrentUserActivated: true,
@@ -77,15 +79,13 @@ const repoConfigMock = {
7779
owner: {
7880
repository: {
7981
__typename: 'Repository',
80-
repositoryConfig: {
81-
indicationRange: { upperRange: 80, lowerRange: 60 },
82-
},
82+
repositoryConfig: { indicationRange: { upperRange: 80, lowerRange: 60 } },
8383
},
8484
},
8585
}
8686

8787
describe('Sunburst', () => {
88-
function setup({ coverageTreeStatus = 200 }) {
88+
function setup({ coverageTreeStatus = 200, coverageTreeData = treeMock }) {
8989
server.use(
9090
graphql.query('GetRepoOverview', () => {
9191
return HttpResponse.json({ data: overviewMock })
@@ -94,21 +94,35 @@ describe('Sunburst', () => {
9494
return HttpResponse.json({ data: repoConfigMock })
9595
}),
9696
http.get('/internal/:provider/:owner/:repo/coverage/tree', () => {
97-
return HttpResponse.json(treeMock, {
97+
return HttpResponse.json(coverageTreeData, {
9898
status: coverageTreeStatus,
9999
})
100100
})
101101
)
102102
}
103103

104104
describe('successful call', () => {
105-
it('renders something', async () => {
106-
setup({ coverageTreeStatus: 200 })
107-
render(<Sunburst />, { wrapper })
105+
describe('with valid tree data', () => {
106+
it('renders something', async () => {
107+
setup({ coverageTreeStatus: 200 })
108+
render(<Sunburst />, { wrapper })
108109

109-
const chart = await screen.findByText('Chart Mocked')
110+
const chart = await screen.findByText('Chart Mocked')
110111

111-
expect(chart).toBeInTheDocument()
112+
expect(chart).toBeInTheDocument()
113+
})
114+
})
115+
116+
describe('with invalid tree data', () => {
117+
it('renders something', async () => {
118+
setup({ coverageTreeStatus: 200, coverageTreeData: mockNullTree })
119+
render(<Sunburst />, { wrapper })
120+
121+
const chart = await screen.findByText(
122+
'The sunburst chart failed to load.'
123+
)
124+
expect(chart).toBeInTheDocument()
125+
})
112126
})
113127
})
114128

src/services/account/useAccountDetails.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,39 +119,41 @@ export const SubscriptionDetailSchema = z
119119
})
120120
.nullable()
121121

122-
export const AccountDetailsSchema = z.object({
123-
activatedStudentCount: z.number(),
124-
activatedUserCount: z.number(),
125-
checkoutSessionId: z.string().nullable(),
126-
delinquent: z.boolean().nullable(),
127-
email: z.string().nullable(),
128-
inactiveUserCount: z.number(),
129-
integrationId: z.number().nullable(),
130-
name: z.string().nullable(),
131-
nbActivePrivateRepos: z.number().nullable(),
132-
planAutoActivate: z.boolean().nullable(),
133-
planProvider: z.string().nullable(),
134-
repoTotalCredits: z.number(),
135-
rootOrganization: z
136-
.object({
137-
username: z.string().nullish(),
138-
})
139-
.nullable(),
140-
scheduleDetail: z
141-
.object({
142-
scheduledPhase: z
143-
.object({
144-
quantity: z.number(),
145-
plan: z.string(),
146-
startDate: z.number(),
147-
})
148-
.nullable(),
149-
})
150-
.nullable(),
151-
studentCount: z.number(),
152-
subscriptionDetail: SubscriptionDetailSchema,
153-
usesInvoice: z.boolean(),
154-
})
122+
export const AccountDetailsSchema = z
123+
.object({
124+
activatedStudentCount: z.number(),
125+
activatedUserCount: z.number(),
126+
checkoutSessionId: z.string().nullable(),
127+
delinquent: z.boolean().nullable(),
128+
email: z.string().nullable(),
129+
inactiveUserCount: z.number(),
130+
integrationId: z.number().nullable(),
131+
name: z.string().nullable(),
132+
nbActivePrivateRepos: z.number().nullable(),
133+
planAutoActivate: z.boolean().nullable(),
134+
planProvider: z.string().nullable(),
135+
repoTotalCredits: z.number(),
136+
rootOrganization: z
137+
.object({
138+
username: z.string().nullish(),
139+
})
140+
.nullable(),
141+
scheduleDetail: z
142+
.object({
143+
scheduledPhase: z
144+
.object({
145+
quantity: z.number(),
146+
plan: z.string(),
147+
startDate: z.number(),
148+
})
149+
.nullable(),
150+
})
151+
.nullable(),
152+
studentCount: z.number(),
153+
subscriptionDetail: SubscriptionDetailSchema,
154+
usesInvoice: z.boolean(),
155+
})
156+
.nullish()
155157

156158
export interface UseAccountDetailsArgs {
157159
provider: Provider

src/services/charts/SunburstCoverageQueryOpts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const SunburstSchema: z.ZodType<SunburstResponse> = baseResponseSchema.extend({
2929
children: z.lazy(() => SunburstSchema.array()).optional(),
3030
})
3131

32-
const ResponseSchema = z.array(SunburstSchema)
32+
const ResponseSchema = z.array(SunburstSchema).nullable()
3333

3434
interface SunburstCoverageArgs {
3535
provider: Provider

src/services/pathContents/branch/dir/useRepoBranchContents.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,12 @@ describe('useRepoBranchContents', () => {
325325
})
326326

327327
describe('request rejects', () => {
328-
const oldConsoleError = console.error
329-
330328
beforeEach(() => {
331-
console.error = () => null
329+
vi.spyOn(console, 'error').mockImplementation(() => {})
332330
})
333331

334332
afterEach(() => {
335-
console.error = oldConsoleError
333+
vi.restoreAllMocks()
336334
})
337335

338336
describe('on repository not found', () => {

src/services/pathContents/branch/dir/useRepoBranchContents.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ export type PathContentResultType = z.infer<typeof PathContentsResultSchema>
8181
const RepositorySchema = z.object({
8282
__typename: z.literal('Repository'),
8383
repositoryConfig: RepositoryConfigSchema,
84-
branch: z.object({
85-
head: z
86-
.object({
87-
deprecatedPathContents: PathContentsUnionSchema.nullish(),
88-
})
89-
.nullable(),
90-
}),
84+
branch: z
85+
.object({
86+
head: z
87+
.object({
88+
deprecatedPathContents: PathContentsUnionSchema.nullish(),
89+
})
90+
.nullable(),
91+
})
92+
.nullable(),
9193
})
9294

9395
const BranchContentsSchema = z.object({

src/services/user/useInternalUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const OwnerSchema = z
1313
service: z.string(),
1414
stats: z
1515
.object({
16-
repos: z.number().nullable(),
16+
repos: z.number().nullish(),
1717
})
1818
.nullable(),
1919
username: z.string(),

0 commit comments

Comments
 (0)