Skip to content

Commit

Permalink
Tslinting tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogelio-o committed Dec 25, 2017
1 parent 220b2e1 commit fe94953
Show file tree
Hide file tree
Showing 26 changed files with 1,342 additions and 1,284 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test": "nyc --reporter=html --reporter=text mocha --recursive dist/test/",
"posttest": "npm run lint && nyc check-coverage --statements 90 --branches 90 --functions 90 --lines 90",
"compile": "tsc",
"lint": "tslint --config tslint.json --project tsconfig.json src/{,**/,**/**/,**/**/**/}*.ts",
"lint": "tslint --config tslint.json --project tsconfig.json",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"prepublish": "npm-auto-version"
},
Expand Down
53 changes: 27 additions & 26 deletions test/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
import * as Chai from 'chai'
/* tslint:disable:no-unused-expression */
import * as Chai from "chai";
import { stub } from "sinon";
import { App } from '../src/index'
import { App } from "../src/index";
import { configuration } from "../src/index";
import defaultConfiguration from "../src/lib/configuration/defaultConfiguration";
import Router from "../src/lib/Router";
import { configuration } from '../src/index'
import defaultConfiguration from '../src/lib/configuration/defaultConfiguration'
import DefaultCallback from './utils/DefaultCallback';
import httpEvent from './utils/httpEvent';
import otherEvent from './utils/otherEvent';
import DefaultCallback from "./utils/DefaultCallback";
import httpEvent from "./utils/httpEvent";
import otherEvent from "./utils/otherEvent";

