✨ update util

This commit is contained in:
Flam3rboy
2021-08-29 00:03:58 +02:00
parent e99008a1a5
commit 766dcc24aa
35 changed files with 853 additions and 6515 deletions
+14 -2
View File
@@ -1,10 +1,9 @@
const { initDatabase, closeDatabase } = require("../dist/util/Database");
const { User } = require("../dist/entities/User");
jest.setTimeout(10000);
jest.setTimeout(20000);
beforeAll((done) => {
initDatabase().then(() => {
new User().validate(); // warm up schema/model
done();
});
});
@@ -28,4 +27,17 @@ describe("User", () => {
new User({ discriminator: "0" }).validate();
}).toThrow();
});
test("add guild", async () => {
try {
await new User({ guilds: [], discriminator: "1" }, { id: "0" }).save();
const user = await User.find("0");
user.guilds.push(new Guild({ name: "test" }));
user.save();
} catch (error) {
console.error(error);
}
});
});
+4
View File
@@ -1,4 +1,8 @@
const { performance } = require("perf_hooks");
const fs = require("fs");
const path = require("path");
// fs.unlinkSync(path.join(__dirname, "..", "database.db"));
global.expect.extend({
toBeFasterThan: async (func, target) => {
-33
View File
@@ -1,33 +0,0 @@
const { initDatabase, closeDatabase } = require("../dist/util/Database");
const { User } = require("../dist/entities/User");
jest.setTimeout(10000);
beforeAll((done) => {
initDatabase().then(() => {
new User().validate(); // warm up schema/model
done();
});
});
afterAll(() => {
closeDatabase();
});
describe("Validate model class properties", () => {
test("object instead of string", async () => {
expect(() => {
new User({}, { id: {} }).validate();
}).toThrow();
});
test("validation should be faster than 20ms", () => {
expect(() => {
new User().validate();
}).toBeFasterThan(20);
});
test("should not set opts", () => {
const user = new User({ opts: { id: 0 } });
expect(user.opts.id).not.toBe(0);
});
});