Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Oct 3, 2024
1 parent 14051c5 commit d92c415
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { useComponentsBackfilled } from 'services/repo'
export function useRepoBackfillingStatus() {
const { data } = useComponentsBackfilled()

const componentsMeasurementsActive =
data?.coverageAnalytics?.componentsMeasurementsActive
const componentsMeasurementsActive = data?.componentsMeasurementsActive
const componentsMeasurementsBackfilled =
data?.coverageAnalytics?.componentsMeasurementsBackfilled
data?.componentsMeasurementsBackfilled
const isTimescaleEnabled = data?.isTimescaleEnabled
const isRepoBackfilling =
componentsMeasurementsActive && !componentsMeasurementsBackfilled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Header = ({
Configured components
</h3>
<p className="flex flex-1 text-xl font-light text-ds-gray-octonary">
{data?.coverageAnalytics?.componentsCount}
{data?.componentsCount}
</p>
<p className="text-xs">
{/* @ts-expect-error */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,35 @@ const mockedComponentMeasurements = {
owner: {
repository: {
__typename: 'Repository',
components: [
{
componentId: 'components1_id',
name: 'components1',
percentCovered: 93.26,
percentChange: -1.56,
lastUploaded: '2021-09-30T00:00:00Z',
measurements: [{ avg: 51.78 }, { avg: 93.356 }],
},
{
componentId: 'components2_id',
name: 'component2',
percentCovered: 91.74,
percentChange: null,
lastUploaded: null,
measurements: [{ avg: null }, { avg: null }],
},

{
componentId: 'testtest_id',
name: 'testtest',
percentCovered: 1.0,
percentChange: 1.0,
lastUploaded: null,
measurements: [{ avg: 51.78 }, { avg: 93.356 }],
},
],
coverageAnalytics: {
components: [
{
componentId: 'components1_id',
name: 'components1',
percentCovered: 93.26,
percentChange: -1.56,
lastUploaded: '2021-09-30T00:00:00Z',
measurements: [{ avg: 51.78 }, { avg: 93.356 }],
},
{
componentId: 'components2_id',
name: 'component2',
percentCovered: 91.74,
percentChange: null,
lastUploaded: null,
measurements: [{ avg: null }, { avg: null }],
},

{
componentId: 'testtest_id',
name: 'testtest',
percentCovered: 1.0,
percentChange: 1.0,
lastUploaded: null,
measurements: [{ avg: 51.78 }, { avg: 93.356 }],
},
],
},
},
},
}
Expand All @@ -78,16 +80,18 @@ const mockNoReportsUploadedMeasurements = {
owner: {
repository: {
__typename: 'Repository',
components: [
{
name: 'components1',
componentId: 'components1_id',
percentCovered: null,
percentChange: null,
lastUploaded: null,
measurements: [],
},
],
coverageAnalytics: {
components: [
{
name: 'components1',
componentId: 'components1_id',
percentCovered: null,
percentChange: null,
lastUploaded: null,
measurements: [],
},
],
},
},
},
}
Expand All @@ -96,7 +100,9 @@ const mockEmptyComponentMeasurements = {
owner: {
repository: {
__typename: 'Repository',
components: [],
coverageAnalytics: {
components: [],
},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ const mockFirstResponse = {
owner: {
repository: {
__typename: 'Repository',
flags: {
edges: [
{
node: {
name: 'flag-1',
coverageAnalytics: {
flags: {
edges: [
{
node: {
name: 'flag-1',
},
},
],
pageInfo: {
hasNextPage: true,
endCursor: '1-flag-1',
},
],
pageInfo: {
hasNextPage: true,
endCursor: '1-flag-1',
},
},
},
Expand All @@ -64,17 +66,19 @@ const mockSecondResponse = {
owner: {
repository: {
__typename: 'Repository',
flags: {
edges: [
{
node: {
name: 'flag-2',
coverageAnalytics: {
flags: {
edges: [
{
node: {
name: 'flag-2',
},
},
],
pageInfo: {
hasNextPage: false,
endCursor: null,
},
],
pageInfo: {
hasNextPage: false,
endCursor: null,
},
},
},
Expand Down
7 changes: 2 additions & 5 deletions src/services/repo/useComponentsBackfilled.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ describe('useComponentsBackfilled', () => {
})

const expectedResponse = {
__typename: 'Repository',
coverageAnalytics: {
componentsMeasurementsActive: true,
componentsMeasurementsBackfilled: true,
},
componentsMeasurementsActive: true,
componentsMeasurementsBackfilled: true,
}
await waitFor(() =>
expect(result.current.data).toEqual(expectedResponse)
Expand Down
2 changes: 1 addition & 1 deletion src/services/repo/useComponentsBackfilled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function useComponentsBackfilled() {

return {
...data?.config,
...data?.owner?.repository,
...data?.owner?.repository?.coverageAnalytics,
}
}),
})
Expand Down
2 changes: 1 addition & 1 deletion src/services/repo/useRepoBackfilled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function useRepoBackfilled() {

return {
...data?.config,
...data?.owner?.repository,
...data?.owner?.repository?.coverageAnalytics,
}
}),
})
Expand Down
8 changes: 6 additions & 2 deletions src/services/repo/useRepoComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export const ComponentEdgeSchema = z.object({

const RepositorySchema = z.object({
__typename: z.literal('Repository'),
components: z.array(ComponentEdgeSchema),
coverageAnalytics: z
.object({
components: z.array(ComponentEdgeSchema),
})
.nullable(),
})

const RequestSchema = z.object({
Expand Down Expand Up @@ -168,7 +172,7 @@ function fetchRepoComponents({

// This returns something else 2
return {
components: data?.owner?.repository?.components,
components: data?.owner?.repository?.coverageAnalytics?.components,
}
})
}
Expand Down
23 changes: 15 additions & 8 deletions src/services/repo/useRepoComponentsSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ query RepoComponentsSelector(

const RepositorySchema = z.object({
__typename: z.literal('Repository'),
componentsYaml: z
.array(
z.object({
name: z.string(),
id: z.string(),
})
)
coverageAnalytics: z
.object({
componentsYaml: z
.array(
z.object({
name: z.string(),
id: z.string(),
})
)
.nullable(),
})
.nullable(),
})

Expand Down Expand Up @@ -136,7 +140,10 @@ export function useRepoComponentsSelect({
} satisfies NetworkErrorObject)
}

return { components: data?.owner?.repository?.componentsYaml || [] }
return {
components:
data?.owner?.repository?.coverageAnalytics?.componentsYaml || [],
}
}),
...opts,
})
Expand Down

0 comments on commit d92c415

Please sign in to comment.