From 9b4f68dff2e9599e57d4e7d1bcf4bb71939eb747 Mon Sep 17 00:00:00 2001 From: yiling Date: Wed, 20 May 2026 14:45:13 +0800 Subject: [PATCH] test(service): add unit tests for team sandbox methods --- src/services/team/team.test.ts | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/services/team/team.test.ts b/src/services/team/team.test.ts index ee3fd675..48a0e038 100644 --- a/src/services/team/team.test.ts +++ b/src/services/team/team.test.ts @@ -179,4 +179,53 @@ describe('TeamService', () => { const newSettings = await teamService.getSettings(team.id) expect(newSettings).toEqual({ theme: 'dark' }) }) + + it('should create sandbox when team is created', async () => { + const user = await prisma.user.create({ + data: { name: 'Test User', email: `test-sandbox-${Date.now()}@example.com`, password: 'pw' }, + }) + + const team = await teamService.createTeam(user, { + name: 'Sandbox Team', + }) + + const sandbox = await prisma.sandbox.findUnique({ + where: { teamId: team.id }, + }) + + expect(sandbox).toBeDefined() + expect(sandbox?.allowedDomains).toContain('github.com') + }) + + it('should get and update sandbox settings', async () => { + const user = await prisma.user.create({ + data: { name: 'Test User', email: `test-settings-${Date.now()}@example.com`, password: 'pw' }, + }) + const team = await teamService.createTeam(user, { + name: 'Settings Team', + }) + + // Should have default settings + const settings = await teamService.getSandboxSettings(team.id) + expect(settings.allowedDomains).toContain('github.com') + + // Should update settings + const updated = await teamService.updateSandboxSettings(team.id, { + allowedDomains: ['example.com'], + }) + expect(updated.allowedDomains).toEqual(['example.com']) + + // Should persist to DB + const persisted = await teamService.getSandboxSettings(team.id) + expect(persisted.allowedDomains).toEqual(['example.com']) + }) + + it('should return empty allowedDomains if sandbox is missing for old team', async () => { + const team = await prisma.team.create({ + data: { name: 'Old Team' }, + }) + + const settings = await teamService.getSandboxSettings(team.id) + expect(settings.allowedDomains).toEqual([]) + }) })