✨ update util
This commit is contained in:
+14
-2
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user