fix architecture and write new tests
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { idParamSchema, inviteSchema, roleSchema } from './team.schemas'
|
||||
|
||||
describe('team.schemas edge contracts', () => {
|
||||
it('accepts only invite payloads with real names, emails and assignable non-owner roles', () => {
|
||||
expect(inviteSchema.parse({
|
||||
firstName: 'Aya',
|
||||
lastName: 'Haddad',
|
||||
email: 'aya@example.test',
|
||||
role: 'MANAGER',
|
||||
})).toEqual({
|
||||
firstName: 'Aya',
|
||||
lastName: 'Haddad',
|
||||
email: 'aya@example.test',
|
||||
role: 'MANAGER',
|
||||
})
|
||||
|
||||
expect(inviteSchema.safeParse({ firstName: '', lastName: 'Haddad', email: 'aya@example.test', role: 'MANAGER' }).success).toBe(false)
|
||||
expect(inviteSchema.safeParse({ firstName: 'Aya', lastName: 'Haddad', email: 'not-email', role: 'MANAGER' }).success).toBe(false)
|
||||
expect(inviteSchema.safeParse({ firstName: 'Aya', lastName: 'Haddad', email: 'aya@example.test', role: 'OWNER' }).success).toBe(false)
|
||||
})
|
||||
|
||||
it('restricts role changes to operational roles only', () => {
|
||||
expect(roleSchema.parse({ role: 'AGENT' })).toEqual({ role: 'AGENT' })
|
||||
expect(roleSchema.parse({ role: 'MANAGER' })).toEqual({ role: 'MANAGER' })
|
||||
expect(roleSchema.safeParse({ role: 'OWNER' }).success).toBe(false)
|
||||
expect(roleSchema.safeParse({ role: 'ADMIN' }).success).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects empty team member route params', () => {
|
||||
expect(idParamSchema.parse({ id: 'employee_1' })).toEqual({ id: 'employee_1' })
|
||||
expect(idParamSchema.safeParse({ id: '' }).success).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,42 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.mock('../../services/teamService', () => ({
|
||||
listEmployees: vi.fn(),
|
||||
inviteEmployee: vi.fn(),
|
||||
updateEmployeeRole: vi.fn(),
|
||||
deactivateEmployee: vi.fn(),
|
||||
reactivateEmployee: vi.fn(),
|
||||
removeEmployee: vi.fn(),
|
||||
}))
|
||||
|
||||
import { listEmployees } from '../../services/teamService'
|
||||
import { getMembers, getMemberStats } from './team.service'
|
||||
|
||||
describe('team.service module facade', () => {
|
||||
beforeEach(() => vi.clearAllMocks())
|
||||
|
||||
it('returns the tenant member list without modifying teamService output', async () => {
|
||||
const members = [{ id: 'emp_1', role: 'OWNER', isActive: true, invitationStatus: 'accepted' }]
|
||||
vi.mocked(listEmployees).mockResolvedValue(members as never)
|
||||
|
||||
await expect(getMembers('company_1')).resolves.toBe(members)
|
||||
expect(listEmployees).toHaveBeenCalledWith('company_1')
|
||||
})
|
||||
|
||||
it('counts active, pending, and inactive accepted team members explicitly', async () => {
|
||||
vi.mocked(listEmployees).mockResolvedValue([
|
||||
{ id: 'owner_1', isActive: true, invitationStatus: 'accepted' },
|
||||
{ id: 'manager_1', isActive: true, invitationStatus: 'accepted' },
|
||||
{ id: 'agent_1', isActive: false, invitationStatus: 'accepted' },
|
||||
{ id: 'agent_2', isActive: true, invitationStatus: 'pending' },
|
||||
{ id: 'agent_3', isActive: false, invitationStatus: 'revoked' },
|
||||
] as never)
|
||||
|
||||
await expect(getMemberStats('company_1')).resolves.toEqual({
|
||||
total: 5,
|
||||
active: 2,
|
||||
pending: 1,
|
||||
inactive: 1,
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user