Browse Source

Trying to find a leaking user and failing but at least this is probably cleaner.

master
Zed A. Shaw 2 months ago
parent
commit
f5c48e0869
  1. 32
      tests/lib/ormish.js
  2. 6
      tests/ui/admin_email.js
  3. 2
      tests/ui/admin_tables.js
  4. 2
      tests/ui/login.js
  5. 8
      tests/ui/register.js
  6. 6
      tests/ui/unsubscribe.js

32
tests/lib/ormish.js

@ -117,22 +117,28 @@ test("basic crud operations on user", async (t) => {
test("upsert works in all situations", async(t) => {
// attempt upsert that will insert
let up1 = random_user();
let res = await User.upsert(up1, "email");
t.not(res, undefined);
let up2 = await User.first({email: up1.email});
t.is(up1.email, up2.email);
try {
// attempt upsert that will insert
let res = await User.upsert(up1, "email");
t.not(res, undefined);
let up2 = await User.first({email: up1.email});
t.is(up1.email, up2.email);
// attempt upsert that will ignore
delete up2.id;
up2.initials = "TST";
// attempt upsert that will ignore
delete up2.id;
up2.initials = "TST";
let up3 = await User.upsert(up2, "email", false);
let up3 = await User.upsert(up2, "email", false);
let up4 = await User.first({id: up3});
t.is(up4.email, up2.email);
t.not(up4.initials, up2.initials);
let up4 = await User.first({id: up3});
t.is(up4.email, up2.email);
t.not(up4.initials, up2.initials);
} catch(error) {
console.error(error);
} finally {
if(up1) await User.delete({email: up1.email});
}
});

6
tests/ui/admin_email.js

@ -1,5 +1,6 @@
import test from 'ava';
import { login, expect, tid, playstart, playstop} from '../../lib/testing.js';
import { User } from "../../lib/models.js";
test.before(async t => t.context = await playstart('http://localhost:5001/client/#/login/'));
@ -9,9 +10,10 @@ test.after(async t => {
test('test /admin/email/ works', async (t) => {
const {p} = t.context;
let user;
try {
const user = await login(t, p);
user = await login(t, p);
await p.goto('http://localhost:5001/client/#/admin/email/');
@ -40,5 +42,7 @@ test('test /admin/email/ works', async (t) => {
} catch (error) {
console.log(error);
t.fail(error.message);
} finally {
if(user) await User.delete({id: user.id});
}
});

2
tests/ui/admin_tables.js

@ -62,6 +62,6 @@ test('test /admin tables works', async (t) => {
console.log(error);
t.fail(error.message);
} finally {
if(user) User.delete({id: user.id});
if(user) await User.delete({id: user.id});
}
});

2
tests/ui/login.js

@ -60,6 +60,6 @@ test('standalone login page works', async (t) => {
console.log(error);
t.fail(error.message);
} finally {
await User.delete({id: user.id});
if(user) await User.delete({id: user.id});
}
});

8
tests/ui/register.js

@ -15,6 +15,8 @@ test('register form error', async (t) => {
const {context, p} = t.context;
t.not(context, undefined);
let res;
try {
// confirm we get errors
await p.click(tid("register-button"));
@ -43,14 +45,14 @@ test('register form error', async (t) => {
await wait(p, tid('login-form'));
await sleep(100); // need this slight delay to keep playwright happy
const res = await knex('user').where({email: user.email.toLowerCase()}).select();
res = await knex('user').where({email: user.email.toLowerCase()}).select();
t.not(res, undefined);
t.not(res.length, 0);
await User.delete({id: res[0].id});
} catch (error) {
console.log(error);
t.fail(error.message);
} finally {
if(res) await User.delete({id: res[0].id});
}
});

6
tests/ui/unsubscribe.js

@ -1,5 +1,6 @@
import test from 'ava';
import {login, expect, tid, playstart, playstop} from '../../lib/testing.js';
import { User } from "../../lib/models.js";
test.before(async t => t.context = await playstart('http://localhost:5001/client/#/login/'));
@ -9,9 +10,10 @@ test.after(async t => {
test('test /login/ works', async (t) => {
const {p} = t.context;
let user;
try {
const user = await login(t, p);
user = await login(t, p);
await p.goto(`http://localhost:5001/client/#/email/unsubscribe/${user.unsubkey}/`);
await expect(t, p, tid("page-unsubscribe"));
@ -24,5 +26,7 @@ test('test /login/ works', async (t) => {
} catch (error) {
console.log(error);
t.fail(error.message);
} finally {
if(user) await User.delete({id: user.id});
}
});

Loading…
Cancel
Save