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:
yiling
2026-08-01 20:44:34 +08:00
parent 1600949e4a
commit 3b86d9b6d8
5 changed files with 269 additions and 0 deletions
+32
View File
@@ -223,4 +223,36 @@ describe('SkillService', () => {
})
expect(dbSkill?.config).toEqual(newConfig)
})
describe('getSkill', () => {
it('returns skill info with teamId when it exists', async () => {
const team = await prisma.team.create({ data: { name: 'Test Team' } })
const skill = await prisma.skill.create({
data: {
name: 'My Skill',
description: 'A description',
assetId: 'asset-1',
hash: 'hash-1',
teamId: team.id,
},
})
const result = await skillService.getSkill(skill.id)
expect(result).not.toBeNull()
expect(result?.id).toBe(skill.id)
expect(result?.name).toBe('My Skill')
expect(result?.description).toBe('A description')
expect(result?.teamId).toBe(team.id)
expect(result?.assetId).toBe('asset-1')
expect(result?.hash).toBe('hash-1')
expect(result?.permission).toBe('reviewer')
expect(typeof result?.createdAt).toBe('string')
expect(typeof result?.updatedAt).toBe('string')
})
it('returns null for non-existent ID', async () => {
const result = await skillService.getSkill('nonexistent-id')
expect(result).toBeNull()
})
})
})