59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
|
import chai from "chai";
|
||
|
import sinon from "ts-sinon";
|
||
|
import sinonChai from "sinon-chai";
|
||
|
|
||
|
chai.use(sinonChai)
|
||
|
const expect = chai.expect;
|
||
|
|
||
|
import { withFile } from "tmp-promise"
|
||
|
import { writeFileSync } from "fs";
|
||
|
|
||
|
import { Router } from "../src/index";
|
||
|
|
||
|
|
||
|
const path = require("path");
|
||
|
const well_build_routing_file: Router.Config = require(path.join(__dirname, "rsrc/wellBuildedRoutingFile.json"));
|
||
|
|
||
|
describe("testing the routing part", function () {
|
||
|
describe("testing the building part", function () {
|
||
|
it("it will test the constructor with a well format config file", function () {
|
||
|
//given
|
||
|
const fun = () => {
|
||
|
const r = new Router(path.join(__dirname, "rsrc/wellBuildedRoutingFile.json"));
|
||
|
};
|
||
|
const spy = sinon.spy(fun);
|
||
|
// when
|
||
|
try {
|
||
|
spy();
|
||
|
} catch (error) {
|
||
|
// nothing it's a test
|
||
|
}
|
||
|
|
||
|
// assert
|
||
|
expect(spy).to.not.thrown();
|
||
|
})
|
||
|
|
||
|
it("it will test a bad formed file", async function () {
|
||
|
await withFile(async (file) => {
|
||
|
//given
|
||
|
writeFileSync(file.path, JSON.stringify({...well_build_routing_file, ...{events: 12}}));
|
||
|
const fun = () => {
|
||
|
const r = new Router(file.path);
|
||
|
console.log(r.config);
|
||
|
|
||
|
};
|
||
|
const spy = sinon.spy(fun);
|
||
|
|
||
|
// when
|
||
|
try {
|
||
|
spy();
|
||
|
} catch (error) {
|
||
|
// nothing it's a test
|
||
|
}
|
||
|
|
||
|
// assert
|
||
|
expect(spy).to.not.thrown();
|
||
|
}, {postfix: ".json"});
|
||
|
})
|
||
|
})
|
||
|
});
|