Browse Source

Implement a way to automatically login during tests.

master
Zed A. Shaw 2 months ago
parent
commit
3c1140915b
  1. 27
      tests/auth.js

27
tests/auth.js

@ -0,0 +1,27 @@
import { User } from "../lib/models.js";
import {sleep, random_user, expect, tid } from '../lib/testing.js';
export const register_user = async () => {
const rando = random_user();
rando.password_repeat = rando.password;
// copy it to keep the original password
const user = await User.register({...rando});
// then replace it so we can use it later
user.raw_password = rando.password;
return user;
}
/* A helper function for other tests to use logins. */
export const login = async (t, p, with_user) => {
const user = with_user ? with_user : await register_user();
await expect(t, p, tid("login-form"));
// fill out correct form, and redirect to watch
await p.fill('#email', user.email);
await p.fill("#password", user.raw_password);
await p.click(tid('login-button'));
await sleep(1000);
return user;
}
Loading…
Cancel
Save