mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 05:09:32 +00:00
test(core): add missing tests for methods introduced in 97069042
Add comprehensive test coverage for 5 core service methods that were added in the layered architecture refactor but lacked tests: - AgentService.getAgent: found/not-found cases - ProjectService.getUserProjects: team scope, project scope, multi-team aggregation, limit, and empty result cases - SkillService.getSkill: full field mapping and not-found cases - TeamService.hasWritableRoleInAnyTeam: owner, editor, reviewer, and no-membership cases - UserService (new file): getUserById and createGuestUser
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { prisma } from '@shumai/db'
|
||||
import { setupTestDbHooks } from '@shumai/db/test'
|
||||
import { userService } from '@shumai/core/src/user/user'
|
||||
|
||||
describe('UserService', () => {
|
||||
setupTestDbHooks()
|
||||
|
||||
describe('getUserById', () => {
|
||||
it('returns user when exists', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name: 'Test User',
|
||||
email: 'gu-test@example.com',
|
||||
},
|
||||
})
|
||||
|
||||
const result = await userService.getUserById(user.id)
|
||||
|
||||
expect(result).not.toBeNull()
|
||||
expect(result?.id).toBe(user.id)
|
||||
expect(result?.name).toBe('Test User')
|
||||
expect(result?.email).toBe('gu-test@example.com')
|
||||
})
|
||||
|
||||
it('returns null for non-existent ID', async () => {
|
||||
const result = await userService.getUserById('nonexistent-id')
|
||||
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('createGuestUser', () => {
|
||||
it('creates user with correct fields', async () => {
|
||||
const result = await userService.createGuestUser({
|
||||
name: 'Guest',
|
||||
email: 'guest@example.com',
|
||||
guestEmail: 'original@example.com',
|
||||
})
|
||||
|
||||
expect(result.name).toBe('Guest')
|
||||
expect(result.email).toBe('guest@example.com')
|
||||
expect(result.guestEmail).toBe('original@example.com')
|
||||
expect(result.type).toBe('human')
|
||||
})
|
||||
|
||||
it('persists to database', async () => {
|
||||
const result = await userService.createGuestUser({
|
||||
name: 'Guest',
|
||||
email: 'guest@example.com',
|
||||
guestEmail: 'original@example.com',
|
||||
})
|
||||
|
||||
const dbUser = await prisma.user.findUnique({
|
||||
where: { id: result.id },
|
||||
})
|
||||
|
||||
expect(dbUser).not.toBeNull()
|
||||
expect(dbUser?.name).toBe('Guest')
|
||||
expect(dbUser?.email).toBe('guest@example.com')
|
||||
expect(dbUser?.guestEmail).toBe('original@example.com')
|
||||
expect(dbUser?.type).toBe('human')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user