initial
This commit is contained in:
41
apps/backend/src/users/tests/users.service.spec.ts
Normal file
41
apps/backend/src/users/tests/users.service.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user