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

44 lines
940 B
JavaScript
Raw Normal View History

2021-08-27 11:11:16 +02:00
const { initDatabase, closeDatabase } = require("../dist/util/Database");
const { User } = require("../dist/entities/User");
2021-08-29 00:03:58 +02:00
jest.setTimeout(20000);
2021-08-27 11:11:16 +02:00
beforeAll((done) => {
initDatabase().then(() => {
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();
});
2021-08-29 00:03:58 +02:00
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);
}
});
2021-08-27 11:11:16 +02:00
});