Files
boilerplate/apps/backend/src/users/tests/users.service.spec.ts
Bastian Wagner 543e8273a7 initial
2026-07-16 09:49:22 +02:00

42 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { ErrorCode } from '../../common/errors/error-codes';
import { UsersService } from '../users.service';
import type { AuditService } from '../../audit/audit.service';
import type { RolesService } from '../../roles/roles.service';
import type { SessionsService } from '../../sessions/sessions.service';
import type { UsersRepository } from '../repositories/users.repository';
import type { DataSource } from 'typeorm';
describe('UsersService', () => {
it('blocks changes that would remove the last active admin', async () => {
const dataSource = {
getRepository: () => ({
createQueryBuilder: () => ({
innerJoin: () => ({
where: () => ({
andWhere: () => ({
andWhere: () => ({
getCount: () => Promise.resolve(0),
}),
}),
}),
}),
}),
}),
} as unknown as DataSource;
const service = new UsersService(
{} as UsersRepository,
{} as RolesService,
{} as SessionsService,
{} as AuditService,
dataSource,
);
await expect(
service.assertAnotherActiveAdminRemains('user-1'),
).rejects.toMatchObject({
code: ErrorCode.LastAdminRequired,
});
});
});