Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Convert org upload token to ts #3516

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions src/services/orgUploadToken/useRegenerateOrgUploadToken.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import { useRegenerateOrgUploadToken } from './useRegenerateOrgUploadToken'

const data = {
data: {
regenerateOrgUploadToken: {
orgUploadToken: 'new token',
},
regenerateOrgUploadToken: {
orgUploadToken: 'new token',
},
}

Expand All @@ -23,7 +21,7 @@
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
const wrapper = ({ children }) => (

Check failure on line 24 in src/services/orgUploadToken/useRegenerateOrgUploadToken.test.tsx

View workflow job for this annotation

GitHub Actions / Run Type Checker

Binding element 'children' implicitly has an 'any' type.

Check failure on line 24 in src/services/orgUploadToken/useRegenerateOrgUploadToken.test.tsx

View workflow job for this annotation

GitHub Actions / Upload Bundle Stats - Production

Binding element 'children' implicitly has an 'any' type.

Check failure on line 24 in src/services/orgUploadToken/useRegenerateOrgUploadToken.test.tsx

View workflow job for this annotation

GitHub Actions / Upload Bundle Stats - Staging

Binding element 'children' implicitly has an 'any' type.
<MemoryRouter initialEntries={['/gh/codecov/gazebo']}>
<Route path="/:provider/:owner/:repo">
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
Expand Down
83 changes: 83 additions & 0 deletions src/services/orgUploadToken/useRegenerateOrgUploadToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { useParams } from 'react-router-dom'
import { z } from 'zod'

import Api from 'shared/api'
import { NetworkErrorObject } from 'shared/api/helpers'

const RequestSchema = z.object({
regenerateOrgUploadToken: z
.object({
orgUploadToken: z.string().nullish(),
error: z
.union([
z.object({
__typename: z.literal('UnauthorizedError'),
message: z.string(),
}),
z.object({
__typename: z.literal('ValidationError'),
message: z.string(),
}),
z.object({
__typename: z.literal('UnauthenticatedError'),
message: z.string(),
}),
])
.nullish(),
})
.nullable(),
})

interface URLParams {
provider: string
owner: string
}

export function useRegenerateOrgUploadToken(
{ onSuccess = (data: z.infer<typeof RequestSchema>) => {} } = {
onSuccess: () => {},
}
) {
const { provider, owner } = useParams<URLParams>()
const queryClient = useQueryClient()
return useMutation({
mutationFn: async () => {
const query = `
mutation regenerateOrgUploadToken(
$input: RegenerateOrgUploadTokenInput!
) {
regenerateOrgUploadToken(input: $input) {
error {
__typename
}
orgUploadToken
}
}
`
const variables = { input: { owner } }
const data = await Api.graphqlMutation({
provider,
query,
variables,
mutationPath: 'regenerateOrgUploadToken',
})

const parsedRes = RequestSchema.safeParse(data.data)
if (!parsedRes.success) {
return Promise.reject({
status: 404,
data: {},
dev: 'useRegenerateOrgUploadToken - 404 schema parsing failed',
} satisfies NetworkErrorObject)
}

return parsedRes
},
useErrorBoundary: true,
onSuccess: ({ data }) => {
onSuccess(data)
queryClient.invalidateQueries(['DetailOwner'])
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@

const title = await screen.findByText('Missing Head Report')
expect(title).toBeInTheDocument()
const description = await screen.findByText(

Check failure on line 90 in src/shared/ComparisonErrorBanner/ComparisonErrorBanner.test.tsx

View workflow job for this annotation

GitHub Actions / Test Runner #6 - Vitest

src/shared/ComparisonErrorBanner/ComparisonErrorBanner.test.tsx > ComparisonErrorBanner > missing head report error > renders coverage report error

TestingLibraryElementError: Unable to find an element with the text: Unable to compare commits because the head commit did not upload a coverage report. THIS IS A TEST. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible. Ignored nodes: comments, script, style <body> <div> <div class="relative w-full border-l-4 p-4 border-orange-500 bg-orange-100 dark:bg-opacity-20" data-testid="comparison-error-banner" role="alert" > <svg class="stroke-orange-500 float-left -mt-1 mr-2 align-middle w-6 h-6" data-icon="exclamationTriangle" data-testid="exclamationTriangle" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" > <path d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" stroke-linecap="round" stroke-linejoin="round" /> </svg> <h5 class="mb-1 font-semibold" > Missing Head Report </h5> <p class="text-sm" > <span class="flex flex-wrap gap-1" > Unable to compare commits because the head commit did not upload a coverage report. <a class=" font-sans cursor-pointer hover:underline focus:ring-2 text-ds-blue-default inline-flex items-center gap-1" data-cy="missingComparisonReport" data-marketing="missingComparisonReport" href="https://docs.codecov.com/docs/error-reference#missing-base-report" target="_blank" > Learn more here <span class="text-ds-gray-quinary" > <svg class="w-4 h-4" data-icon="" data-testid="" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" > <path d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" /> </svg> </span> </a> </span> </p> </div> </div> </body> Ignored nodes: comments, script, style <body> <div> <div class="relative w-full border-l-4 p-4 border-orange-500 bg-orange-100 dark:bg-opacity-20" data-testid="comparison-error-banner" role="alert" > <svg class="stroke-orange-500 float-left -mt-1 mr-2 align-middle w-6 h-6" data-icon="exclamationTriangle" data-testid="exclamationTriangle" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" > <path d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" stroke-linecap="round" stroke-linejoin="round" /> </svg> <h5 class="mb-1 font-semibold" > Missing Head Report </h5> <p class="text-sm" > <span class="flex flex-wrap gap-1" > Unable to compare commits because the head commit did not upload a coverage report. <a class=" font-sans cursor-pointer hover:underline focus:ring-2 text-ds-blue-default inline-flex items-center gap-1" data-cy="missingComparisonReport" data-marketing="missingComparisonReport" href="https://docs.codecov.com/docs/error-reference#missing-base-report" target="
'Unable to compare commits because the head commit did not upload a coverage report.'
'Unable to compare commits because the head commit did not upload a coverage report. THIS IS A TEST'
)
expect(description).toBeInTheDocument()
})
Expand Down
Loading