Skip to content

Commit

Permalink
feat: Fetch isCached Field with CommitPageDataQueryOpts - Round 2 (#3631
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nicholas-codecov authored Jan 6, 2025
1 parent 0d5e832 commit 9807408
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const mockCommitPageData = ({
__typename: 'Comparison',
},
bundleAnalysis: {
bundleAnalysisReport: {
__typename: 'BundleAnalysisReport',
isCached: false,
},
bundleAnalysisCompareWithParent: {
__typename: firstPullRequest
? 'FirstPullRequest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ const mockCommitPageData = (
: 'Comparison',
},
bundleAnalysis: {
bundleAnalysisReport: {
__typename: 'BundleAnalysisReport',
isCached: false,
},
bundleAnalysisCompareWithParent: {
__typename: 'BundleAnalysisComparison',
},
Expand Down
4 changes: 4 additions & 0 deletions src/pages/CommitDetailPage/CommitDetailPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const mockCommitPageData = ({
__typename: 'Comparison',
},
bundleAnalysis: {
bundleAnalysisReport: {
__typename: 'BundleAnalysisReport',
isCached: false,
},
bundleAnalysisCompareWithParent: {
__typename: 'BundleAnalysisComparison',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const mockCommitData = {
__typename: 'Comparison',
},
bundleAnalysis: {
bundleAnalysisReport: {
__typename: 'BundleAnalysisReport',
isCached: false,
},
bundleAnalysisCompareWithParent: {
__typename: 'BundleAnalysisComparison',
},
Expand Down Expand Up @@ -89,7 +93,7 @@ interface SetupArgs {
isNullOwner?: boolean
}

describe('useCommitPageData', () => {
describe('CommitPageData', () => {
function setup({
isNotFoundError = false,
isOwnerNotActivatedError = false,
Expand Down Expand Up @@ -146,6 +150,10 @@ describe('useCommitPageData', () => {
__typename: 'Comparison',
},
bundleAnalysis: {
bundleAnalysisReport: {
__typename: 'BundleAnalysisReport',
isCached: false,
},
bundleAnalysisCompareWithParent: {
__typename: 'BundleAnalysisComparison',
},
Expand Down
20 changes: 19 additions & 1 deletion src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import Api from 'shared/api'
import { rejectNetworkError } from 'shared/api/helpers'
import A from 'ui/A'

const BundleAnalysisReportSchema = z.object({
__typename: z.literal('BundleAnalysisReport'),
isCached: z.boolean(),
})

const BundleAnalysisReportUnion = z.discriminatedUnion('__typename', [
BundleAnalysisReportSchema,
z.object({ __typename: MissingHeadReportSchema.shape.__typename }),
])

const BundleAnalysisComparisonResult = z.union([
z.literal('BundleAnalysisComparison'),
FirstPullRequestSchema.shape.__typename,
Expand Down Expand Up @@ -54,6 +64,7 @@ const RepositorySchema = z.object({
.nullable(),
bundleAnalysis: z
.object({
bundleAnalysisReport: BundleAnalysisReportUnion.nullable(),
bundleAnalysisCompareWithParent: z
.object({
__typename: BundleAnalysisComparisonResult,
Expand Down Expand Up @@ -98,6 +109,12 @@ query CommitPageData($owner: String!, $repo: String!, $commitId: String!) {
__typename
}
bundleAnalysis {
bundleAnalysisReport {
__typename
... on BundleAnalysisReport {
isCached
}
}
bundleAnalysisCompareWithParent {
__typename
}
Expand All @@ -112,7 +129,8 @@ query CommitPageData($owner: String!, $repo: String!, $commitId: String!) {
}
}
}
}`
}
`

interface CommitPageDataQueryArgs {
provider: string
Expand Down

0 comments on commit 9807408

Please sign in to comment.