Skip to content

Commit

Permalink
add test case for manipulating data in outgoing event of wall
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed May 17, 2020
1 parent ba3d62b commit df47eb8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 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.

2 changes: 1 addition & 1 deletion src/handlers/request_handler_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class RequestHandlerHelper {

protected wallInstances: Wall[] = [];

protected controllerResult_: HttpResult | HttpFormatResult;
protected controllerResult_: HttpResult | HttpFormatResult = {} as any;

protected runWallOutgoing() {
const outgoingResults: Array<Promise<any>> = [];
Expand Down
8 changes: 7 additions & 1 deletion tests/general/controllers/random_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";


export class RandomController extends Controller {

@DefaultWorker()
async format() {
const result = {
Expand Down Expand Up @@ -62,4 +62,10 @@ export class RandomController extends Controller {
async null() {

}

@Worker()
@Route("/status-override")
async statusCodeOverrideTestUsingWall() {
return textResult("ok", 202);
}
}
10 changes: 10 additions & 0 deletions tests/general/test/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,14 @@ describe("/random", () => {
done();
})
})

it("/status-override using wall", (done) => {
request.get('/random/status-override').end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res).to.have.header('content-type', 'text/plain');
expect(res.text).to.be.equal("overrided");
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(108);
expect(res.body).haveOwnProperty('reqCount').equal(109);
done();
})
})
Expand Down
9 changes: 7 additions & 2 deletions tests/general/walls/request_logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Wall, textResult, Assign } from "fortjs";
import { Wall, textResult, HttpResult, Assign } from "fortjs";
let reqCount = 0;
export class RequestLogger extends Wall {

Expand Down Expand Up @@ -36,9 +36,14 @@ export class RequestLogger extends Wall {
}
}

async onOutgoing(result, @Assign('on outgoing called') value: string) {
async onOutgoing(result: HttpResult, @Assign('on outgoing called') value: string) {
this.logger.log('executing request logger');
this.response.setHeader('Custom-Header-From-Outgoing-Wall', '*');
this.response.setHeader('injection-result', this.injectionValue + ` ${value}`);

if (result.statusCode === 202) {
result.statusCode = 200;
result.responseData = "overrided";
}
}
}

0 comments on commit df47eb8

Please sign in to comment.