Skip to content

Commit

Permalink
added test for assign decorator for multiple strings value
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed Oct 30, 2019
1 parent d77cddc commit 1787378
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 8 deletions.
10 changes: 8 additions & 2 deletions dist/fort.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/fort.js.map

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/handlers/injector_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ const singletons: {
export class InjectorHandler {

static addWorkerValue(className: string, methodName: string, paramIndex, paramValue, shouldFindIndex = true): number {
if (shouldFindIndex === true && injectorValues.indexOf(paramValue) < 0) {
paramValue = injectorValues.push(paramValue) - 1;

if (shouldFindIndex === true) {
const paramValueIndex = injectorValues.indexOf(paramValue);
if (paramValueIndex < 0) {
paramValue = injectorValues.push(paramValue) - 1;
}
else {
paramValue = paramValueIndex;
}
}


const savedValue = injectorStoreInfos.find(x => x.className === className);
const value: InjectorStoreInfo = {
Expand Down
1 change: 0 additions & 1 deletion tests/general/controllers/home_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,5 @@ export class HomeController extends Controller {
@Singleton(EmployeeService) employeeService) {
return jsonResult([...studentService.getAll(), ...employeeService.getAll(),
...userService.getUsers()]);

}
}
10 changes: 10 additions & 0 deletions tests/general/controllers/injection_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller, viewResult, Worker, Route, jsonResult, HTTP_METHOD, DefaultWorker, Assign, Singleton, textResult } from "fortjs";

export class InjectionController extends Controller {

@Worker()
async getMultipleStringInjection(@Assign('Welcome to fort') title, @Assign('Hello World') helloWorld, @Assign('ujjwal') firstName, @Assign('Gupta') lastName) {
return jsonResult({ value: [title, helloWorld, firstName, lastName] });
}

}
4 changes: 4 additions & 0 deletions tests/general/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CookieController } from "./controllers/cookie_controller";
import { SessionController } from "./controllers/session_controller";
import { ParentRoute } from "fortjs";
import { DefaultController } from "./controllers/default_controller";
import { InjectionController } from "./controllers/injection_controller";

export const routes: ParentRoute[] = [{
controller: DefaultController,
Expand All @@ -24,4 +25,7 @@ export const routes: ParentRoute[] = [{
}, {
controller: SessionController,
path: "/session"
}, {
controller: InjectionController,
path: "/injection"
}];
25 changes: 25 additions & 0 deletions tests/general/test/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,29 @@ describe("/home", () => {
done();
});
});

it('/getAllFromServices', (done) => {
request.get('/home/getAllFromServices').end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(200);
const data = [{
id: 1,
name: 'ujjwal',
type: 'student'
}, {
id: 1,
name: 'ujjwal',
type: 'employee'
}, {
id: 1,
name: 'ujjwal',
address: 'bhubaneswar india',
emailId: 'ujjwal@mg.com',
gender: 'male',
password: 'admin'
}]
expect(res.body).to.be.eql(data);
done();
});
});
});
2 changes: 1 addition & 1 deletion tests/general/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require('./file_test');
require('./random');
require('./user');
require('./session');

require('./injection');
require('./wall');

// process.exit(0);
Expand Down
17 changes: 17 additions & 0 deletions tests/general/test/injection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let {
request,
expect
} = require('./common');

describe("Injection", () => {
it("/getMultipleStringInjection", (done) => {

request.get('/Injection/getMultipleStringInjection').end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(200);
const data = {"value":["Welcome to fort","Hello World","ujjwal","Gupta"]};
expect(res.body).to.be.eql(data);
done();
})
})
})
2 changes: 1 addition & 1 deletion tests/general/test/wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("wall test", () => {
expect(res).to.have.header('custom-header-from-incoming-wall', '*');
expect(res).to.have.header('injection-result', 'wall constructor onIncoming called on outgoing called');
expect(res).to.have.header('wall-without-outgoing-wall', '*');
expect(res.body).haveOwnProperty('reqCount').equal(84);
expect(res.body).haveOwnProperty('reqCount').equal(86);
done();
})
})
Expand Down

0 comments on commit 1787378

Please sign in to comment.