mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 18:57:16 +00:00
update tests
This commit is contained in:
@@ -77,7 +77,8 @@ export class AuthzService {
|
||||
},
|
||||
})
|
||||
|
||||
if (!pm) throw new HTTPException(403, { message: `User is not a member of project ${projectId}` })
|
||||
if (!pm)
|
||||
throw new HTTPException(403, { message: `User is not a member of project ${projectId}` })
|
||||
|
||||
return this.checkRole(pm.role, req.permission)
|
||||
}
|
||||
@@ -174,7 +175,8 @@ export class AuthzService {
|
||||
})
|
||||
return { teamId: proj!.teamId, projectId: field.projectId }
|
||||
}
|
||||
if (!field.teamId) throw new HTTPException(403, { message: 'Metadata field has no context' })
|
||||
if (!field.teamId)
|
||||
throw new HTTPException(403, { message: 'Metadata field has no context' })
|
||||
return { teamId: field.teamId }
|
||||
}
|
||||
|
||||
@@ -211,7 +213,8 @@ export class AuthzService {
|
||||
include: { asset: { include: { project: true } } },
|
||||
})
|
||||
if (!comment) throw new HTTPException(404, { message: 'Comment not found' })
|
||||
if (!comment.asset.project) throw new HTTPException(403, { message: 'Comment asset has no project' })
|
||||
if (!comment.asset.project)
|
||||
throw new HTTPException(403, { message: 'Comment asset has no project' })
|
||||
return { teamId: comment.asset.project.teamId, projectId: comment.asset.projectId! }
|
||||
}
|
||||
|
||||
|
||||
@@ -185,9 +185,7 @@ export class SearchService {
|
||||
}
|
||||
}
|
||||
|
||||
const countRes = await this.prismaClient.$queryRaw<{ count: bigint }[]>(
|
||||
countBuilder.build(),
|
||||
)
|
||||
const countRes = await this.prismaClient.$queryRaw<{ count: bigint }[]>(countBuilder.build())
|
||||
pageInfo.total = Number(countRes[0]?.count || 0)
|
||||
|
||||
if (hasNextPage) {
|
||||
@@ -368,9 +366,7 @@ export class SearchService {
|
||||
countBuilder.addWhere(Prisma.sql`a.name ILIKE ${'%' + valStr + '%'}`)
|
||||
}
|
||||
|
||||
const countRes = await this.prismaClient.$queryRaw<{ count: bigint }[]>(
|
||||
countBuilder.build(),
|
||||
)
|
||||
const countRes = await this.prismaClient.$queryRaw<{ count: bigint }[]>(countBuilder.build())
|
||||
pageInfo.total = Number(countRes[0]?.count || 0)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { prisma } from '@shumai/db'
|
||||
import { setupTestDbHooks } from '@shumai/db/test'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { transcodeService } from '../transcode'
|
||||
import {
|
||||
getMediaInfoActivity,
|
||||
overlayAnnotationsActivity,
|
||||
takeScreenshotsActivity,
|
||||
transcodeVideoActivity,
|
||||
updateAssetMediaActivity,
|
||||
takeScreenshotsActivity,
|
||||
overlayAnnotationsActivity,
|
||||
} from './transcode'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { transcodeService } from '../transcode'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
|
||||
vi.mock('@shumai/core/src/s3/s3', () => ({
|
||||
s3Service: {
|
||||
@@ -85,6 +85,12 @@ describe('Transcode Activities', () => {
|
||||
|
||||
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/v.mp4')
|
||||
expect(result.duration).toBe(10)
|
||||
expect(result.metadata?.originalWidth).toBe(1920)
|
||||
expect(result.metadata?.videoCodec).toBe('Advanced Video Coding')
|
||||
expect(result.metadata?.audioCodec).toBe('MPEG-4 Audio')
|
||||
expect(result.metadata?.audioChannels).toBe(2)
|
||||
expect(result.metadata?.audioSampleRate).toBe(48000)
|
||||
expect(result.metadata?.audioBitDepth).toBe(16)
|
||||
expect(metadataService.updateAssetMetadata).toHaveBeenCalledWith(
|
||||
asset.id,
|
||||
expect.arrayContaining([{ key: 'file_type', value: 'video' }]),
|
||||
@@ -106,13 +112,15 @@ describe('Transcode Activities', () => {
|
||||
mimeType: 'image/png',
|
||||
})
|
||||
|
||||
await getMediaInfoActivity({
|
||||
const result = await getMediaInfoActivity({
|
||||
assetId: asset.id,
|
||||
filePath: '/tmp/i.png',
|
||||
mediaType: 'image/png',
|
||||
})
|
||||
|
||||
expect(transcodeService.getImageInfo).toHaveBeenCalledWith('/tmp/i.png')
|
||||
expect(result.metadata?.originalWidth).toBe(800)
|
||||
expect(result.metadata?.duration).toBe(0)
|
||||
expect(metadataService.updateAssetMetadata).toHaveBeenCalledWith(
|
||||
asset.id,
|
||||
expect.arrayContaining([{ key: 'file_type', value: 'image' }]),
|
||||
|
||||
@@ -185,7 +185,10 @@ export function SearchFilterDialog({
|
||||
const errorData = (await res.json().catch(() => ({}))) as Record<string, unknown>
|
||||
throw new Error((errorData.message as string) || 'Search failed')
|
||||
}
|
||||
return (await res.json()) as { data: AssetInfo[]; pageInfo?: { total?: number; cursor?: string } }
|
||||
return (await res.json()) as {
|
||||
data: AssetInfo[]
|
||||
pageInfo?: { total?: number; cursor?: string }
|
||||
}
|
||||
},
|
||||
enabled: open && hasActiveCriteria,
|
||||
staleTime: 500,
|
||||
|
||||
Reference in New Issue
Block a user