1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-01-30 10:26:29 +00:00
bramw_baserow/e2e-tests/fixtures/user.ts
2024-11-14 12:30:42 +00:00

68 lines
1.8 KiB
TypeScript

import { getClient } from "../client";
import { faker } from "@faker-js/faker";
export type User = {
name: string;
email: string;
password?: string;
language: string;
accessToken: string;
refreshToken: string;
};
export async function getTokenAuth(
email: String,
password: String
): Promise<User> {
/**
* Authenticates an existing user.
*/
const response: any = await getClient().post("user/token-auth/", {
email: email,
password: password,
});
return {
name: response.data.user.first_name,
email: response.data.user.username,
language: response.data.user.language,
accessToken: response.data.access_token,
refreshToken: response.data.refresh_token,
};
}
export async function getStaffUser(): Promise<User> {
/**
* Authenticates as the 'e2e' staff user. Used in fixtures which rely
* on API endpoints that require an admin/staff user.
*/
return getTokenAuth("e2e@baserow.io", "testpassword");
}
export async function createUser(skipOnboarding = true): Promise<User> {
const password = faker.internet.password();
const response: any = await getClient().post("user/", {
name: faker.name.fullName(),
email: faker.internet.email(),
password,
language: "en",
authenticate: true,
});
const user: User = {
name: response.data.user.first_name,
email: response.data.user.username,
password,
language: response.data.user.language,
accessToken: response.data.access_token,
refreshToken: response.data.refresh_token,
};
if (skipOnboarding) {
await getClient(user).patch("user/account/", {
completed_onboarding: true,
});
}
return user;
}
export async function deleteUser(user: User): Promise<any> {
await getClient(user).post("user/schedule-account-deletion/");
}