You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
829 B
TypeScript

import { Users } from "../collections/collections";
import { CollectionItem, TestUtils } from "sealious";
import TheApp from "../app";
type Unpromisify<T> = T extends Promise<infer R> ? R : T;
export function createAUser(app: TheApp, username: string) {
return app.collections.users.suCreate({
username,
email: `${username}@example.com`,
password: "password",
roles: [],
});
}
export async function createAdmin(
app: TheApp,
rest_api: TestUtils.MockRestApi
): Promise<
[CollectionItem<typeof Users>, Unpromisify<ReturnType<typeof rest_api.login>>]
> {
const user = await createAUser(app, "super_user");
await app.collections["user-roles"].suCreate({
user: user.id,
role: "admin",
});
const session = await rest_api.login({
username: "super_user",
password: "password",
});
return [user, session];
}