49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { expect, describe, it, afterEach, beforeAll, beforeEach } from "vitest";
|
|
import { PlatformTest } from "@tsed/common";
|
|
import { UserController } from "./UserController";
|
|
import { User } from "../../entities/user/User";
|
|
import { v4 as uuidv4 } from "uuid";
|
|
import { Server } from "../../Server";
|
|
import { SqliteDatasource, sqliteDatasource } from "src/datasources/SqliteDatasource";
|
|
|
|
describe("UserController", () => {
|
|
let controller: UserController;
|
|
|
|
beforeAll(
|
|
PlatformTest.bootstrap(Server, {
|
|
imports: [sqliteDatasource]
|
|
})
|
|
);
|
|
|
|
beforeEach(async () => {
|
|
controller = await PlatformTest.invoke(UserController, [
|
|
{
|
|
token: SqliteDatasource,
|
|
use: sqliteDatasource
|
|
}
|
|
]);
|
|
});
|
|
|
|
afterEach(() => {
|
|
PlatformTest.reset();
|
|
});
|
|
|
|
it("should get a user by ID", async () => {
|
|
const userId = uuidv4();
|
|
const user = new User();
|
|
user.id = userId;
|
|
user.service = "github";
|
|
user.serviceIdentifier = `user-${userId}`;
|
|
user.links = [];
|
|
const repo = sqliteDatasource.getRepository(User);
|
|
await repo.save(user);
|
|
|
|
const result = await controller.getOne(userId);
|
|
|
|
expect(result).toEqual(user);
|
|
expect(result?.id).toEqual(userId);
|
|
expect(result?.service).toEqual("github");
|
|
expect(result?.serviceIdentifier).toEqual(`user-${userId}`);
|
|
});
|
|
});
|