mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
5156313074
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Waiting to run
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import Container from 'typedi';
|
|
|
|
import { ProjectRelationRepository } from '@/databases/repositories/project-relation.repository';
|
|
import { UserRepository } from '@/databases/repositories/user.repository';
|
|
|
|
import { createAdmin, createMember, createOwner } from './shared/db/users';
|
|
import { randomEmail } from './shared/random';
|
|
import * as testDb from './shared/test-db';
|
|
|
|
describe('UserRepository', () => {
|
|
let userRepository: UserRepository;
|
|
|
|
beforeAll(async () => {
|
|
await testDb.init();
|
|
|
|
userRepository = Container.get(UserRepository);
|
|
|
|
await testDb.truncate(['User']);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await testDb.terminate();
|
|
});
|
|
|
|
describe('countUsersByRole()', () => {
|
|
test('should return the number of users in each role', async () => {
|
|
await Promise.all([
|
|
createOwner(),
|
|
createAdmin(),
|
|
createAdmin(),
|
|
createMember(),
|
|
createMember(),
|
|
createMember(),
|
|
]);
|
|
|
|
const usersByRole = await userRepository.countUsersByRole();
|
|
|
|
expect(usersByRole).toStrictEqual({
|
|
'global:admin': 2,
|
|
'global:member': 3,
|
|
'global:owner': 1,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('createUserWithProject()', () => {
|
|
test('should create personal project for a user', async () => {
|
|
const { user, project } = await userRepository.createUserWithProject({
|
|
email: randomEmail(),
|
|
role: 'global:member',
|
|
});
|
|
|
|
const projectRelation = await Container.get(ProjectRelationRepository).findOneOrFail({
|
|
where: {
|
|
userId: user.id,
|
|
project: {
|
|
type: 'personal',
|
|
},
|
|
},
|
|
relations: ['project'],
|
|
});
|
|
|
|
expect(projectRelation.project.id).toBe(project.id);
|
|
});
|
|
});
|
|
});
|