mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 00:54:06 -08:00
596c472ecc
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Val <68596159+valya@users.noreply.github.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Valya Bullions <valya@n8n.io> Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: Danny Martini <despair.blue@gmail.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Giulio Andreini <g.andreini@gmail.com> Co-authored-by: Ayato Hayashi <go12limchangyong@gmail.com>
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import Container from 'typedi';
|
|
import { UserRepository } from '@db/repositories/user.repository';
|
|
import { createAdmin, createMember, createOwner } from './shared/db/users';
|
|
import * as testDb from './shared/testDb';
|
|
import { randomEmail } from './shared/random';
|
|
import { ProjectRelationRepository } from '@/databases/repositories/projectRelation.repository';
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|