diff --git a/src/pages/AccountSettings/tabs/OrgUploadToken/OrgUploadToken.test.tsx b/src/pages/AccountSettings/tabs/OrgUploadToken/OrgUploadToken.test.tsx
index 948c3deffe..1130364d5f 100644
--- a/src/pages/AccountSettings/tabs/OrgUploadToken/OrgUploadToken.test.tsx
+++ b/src/pages/AccountSettings/tabs/OrgUploadToken/OrgUploadToken.test.tsx
@@ -68,8 +68,8 @@ describe('OrgUploadToken', () => {
const user = userEvent.setup()
const mutate = vi.fn()
const addNotification = vi.fn()
- vi.mocked(useFlags).mockReturnValue({ tokenlessSection: true })
+ vi.mocked(useFlags).mockReturnValue({ tokenlessSection: true })
vi.mocked(useAddNotification).mockReturnValue(addNotification)
server.use(
@@ -92,8 +92,8 @@ describe('OrgUploadToken', () => {
},
})
}),
- graphql.mutation('regenerateOrgUploadToken', () => {
- mutate('regenerateOrgUploadToken')
+ graphql.mutation('RegenerateOrgUploadToken', () => {
+ mutate('RegenerateOrgUploadToken')
return HttpResponse.json({
data: {
regenerateOrgUploadToken: {
@@ -170,7 +170,7 @@ describe('OrgUploadToken', () => {
describe('when user clicks on Generate button', () => {
it('calls the mutation', async () => {
- const { mutate, user } = setup({ orgUploadToken: 'token' })
+ const { mutate, user } = setup({ orgUploadToken: '' })
render(, { wrapper })
@@ -197,7 +197,7 @@ describe('OrgUploadToken', () => {
await waitFor(() => expect(mutate).toHaveBeenCalled())
})
- it.only('adds an error notification', async () => {
+ it('adds an error notification', async () => {
const { addNotification, user } = setup({
orgUploadToken: '',
error: 'UnauthenticatedError',
diff --git a/src/pages/AccountSettings/tabs/OrgUploadToken/RegenerateOrgUploadToken.tsx b/src/pages/AccountSettings/tabs/OrgUploadToken/RegenerateOrgUploadToken.tsx
index b6b68056d1..007f3d2ec3 100644
--- a/src/pages/AccountSettings/tabs/OrgUploadToken/RegenerateOrgUploadToken.tsx
+++ b/src/pages/AccountSettings/tabs/OrgUploadToken/RegenerateOrgUploadToken.tsx
@@ -52,7 +52,7 @@ function RegenerateOrgUploadToken({
orgUploadToken: string
}) {
const { owner } = useParams()
- const { regenerateToken, isLoading } = useGenerateOrgUploadToken()
+ const { regenerateTokenAsync, isLoading } = useGenerateOrgUploadToken()
const [showModal, setShowModal] = useState(false)
const isAdmin = useIsCurrentUserAnAdmin({ owner })
@@ -87,7 +87,7 @@ function RegenerateOrgUploadToken({
{showModal && (
setShowModal(false)}
- regenerateToken={() => Promise.resolve(regenerateToken())}
+ regenerateToken={regenerateTokenAsync}
isLoading={isLoading}
/>
)}
diff --git a/src/pages/AccountSettings/tabs/OrgUploadToken/useGenerateOrgUploadToken.ts b/src/pages/AccountSettings/tabs/OrgUploadToken/useGenerateOrgUploadToken.ts
index 22624eaf9a..979c79e4f9 100644
--- a/src/pages/AccountSettings/tabs/OrgUploadToken/useGenerateOrgUploadToken.ts
+++ b/src/pages/AccountSettings/tabs/OrgUploadToken/useGenerateOrgUploadToken.ts
@@ -5,12 +5,12 @@ export default function useGenerateOrgUploadToken() {
const addToast = useAddNotification()
const {
mutate,
+ mutateAsync,
data: res,
...rest
} = useRegenerateOrgUploadToken({
- onSuccess: () => {
- console.log("MY DEBUG 2", res)
- const errString = res?.error?.__typename
+ onSuccess: (result) => {
+ const errString = result?.error?.__typename
if (errString) {
addToast({
@@ -26,5 +26,10 @@ export default function useGenerateOrgUploadToken() {
},
})
- return { regenerateToken: mutate, res, ...rest }
+ return {
+ regenerateToken: mutate,
+ regenerateTokenAsync: mutateAsync,
+ res,
+ ...rest,
+ }
}
diff --git a/src/services/orgUploadToken/useRegenerateOrgUploadToken.test.tsx b/src/services/orgUploadToken/useRegenerateOrgUploadToken.test.tsx
index d8e18d020e..a554317ce2 100644
--- a/src/services/orgUploadToken/useRegenerateOrgUploadToken.test.tsx
+++ b/src/services/orgUploadToken/useRegenerateOrgUploadToken.test.tsx
@@ -1,26 +1,17 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import { act, renderHook, waitFor } from '@testing-library/react'
+import { renderHook, waitFor } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'
-import { useRegenerateOrgUploadToken } from './useRegenerateOrgUploadToken'
-import { rejectNetworkError } from 'shared/api/helpers'
+import * as apiHelpers from 'shared/api/helpers'
-vi.mock('shared/api/helpers', () => ({
- rejectNetworkError: vi.fn(),
-}))
+import { useRegenerateOrgUploadToken } from './useRegenerateOrgUploadToken'
-vi.mock(import('shared/api/helpers'), async (importOriginal) => {
- const actual = await importOriginal()
- return {
- ...actual,
- rejectNetworkError: vi.fn(),
- }
-})
+vi.mock('shared/api/helpers')
const mocks = {
- rejectNetworkError: vi.mocked(rejectNetworkError),
+ rejectNetworkError: vi.spyOn(apiHelpers, 'rejectNetworkError'),
}
const mockData = {
@@ -59,7 +50,7 @@ describe('useRegenerateOrgUploadToken', () => {
function setup({ data = mockData }: { data?: SetupArgs } = {}) {
server.use(
- graphql.mutation('regenerateOrgUploadToken', () => {
+ graphql.mutation('RegenerateOrgUploadToken', () => {
return HttpResponse.json({ data })
})
)
diff --git a/src/services/orgUploadToken/useRegenerateOrgUploadToken.tsx b/src/services/orgUploadToken/useRegenerateOrgUploadToken.tsx
index fcb3b52b5c..b4c2fec572 100644
--- a/src/services/orgUploadToken/useRegenerateOrgUploadToken.tsx
+++ b/src/services/orgUploadToken/useRegenerateOrgUploadToken.tsx
@@ -6,7 +6,7 @@ import Api from 'shared/api'
import { Provider, rejectNetworkError } from 'shared/api/helpers'
const query = `
- mutation regenerateOrgUploadToken(
+ mutation RegenerateOrgUploadToken(
$input: RegenerateOrgUploadTokenInput!
) {
regenerateOrgUploadToken(input: $input) {
@@ -33,7 +33,6 @@ const ResponseSchema = z.object({
__typename: z.literal('UnauthenticatedError'),
}),
])
- .optional()
.nullish(),
orgUploadToken: z.string().nullish(),
})
@@ -45,10 +44,10 @@ interface URLParams {
owner: string
}
-type RegenerateOrgUploadTokenData = z.infer
-
interface UseRegenerateOrgUploadTokenProps {
- onSuccess?: (data: RegenerateOrgUploadTokenData) => void
+ onSuccess?: (
+ data: z.infer['regenerateOrgUploadToken']
+ ) => void
}
export function useRegenerateOrgUploadToken({
@@ -63,7 +62,7 @@ export function useRegenerateOrgUploadToken({
provider,
query,
variables: { input: { owner } },
- mutationPath: 'regenerateOrgUploadToken',
+ mutationPath: 'RegenerateOrgUploadToken',
})
},
useErrorBoundary: true,
@@ -78,8 +77,7 @@ export function useRegenerateOrgUploadToken({
})
}
- console.log("MY DEBUG 3", parsedRes.data)
- onSuccess(parsedRes.data)
+ onSuccess(parsedRes.data.regenerateOrgUploadToken)
},
onSettled: () => {
queryClient.invalidateQueries(['DetailOwner'])