1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-13 06:02:39 +01:00
server/util/tests/validate.test.js

34 lines
746 B
JavaScript
Raw Normal View History

2021-08-27 11:11:16 +02:00
const { initDatabase, closeDatabase } = require("../dist/util/Database");
2021-08-24 16:35:39 +02:00
const { User } = require("../dist/entities/User");
2021-08-26 02:07:16 +02:00
jest.setTimeout(10000);
2021-08-24 16:35:39 +02:00
2021-08-26 02:07:16 +02:00
beforeAll((done) => {
initDatabase().then(() => {
new User().validate(); // warm up schema/model
done();
});
2021-08-24 16:35:39 +02:00
});
2021-08-27 11:11:16 +02:00
afterAll(() => {
closeDatabase();
});
2021-08-24 16:35:39 +02:00
describe("Validate model class properties", () => {
2021-08-27 11:11:16 +02:00
test("object instead of string", async () => {
expect(() => {
new User({}, { id: {} }).validate();
}).toThrow();
2021-08-24 16:35:39 +02:00
});
2021-08-26 02:07:16 +02:00
test("validation should be faster than 20ms", () => {
expect(() => {
new User().validate();
}).toBeFasterThan(20);
});
2021-08-24 16:35:39 +02:00
test("should not set opts", () => {
const user = new User({ opts: { id: 0 } });
expect(user.opts.id).not.toBe(0);
});
});