ci: Delete some duplicate code in cli tests (no-changelog) (#9049)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-04-05 13:47:49 +02:00
committed by GitHub
parent b8ab049932
commit ff77ef4b62
5 changed files with 42 additions and 49 deletions

View File

@@ -12,12 +12,10 @@ import { randomApiKey, randomEmail, randomName, randomValidPassword } from '../r
// pre-computed bcrypt hash for the string 'password', using `await hash('password', 10)`
const passwordHash = '$2a$10$njedH7S6V5898mj6p0Jr..IGY9Ms.qNwR7RbSzzX9yubJocKfvGGK';
/**
* Store a user in the DB, defaulting to a `member`.
*/
export async function createUser(attributes: Partial<User> = {}): Promise<User> {
/** Store a new user object, defaulting to a `member` */
export async function newUser(attributes: Partial<User> = {}): Promise<User> {
const { email, password, firstName, lastName, role, ...rest } = attributes;
const user = Container.get(UserRepository).create({
return Container.get(UserRepository).create({
email: email ?? randomEmail(),
password: password ? await hash(password, 1) : passwordHash,
firstName: firstName ?? randomName(),
@@ -25,8 +23,12 @@ export async function createUser(attributes: Partial<User> = {}): Promise<User>
role: role ?? 'global:member',
...rest,
});
user.computeIsOwner();
}
/** Store a user object in the DB */
export async function createUser(attributes: Partial<User> = {}): Promise<User> {
const user = await newUser(attributes);
user.computeIsOwner();
return await Container.get(UserRepository).save(user);
}
@@ -98,21 +100,11 @@ export async function createManyUsers(
amount: number,
attributes: Partial<User> = {},
): Promise<User[]> {
let { email, password, firstName, lastName, role, ...rest } = attributes;
const users = await Promise.all(
[...Array(amount)].map(async () =>
Container.get(UserRepository).create({
email: email ?? randomEmail(),
password: password ? await hash(password, 1) : passwordHash,
firstName: firstName ?? randomName(),
lastName: lastName ?? randomName(),
role: role ?? 'global:member',
...rest,
}),
),
Array(amount)
.fill(0)
.map(async () => await newUser(attributes)),
);
return await Container.get(UserRepository).save(users);
}