@tsed/platform-test-sdk
Version:
Package to test platform adapter integration with Ts.ED
63 lines (62 loc) • 2.24 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { Controller } from "@tsed/di";
import { PlatformTest } from "@tsed/platform-http/testing";
import { Get } from "@tsed/schema";
import SuperTest from "supertest";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
export function testChildrenControllers(options) {
let request;
let TestChildController = class TestChildController {
get() {
return "hello child";
}
};
__decorate([
Get("/scenario-2"),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], TestChildController.prototype, "get", null);
TestChildController = __decorate([
Controller("/children")
], TestChildController);
let TestController = class TestController {
scenario1() {
return "hello world";
}
};
__decorate([
Get("/scenario-1"),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], TestController.prototype, "scenario1", null);
TestController = __decorate([
Controller({
path: "/controllers",
children: [TestChildController]
})
], TestController);
beforeEach(PlatformTest.bootstrap(options.server, {
...options,
mount: {
"/rest": [TestController]
}
}));
beforeEach(() => {
request = SuperTest(PlatformTest.callback());
});
afterEach(PlatformTest.reset);
describe("scenario 1: GET /rest/controllers/scenario-1", () => {
it("should return a response from method", async () => {
const response = await request.get("/rest/controllers/scenario-1").expect(200);
expect(response.text).toEqual("hello world");
});
});
describe("scenario 2: GET /rest/controllers/children/scenario-2", () => {
it("should return a response from method", async () => {
const response = await request.get("/rest/controllers/children/scenario-2").expect(200);
expect(response.text).toEqual("hello child");
});
});
}