🚧 typeorm

This commit is contained in:
Flam3rboy
2021-08-27 11:11:16 +02:00
parent 0ecc5d8c0e
commit c21c342821
18 changed files with 1465 additions and 732 deletions
+31
View File
@@ -0,0 +1,31 @@
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("User", () => {
test("valid discriminator: 1", async () => {
new User({ discriminator: "1" }).validate();
});
test("invalid discriminator: test", async () => {
expect(() => {
new User({ discriminator: "test" }).validate();
}).toThrow();
});
test("invalid discriminator: 0", async () => {
expect(() => {
new User({ discriminator: "0" }).validate();
}).toThrow();
});
});
+9 -7
View File
@@ -1,4 +1,4 @@
const { initDatabase } = require("../dist/util/Database");
const { initDatabase, closeDatabase } = require("../dist/util/Database");
const { User } = require("../dist/entities/User");
jest.setTimeout(10000);
@@ -9,13 +9,15 @@ beforeAll((done) => {
});
});
afterAll(() => {
closeDatabase();
});
describe("Validate model class properties", () => {
describe("User", () => {
test("object instead of string", async () => {
expect(() => {
new User({ username: {} }).validate();
}).toThrow();
});
test("object instead of string", async () => {
expect(() => {
new User({}, { id: {} }).validate();
}).toThrow();
});
test("validation should be faster than 20ms", () => {