/**
* Test for App.
*/
describe('App', () => {
describe("App", () => {
let app: App;

beforeEach(() => {
app = new App()
app = new App();
});

it('#init without settings should init with default configuration', async () => {
app.init()
it("#init without settings should init with default configuration", async () => {
app.init();
Object.keys(defaultConfiguration)
.forEach(param => Chai.expect(defaultConfiguration[param]).to.be.equal(app.get(param)))
.forEach((param) => Chai.expect(defaultConfiguration[param]).to.be.equal(app.get(param)));
});

it('#init with settings should init with custom configuration', async () => {
const settings = {}
settings[configuration.DEFAULT_MYME_TYPE] = 'text/html'
it("#init with settings should init with custom configuration", async () => {
const settings = {};
settings[configuration.DEFAULT_MYME_TYPE] = "text/html";

app.init(settings)
app.init(settings);
Object.keys(settings)
.forEach(param => Chai.expect(settings[param]).to.be.equal(app.get(param)))
.forEach((param) => Chai.expect(settings[param]).to.be.equal(app.get(param)));
});

it('#enable should set the param as true', async () => {
app.enable('option1')
Chai.expect(app.get('option1')).to.be.true
it("#enable should set the param as true", async () => {
app.enable("option1");
Chai.expect(app.get("option1")).to.be.true;
});

it('#disable should set the param as false', async () => {
app.disable('option1')
Chai.expect(app.get('option1')).to.be.false
it("#disable should set the param as false", async () => {
app.disable("option1");
Chai.expect(app.get("option1")).to.be.false;
});

it('#set should set the param with the indicated value', async () => {
app.set('option1', 'value1')
Chai.expect(app.get('option1')).to.be.equal('value1')
it("#set should set the param with the indicated value", async () => {
app.set("option1", "value1");
Chai.expect(app.get("option1")).to.be.equal("value1");
});

describe("#handle", () => {
Expand Down
97 changes: 49 additions & 48 deletions test/event/EventLayer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
import * as Chai from 'chai'
import EventRequest from './../../src/lib/event/EventRequest'
import EventLayer from './../../src/lib/event/EventLayer'
import otherEvent from './../utils/otherEvent';
/* tslint:disable:no-unused-expression */
import * as Chai from "chai";
import EventLayer from "./../../src/lib/event/EventLayer";
import EventRequest from "./../../src/lib/event/EventRequest";
import otherEvent from "./../utils/otherEvent";

/**
* Test for EventLayer.
*/
describe('EventLayer', () => {
let req
describe("EventLayer", () => {
let req;

beforeEach(() => {
req = new EventRequest(Object.assign({}, otherEvent))
})
req = new EventRequest(Object.assign({}, otherEvent));
});

describe('#match', () => {
it('should return true if the looking event is an event type (string) and the event type of the given #request is the same.', () => {
const layer = new EventLayer('S3CreateEvent', () => {})
Chai.expect(layer.match(req)).to.be.true
describe("#match", () => {
it("should return true if the looking event is an event type (string) and the event type of the given #request is the same.", () => {
const layer = new EventLayer("S3CreateEvent", () => console.log("OK"));
Chai.expect(layer.match(req)).to.be.true;
});

it('should return false if the looking event is an event type (string) and the event type of the given #request is NOT the same.', () => {
const layer = new EventLayer('SNSEvent', () => {})
Chai.expect(layer.match(req)).to.be.false
it("should return false if the looking event is an event type (string) and the event type of the given #request is NOT the same.", () => {
const layer = new EventLayer("SNSEvent", () => console.log("OK"));
Chai.expect(layer.match(req)).to.be.false;
});

it('should return true if the looking event is a predicate (function) and the result of calling that function with the given #request is true.', () => {
const predicate = (req) => req.event.original.Records[0].s3.bucket.arn == 'arn:aws:s3:::example-bucket'
const layer = new EventLayer(predicate, () => {})
Chai.expect(layer.match(req)).to.be.true
it("should return true if the looking event is a predicate (function) and the result of calling that function with the given #request is true.", () => {
const predicate = (request) => req.event.original.Records[0].s3.bucket.arn === "arn:aws:s3:::example-bucket";
const layer = new EventLayer(predicate, () => console.log("OK"));
Chai.expect(layer.match(req)).to.be.true;
});

it('should return false if the looking event is a predicate (function) and the result of calling that function with the given #request is false.', () => {
const predicate = (req) => req.event.original.Records[0].s3.bucket.arn == 'other-bucket'
const layer = new EventLayer(predicate, () => {})
Chai.expect(layer.match(req)).to.be.false
it("should return false if the looking event is a predicate (function) and the result of calling that function with the given #request is false.", () => {
const predicate = (request) => req.event.original.Records[0].s3.bucket.arn === "other-bucket";
const layer = new EventLayer(predicate, () => console.log("OK"));
Chai.expect(layer.match(req)).to.be.false;
});
});

describe('#handle', () => {
it('should call the handler if it exists.', (done) => {
const layer = new EventLayer('S3CreateEvent', () => {
done()
})
describe("#handle", () => {
it("should call the handler if it exists.", (done) => {
const layer = new EventLayer("S3CreateEvent", () => {
done();
});

layer.handle(req, () => {}, null)
layer.handle(req, () => console.log("OK"), null);
});

it('should call #next if the handler does not exist.', (done) => {
const layer = new EventLayer('S3CreateEvent', null)
it("should call #next if the handler does not exist.", (done) => {
const layer = new EventLayer("S3CreateEvent", null);

layer.handle(req, () => {
done()
}, null)
layer.handle(
req,
() => {
done();
},
null
);
});
});

describe('#isErrorHandler', () => {
it('should return true if the handler has 3 arguments as input.', () => {
const layer = new EventLayer('S3CreateEvent', (arg1, arg2, arg3) => {

})
Chai.expect(layer.isErrorHandler()).to.be.true
describe("#isErrorHandler", () => {
it("should return true if the handler has 3 arguments as input.", () => {
const layer = new EventLayer("S3CreateEvent", (arg1, arg2, arg3) => console.log("OK"));
Chai.expect(layer.isErrorHandler()).to.be.true;
});

it('should return false if the handler doesn\'t exist.', () => {
const layer = new EventLayer('S3CreateEvent', null)
Chai.expect(layer.isErrorHandler()).to.be.false
it("should return false if the handler doesn't exist.", () => {
const layer = new EventLayer("S3CreateEvent", null);
Chai.expect(layer.isErrorHandler()).to.be.false;
});

it('should return false if the handler has NOT 3 arguments as input.', () => {
const layer = new EventLayer('S3CreateEvent', (arg1, arg2) => {

})
Chai.expect(layer.isErrorHandler()).to.be.false
it("should return false if the handler has NOT 3 arguments as input.", () => {
const layer = new EventLayer("S3CreateEvent", (arg1, arg2) => console.log("OK"));
Chai.expect(layer.isErrorHandler()).to.be.false;
});
});

Expand Down
11 changes: 6 additions & 5 deletions test/event/EventRequest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Chai from "chai"
import otherEvent from "./../utils/otherEvent";
/* tslint:disable:no-unused-expression */
import * as Chai from "chai";
import EventRequest from "./../../src/lib/event/EventRequest";
import RawEvent from "./../../src/lib/RawEvent";
import EventRequest from "./../../src/lib/event/EventRequest"
import otherEvent from "./../utils/otherEvent";

/**
* Test for EventRequest.
Expand All @@ -10,8 +11,8 @@ describe("EventRequest", () => {

describe("#eventType", () => {
it("should return the type of the raw event.", () => {
const req = new EventRequest(otherEvent)
Chai.expect(req.eventType).to.be.equal("S3CreateEvent")
const req = new EventRequest(otherEvent);
Chai.expect(req.eventType).to.be.equal("S3CreateEvent");
});

describe("#context", () => {
Expand Down
Loading

0 comments on commit fe94953

Please sign in to comment.