intended-server/src/controllers/rest/LinkController.integration....

40 lines
1.2 KiB
TypeScript

import { expect, describe, it, afterAll, beforeAll } from "vitest";
import { PlatformTest } from "@tsed/common";
import SuperTest from "supertest";
import { LinkController } from "./LinkController";
import { Server } from "../../Server";
import { randomUUID } from "crypto";
describe("LinkController", () => {
beforeAll(
PlatformTest.bootstrap(Server, {
mount: {
"/rest": [LinkController]
}
})
);
afterAll(PlatformTest.reset);
it("should call POST /rest/links and GET /rest/links/:id", async () => {
const request = SuperTest(PlatformTest.callback());
const username = `silentsilas-${randomUUID()}`;
const response = await request
.post("/rest/links")
.send({
service: "github",
serviceUsername: username
})
.expect(201);
const response2 = await request.get(`/rest/users/${response.body.userId}`).expect(200);
expect(response.body.id).toBeTruthy();
expect(response.body.service).toEqual("github");
expect(response.body.serviceUsername).toEqual(username);
expect(response2.body.id).toEqual(response.body.userId);
expect(response2.body.service).toEqual("github");
expect(response2.body.serviceUsername).toEqual(username);
});
});