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

fix unused controller throwing error in route handling #40

Merged
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
4 changes: 1 addition & 3 deletions src/models/route_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export class RouteInfo implements IRouteInfo {

set path(value) {
this.path_ = value;
if (value) {
this.pathSplitted = value.split("/");
}
this.pathSplitted = value ? value.split("/") : [];
}

get path() {
Expand Down
16 changes: 16 additions & 0 deletions tests/general/controllers/user_profile_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ export class UserProfileController extends Controller {
@shields(UserProfileNestedShield)
export class UserProfileNestedController extends Controller {

@worker()
@route('/me')
async getMe(@singleton(UserService) userService: UserService) {
const userId = await this.session.get('userId');
const user = userService.getUser(userId);
return jsonResult({
nestedProfile: user
});
}
}

// do not remove this -
// this to make sure that controller which is not used but created are not creating problem
@shields(UserProfileNestedShield)
export class NotUsedController extends Controller {

@worker()
@route('/me')
async getMe(@singleton(UserService) userService: UserService) {
Expand Down
5 changes: 1 addition & 4 deletions tests/general/crons/counter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { initServer } from "..";
import { viewResult, Fort, textResult } from "fortjs";
import { Fort } from "fortjs";
import { CounterScheduler } from "./counter";
// import { } from "jest;

// jest.
// jest.sp
describe("counter scheduler", () => {
beforeAll(async () => {
await initServer();
Expand Down
4 changes: 2 additions & 2 deletions tests/general/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build:test:prod": "NODE_ENV=production npm run build:test",
"install:build:test": "npm run install:lib && npm run build:test",
"webpack:watch": "webpack --config webpack.config.js --watch",
"start": "export NODE_OPTIONS=--openssl-legacy-provider; npm run webpack:watch",
"start": "export NODE_OPTIONS=\"--openssl-legacy-provider --enable-source-maps\" && npm run webpack:watch",
"start:dev": "NODE_ENV=development npm run start",
"start:prod": "NODE_ENV=production npm run start"
},
Expand Down Expand Up @@ -51,4 +51,4 @@
"ts-loader": "^8.0.1",
"typescript": "^3.9.7"
}
}
}
3 changes: 2 additions & 1 deletion tests/general/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ describe('DefaultController', () => {
const router = new Router();
const routesAsArray = router.routesAsArray;
expect(routesAsArray).toHaveLength(
routes.length + 2
routes.length + 2 + 1
// +2 due to nested child
// +1 unused controller
);
const controllerName = "HomeController";
const controller = routesAsArray.find(q => q.controllerName === controllerName);
Expand Down
12 changes: 6 additions & 6 deletions tests/general/test/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ describe("/home", () => {
request.get('/setSingletonValue?value=' + value).end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(200);
})

request.get('/getSingletonValue').end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res.text).to.be.equal(value);
done();
request.get('/getSingletonValue').end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res.text).to.be.equal(value);
done();
})
})
})
})
Expand Down
Loading