You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
2 years ago
|
import test from "ava";
|
||
|
import { Payment } from "../../lib/models.js";
|
||
|
|
||
|
test("quick check the internal uuid generation", (t) => {
|
||
|
let test_id1 = Payment.gen_internal_id();
|
||
|
t.not(test_id1, undefined);
|
||
|
t.not(test_id1, null);
|
||
|
|
||
|
let test_id2 = Payment.gen_internal_id();
|
||
|
t.not(test_id1, undefined);
|
||
|
t.not(test_id1, null);
|
||
|
|
||
|
t.not(test_id1, test_id2);
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
test('test payment model basics work', async (t) => {
|
||
|
try {
|
||
|
let test1 = await Payment.fake_payment();
|
||
|
|
||
|
let test2 = await Payment.first({id: test1.id});
|
||
|
t.is(test1.id, test2.id);
|
||
|
t.not(test1.internal_id, undefined);
|
||
|
t.not(test1.sys_created_on, undefined);
|
||
|
|
||
|
let all = await Payment.all({internal_id: test1.internal_id});
|
||
|
t.is(all.length, 1);
|
||
|
t.is(all[0].internal_id, test1.internal_id);
|
||
|
|
||
|
let new_id = Payment.gen_internal_id();
|
||
|
let res = await Payment.update({id: test1.id}, {internal_id: new_id});
|
||
|
t.is(res, 1);
|
||
|
|
||
|
let count = await Payment.count({internal_id: new_id});
|
||
|
t.is(count, 1);
|
||
|
|
||
|
res = await Payment.first({internal_id: new_id});
|
||
|
t.not(res, undefined);
|
||
|
t.is(res.id, test2.id);
|
||
|
t.is(res.internal_id, new_id);
|
||
|
|
||
|
res = await Payment.delete({id: test2.id});
|
||
|
t.is(res, 1);
|
||
|
|
||
|
count = await Payment.count({id: test2.id});
|
||
|
t.is(count, 0);
|
||
|
|
||
|
all = await Payment.all({id: test2.id});
|
||
|
t.is(all.length, 0);
|
||
|
|
||
|
} catch (error) {
|
||
|
console.log(error);
|
||
|
t.fail(error.message);
|
||
|
}
|
||
|
})
|