Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Add a test to ensure that we can load a route at the root. #726

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/e2e/scenarios/modules/networking/controllers.scenario.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,38 @@ describe("Networking - Controllers", () => {
expect(response instanceof Response).toBeTruthy()
expect(response.status).toBe(200);
})

it("should load the 'nested' controller", async () => {
const kernel = new Kernel();
await kernel.start(testModule, {
"pristine.logging.consoleLoggerActivated": false,
"pristine.logging.fileLoggerActivated": false,
});

let request = new Request(HttpMethod.Get, "https://localhost:8080/api/2.0/magieno/pristine");

let response = await kernel.handle(request, {
keyname: ExecutionContextKeynameEnum.Jest,
context: {}
}) as Response;

expect(response instanceof Response).toBeTruthy()
expect(response.status).toBe(200);
expect(response.body).toStrictEqual({"NestedController": true});

request = new Request(HttpMethod.Post, "https://localhost:8080/api/2.0/magieno/pristine");
const body = {
"my_body": true,
};
request.body = body;

response = await kernel.handle(request, {
keyname: ExecutionContextKeynameEnum.Jest,
context: {}
}) as Response;

expect(response instanceof Response).toBeTruthy()
expect(response.status).toBe(200);
expect(response.body).toStrictEqual(body);
})
})
16 changes: 16 additions & 0 deletions tests/e2e/src/controllers/nested.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {controller, route, body, routeParameter} from "@pristine-ts/networking";
import {HttpMethod} from "@pristine-ts/common";


@controller("/api/2.0/magieno/pristine")
export class NestedController {
@route(HttpMethod.Get, "/")
get() {
return {"NestedController": true}
}

@route(HttpMethod.Post, "/")
post(@body() body: any) {
return body;
}
}
3 changes: 2 additions & 1 deletion tests/e2e/src/test.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {InjectedClass} from "./models/injected-class.model";
import {Voter1Model} from "./models/voter1.model";
import {Voter2Model} from "./models/voter2.model";
import {TestController} from "./controllers/test.controller";
import {NestedController} from "./controllers/nested.controller";
import {TestGuard} from "./guards/test.guard";
import {SecurityModule} from "@pristine-ts/security";
import {AppModuleInterface} from "@pristine-ts/common";
import {NetworkingModule} from "@pristine-ts/networking";

export const testModule: AppModuleInterface = {
keyname: "test",
importServices: [TestController],
importServices: [TestController, NestedController],
importModules: [CoreModule, SecurityModule, NetworkingModule],
providerRegistrations: [
{
Expand Down