server/tests/cli.skip-test.ts

95 lines
2.8 KiB
TypeScript
Raw Normal View History

2023-11-21 00:58:39 +01:00
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import { client } from "~database/datasource";
import { createNewLocalUser } from "~database/entities/User";
describe("cli.ts", () => {
2024-04-07 07:30:49 +02:00
describe("User creation", () => {
it("should execute user create command without admin flag", async () => {
afterAll(async () => {
await client.user.deleteMany({
where: {
username: "testuser297",
email: "testuser297@gmail.com",
},
});
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
// Run command and wait for it to finish
Bun.spawnSync([
"bun",
"run",
"cli.ts",
"user",
"create",
"testuser297",
"password123",
"testuser297@gmail.com",
]);
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
const createdUser = await client.user.findFirst({
where: {
username: "testuser297",
email: "testuser297@gmail.com",
},
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
expect(createdUser).toBeDefined();
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
it("should execute user create command with admin flag", async () => {
afterAll(async () => {
await client.user.deleteMany({
where: {
username: "testuser297",
email: "testuser297@gmail.com",
},
});
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
// Run command and wait for it to finish
Bun.spawnSync([
"bun",
"run",
"cli.ts",
"user",
"create",
"testuser297",
"password123",
"testuser297@gmail.com",
"--admin",
]);
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
const createdUser = await client.user.findFirst({
where: {
username: "testuser297",
email: "testuser297@gmail.com",
isAdmin: true,
},
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
expect(createdUser).toBeDefined();
});
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
it("should execute user delete command", async () => {
beforeAll(async () => {
await createNewLocalUser({
username: "bob124",
password: "jesus",
email: "bob124@bob124.com",
});
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
Bun.spawnSync(["bun", "run", "cli", "user", "delete", "bob124"]);
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
const userExists = await client.user.findFirst({
where: {
username: "bob124",
email: "bob124@bob124.com",
},
});
2023-11-21 00:58:39 +01:00
2024-04-07 07:30:49 +02:00
expect(!!userExists).toBe(false);
});
2023-11-21 00:58:39 +01:00
});