Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: fix failing tests

TzeYiingec67a91f2bcc
diff --git a/studio/data/analytics/project-log-stats-query.ts b/studio/data/analytics/project-log-stats-query.ts
index db294c11124..023b1c0cfdb 100644
--- a/studio/data/analytics/project-log-stats-query.ts
+++ b/studio/data/analytics/project-log-stats-query.ts
@@ -44,7 +44,7 @@ export async function getProjectLogStats(
return response as ProjectLogStatsResponse
}
-export type ProjectLogStatsData = Awaited<ReturnType<ProjectLogStatsResponse>>
+export type ProjectLogStatsData = Awaited<ReturnType<typeof getProjectLogStats>>
export type ProjectLogStatsError = unknown
export const useProjectLogStatsQuery = <TData = ProjectLogStatsData>(
diff --git a/studio/tests/components/Home/ProjectUsage.test.js b/studio/tests/components/Home/ProjectUsage.test.js
index dabfd3133f3..159e62052d5 100644
--- a/studio/tests/components/Home/ProjectUsage.test.js
+++ b/studio/tests/components/Home/ProjectUsage.test.js
@@ -1,17 +1,8 @@
import { waitFor, screen } from '@testing-library/react'
-import { render } from '../../helpers'
+import { clickDropdown, render } from '../../helpers'
import userEvent from '@testing-library/user-event'
-jest.mock('lib/common/fetch')
-import { get } from 'lib/common/fetch'
-
-// mock the router
-jest.mock('next/router')
-import { useRouter } from 'next/router'
-import { clickDropdown } from 'tests/helpers'
-const mockPush = jest.fn()
-useRouter.mockReturnValue({ query: { ref: '123' }, push: mockPush })
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { get } from 'lib/common/fetch'
// TODO: abstract out to global setup
const ProjectUsage = jest.fn()
@@ -40,49 +31,35 @@ ProjectUsage.mockImplementation((props) => {
)
})
-jest.mock('components/ui/Flag/Flag')
-import Flag from 'components/ui/Flag/Flag'
-Flag.mockImplementation(({ children }) => <>{children}</>)
-jest.mock('hooks')
-import { useFlag } from 'hooks'
jest.mock('data/subscriptions/project-subscription-query')
import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
-useFlag.mockReturnValue(true)
useProjectSubscriptionQuery.mockReturnValue({
data: undefined,
})
beforeEach(() => {
get.mockReset()
- mockPush.mockReset()
})
const MOCK_CHART_DATA = {
- data: [
+ result: [
{
total_auth_requests: 123,
total_realtime_requests: 223,
total_storage_requests: 323,
total_rest_requests: 333,
- timestamp: new Date().getTime() / 1000,
+ timestamp: new Date().toISOString(),
},
- ],
- total: 123 + 223 + 323,
- totalAverage: 123 + 223 + 323,
- totalGrouped: {
- total_auth_requests: 123,
- total_realtime_requests: 223,
- total_storage_requests: 323,
- total_rest_requests: 333,
- },
+ ]
}
test('mounts correctly', async () => {
get.mockImplementation((url) => {
- if (url.includes('usage')) return {}
- if (url.includes('subscription')) return {}
- return { data: MOCK_CHART_DATA }
+ if (decodeURIComponent(url).includes('usage.api-counts')) {
+ return MOCK_CHART_DATA
+ }
+ return {}
})
render(<ProjectUsage project="12345" />)
await waitFor(() => screen.getByText(/Statistics for past 24 hours/))
@@ -94,8 +71,10 @@ test('mounts correctly', async () => {
test('dropdown options changes chart query', async () => {
get.mockImplementation((url) => {
- if (url.includes('usage')) return {}
- return { data: MOCK_CHART_DATA }
+ if (decodeURIComponent(url).includes('usage.api-counts')) {
+ return MOCK_CHART_DATA
+ }
+ return {}
})
render(<ProjectUsage project="12345" />)
await waitFor(() => screen.getByText(/Statistics for past 24 hours/))
diff --git a/studio/tests/pages/projects/Logs.utils.test.js b/studio/tests/pages/projects/Logs.utils.test.js
index 38f24429f9d..499cb7d8256 100644
--- a/studio/tests/pages/projects/Logs.utils.test.js
+++ b/studio/tests/pages/projects/Logs.utils.test.js
@@ -151,7 +151,7 @@ test.each([
len: 2,
min: '2023-04-26T18:00:00.000Z',
max: '2023-04-26T19:00:00.000Z',
- keys: ['count', 'other'],
+ valKey: ['count', 'other'],
includes: [
{ timestamp: '2023-04-26T18:00:00.000Z', count: 0, other: 0 },
{ timestamp: '2023-04-26T19:00:00.000Z', count: 0, other: 0 },