mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
Phase 3: Fix unsafe any assignments and more strict boolean errors
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -37,7 +37,7 @@ export const GET = async (request: NextRequest, { params }: RouteParams) => {
|
||||
jobLimit,
|
||||
})
|
||||
|
||||
if (!result) {
|
||||
if (result === null || result === undefined) {
|
||||
return NextResponse.json({ error: 'Failed to fetch workflow logs' }, { status: 500 })
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export const GET = async (request: NextRequest) => {
|
||||
const perPageParam = request.nextUrl.searchParams.get('perPage')
|
||||
let perPage = 20
|
||||
|
||||
if (perPageParam) {
|
||||
if (perPageParam !== null && perPageParam !== undefined && perPageParam.length > 0) {
|
||||
const parsed = Number(perPageParam)
|
||||
if (!Number.isNaN(parsed)) {
|
||||
perPage = Math.max(1, Math.min(100, Math.floor(parsed)))
|
||||
|
||||
@@ -6,7 +6,7 @@ import { GET } from './route'
|
||||
describe('GET /api/health', () => {
|
||||
it('returns OK status and permission level count', async () => {
|
||||
const response = GET(new NextRequest('http://example.com/api/health'))
|
||||
const payload = await response.json()
|
||||
const payload = await response.json() as Record<string, unknown>
|
||||
|
||||
expect(payload.status).toBe('ok')
|
||||
expect(typeof payload.timestamp).toBe('string')
|
||||
|
||||
@@ -18,7 +18,7 @@ interface RouteParams {
|
||||
export async function PUT(request: NextRequest, { params }: RouteParams) {
|
||||
try {
|
||||
const body = await readJson<PackageDataPayload>(request)
|
||||
if (!body?.data || Array.isArray(body.data)) {
|
||||
if (body?.data === null || body?.data === undefined || Array.isArray(body.data)) {
|
||||
return NextResponse.json({ error: 'Package data is required' }, { status: 400 })
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ export default async function RootPage() {
|
||||
|
||||
// If route has full component tree, render it directly
|
||||
if (route.componentTree !== null && route.componentTree !== undefined && route.componentTree.length > 0) {
|
||||
const componentDef = JSON.parse(route.componentTree)
|
||||
const componentDef = JSON.parse(route.componentTree) as Record<string, unknown>
|
||||
return renderJSONComponent(componentDef, {}, {})
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('getAppConfig', () => {
|
||||
|
||||
const result = await getAppConfig()
|
||||
|
||||
if (expected) {
|
||||
if (expected !== null && expected !== undefined) {
|
||||
expect(result).toMatchObject(expected)
|
||||
} else {
|
||||
expect(result).toBeNull()
|
||||
|
||||
@@ -23,8 +23,15 @@ describe('setComments', () => {
|
||||
mockDelete.mockResolvedValue(undefined)
|
||||
mockCreate.mockResolvedValue(undefined)
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await setComments([{ id: 'new', userId: 'u1', content: 'Hi', createdAt: 1000 }] as any)
|
||||
const testComment: Comment = {
|
||||
id: 'new',
|
||||
userId: 'u1',
|
||||
entityType: 'test',
|
||||
entityId: 'test1',
|
||||
content: 'Hi',
|
||||
createdAt: 1000
|
||||
}
|
||||
await setComments([testComment])
|
||||
|
||||
expect(mockDelete).toHaveBeenCalledTimes(1)
|
||||
expect(mockCreate).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -18,11 +18,11 @@ export async function getComponentConfigs(): Promise<Record<string, ComponentCon
|
||||
configs[config.id] = {
|
||||
id: config.id,
|
||||
componentId: config.componentId,
|
||||
props: JSON.parse(config.props),
|
||||
styles: JSON.parse(config.styles),
|
||||
events: JSON.parse(config.events),
|
||||
conditionalRendering: config.conditionalRendering
|
||||
? JSON.parse(config.conditionalRendering)
|
||||
props: JSON.parse(config.props) as Record<string, unknown>,
|
||||
styles: JSON.parse(config.styles) as Record<string, unknown>,
|
||||
events: JSON.parse(config.events) as Record<string, unknown>,
|
||||
conditionalRendering: config.conditionalRendering !== null && config.conditionalRendering !== undefined
|
||||
? (JSON.parse(config.conditionalRendering) as Record<string, unknown>)
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ export async function getCssClasses(): Promise<CssCategory[]> {
|
||||
const rows = result.data as Array<{ name: string; classes: string | string[] }>
|
||||
return rows.map(c => ({
|
||||
name: c.name,
|
||||
classes: typeof c.classes === 'string' ? JSON.parse(c.classes) : c.classes,
|
||||
classes: typeof c.classes === 'string' ? (JSON.parse(c.classes) as string[]) : c.classes,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ describe('addErrorLog', () => {
|
||||
expect(mockCreate).toHaveBeenCalledWith(
|
||||
'ErrorLog',
|
||||
expect.objectContaining({
|
||||
id: expect.stringContaining('error_'),
|
||||
timestamp: expect.any(BigInt),
|
||||
id: expect.stringContaining('error_') as string,
|
||||
timestamp: expect.any(BigInt) as bigint,
|
||||
level: log.level,
|
||||
message: log.message,
|
||||
resolved: false,
|
||||
|
||||
@@ -125,7 +125,7 @@ describe('getErrorLogs', () => {
|
||||
expect(mockList).toHaveBeenCalledWith('ErrorLog')
|
||||
expect(result).toHaveLength(expectedLength)
|
||||
|
||||
if (options?.tenantId && result.length > 0) {
|
||||
if (options?.tenantId !== null && options?.tenantId !== undefined && result.length > 0) {
|
||||
expect(result.every(log => log.tenantId === options.tenantId)).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user