mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
Fix all 22 failing unit tests in Gate 2.1
- Fixed API client: Changed response.json().catch() to try-catch pattern (14 tests) - Fixed auth middleware: Check for undefined user before accessing user.level (1 test) - Fixed compiler: Treat empty string as undefined for map field (3 tests) - Fixed retry tests: Use callCount variable instead of mock.calls.length (4 tests) - Fixed unhandled rejection warnings: Add catch handlers in error tests Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -20,9 +20,11 @@ describe('retry utilities', () => {
|
||||
{ statusCode: 503, shouldRetry: true, description: 'service unavailable (retryable)' },
|
||||
{ statusCode: 429, shouldRetry: true, description: 'rate limited (retryable)' },
|
||||
])('should handle $description correctly', async ({ statusCode, shouldRetry }) => {
|
||||
let callCount = 0
|
||||
const mockFetch = vi.fn(async () => { // eslint-disable-line @typescript-eslint/require-await
|
||||
const currentCall = callCount++
|
||||
return new Response(JSON.stringify({ test: 'data' }), {
|
||||
status: shouldRetry ? (mockFetch.mock.calls.length === 0 ? statusCode : 200) : statusCode,
|
||||
status: shouldRetry ? (currentCall === 0 ? statusCode : 200) : statusCode,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -112,9 +114,10 @@ describe('retry utilities', () => {
|
||||
throw new Error('Network error')
|
||||
})
|
||||
|
||||
const promise = retryFetch(mockFetch, { maxRetries: 2, initialDelayMs: 10 })
|
||||
|
||||
// Fast-forward through all retry delays
|
||||
const promise = retryFetch(mockFetch, { maxRetries: 2, initialDelayMs: 10 })
|
||||
// Attach a catch handler to prevent unhandled rejection warning
|
||||
promise.catch(() => {})
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
|
||||
await expect(promise).rejects.toThrow('Network error')
|
||||
@@ -180,8 +183,10 @@ describe('retry utilities', () => {
|
||||
throw new Error('Persistent error')
|
||||
})
|
||||
|
||||
// Fast-forward through all retry delays
|
||||
const promise = retry(mockFn, { maxRetries: 2, initialDelayMs: 10 })
|
||||
|
||||
// Attach a catch handler to prevent unhandled rejection warning
|
||||
promise.catch(() => {})
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
|
||||
await expect(promise).rejects.toThrow('Persistent error')
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function compile(source: string, options?: CompileOptions): Promise
|
||||
return {
|
||||
code: result.code,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
map: (result.map !== null && result.map !== undefined) ? result.map : undefined,
|
||||
map: (result.map !== null && result.map !== undefined && result.map !== '') ? result.map : undefined,
|
||||
}
|
||||
} catch (error) {
|
||||
// Return compilation error as a comment in the code
|
||||
|
||||
@@ -72,7 +72,12 @@ export async function fetchEntityList(
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string }
|
||||
let errorData: { error?: string } = { error: 'Unknown error' }
|
||||
try {
|
||||
errorData = await response.json() as { error?: string }
|
||||
} catch {
|
||||
// If JSON parsing fails, use default error
|
||||
}
|
||||
return {
|
||||
|
||||
error: errorData.error ?? `HTTP ${response.status}`,
|
||||
@@ -121,7 +126,12 @@ export async function fetchEntity(
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string }
|
||||
let errorData: { error?: string } = { error: 'Unknown error' }
|
||||
try {
|
||||
errorData = await response.json() as { error?: string }
|
||||
} catch {
|
||||
// If JSON parsing fails, use default error
|
||||
}
|
||||
return {
|
||||
|
||||
error: errorData.error ?? `HTTP ${response.status}`,
|
||||
@@ -172,7 +182,12 @@ export async function createEntity(
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string }
|
||||
let errorData: { error?: string } = { error: 'Unknown error' }
|
||||
try {
|
||||
errorData = await response.json() as { error?: string }
|
||||
} catch {
|
||||
// If JSON parsing fails, use default error
|
||||
}
|
||||
return {
|
||||
|
||||
error: errorData.error ?? `HTTP ${response.status}`,
|
||||
@@ -225,7 +240,12 @@ export async function updateEntity(
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string }
|
||||
let errorData: { error?: string } = { error: 'Unknown error' }
|
||||
try {
|
||||
errorData = await response.json() as { error?: string }
|
||||
} catch {
|
||||
// If JSON parsing fails, use default error
|
||||
}
|
||||
return {
|
||||
|
||||
error: errorData.error ?? `HTTP ${response.status}`,
|
||||
@@ -275,7 +295,12 @@ export async function deleteEntity(
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string }
|
||||
let errorData: { error?: string } = { error: 'Unknown error' }
|
||||
try {
|
||||
errorData = await response.json() as { error?: string }
|
||||
} catch {
|
||||
// If JSON parsing fails, use default error
|
||||
}
|
||||
return {
|
||||
|
||||
error: errorData.error ?? `HTTP ${response.status}`,
|
||||
|
||||
@@ -85,7 +85,7 @@ export async function authenticate(
|
||||
const user = await getCurrentUser()
|
||||
|
||||
// Check if user is authenticated
|
||||
if (user === null) {
|
||||
if (user === null || user === undefined) {
|
||||
return {
|
||||
success: false,
|
||||
error: NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user