Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Add lairMetaRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
onechiporenko committed Jan 16, 2018
1 parent fa6867f commit 1b6fb13
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
9 changes: 9 additions & 0 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class Server {
public port = 54321;
public verbose = true;
public delay = 0;
public lairMetaRoute = '/lair/meta';

public get server(): http.Server {
return this.internalServer;
Expand Down Expand Up @@ -75,10 +76,18 @@ export default class Server {
clbs.map(clb => this.addMiddleware(clb));
}

public addLairMetaRoute() {
if (!this.lairMetaRoute) {
return;
}
this.expressApp.get(this.lairMetaRoute, (req, res) => res.json(this.lair.getDevInfo()));
}

public startServer(clb?: () => any) {
this.lair.verbose = this.verbose;
this.fillLair();
this.useMiddlewares();
this.addLairMetaRoute();
this.expressApp.use(this.namespace, this.expressRouter);
this.printRoutesMap();
this.internalServer = this.expressApp.listen(this.port, () => clb ? clb() : null);
Expand Down
12 changes: 3 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swarm-host",
"version": "1.0.0",
"version": "1.0.2",
"description": "fake-server",
"main": "dist/index.js",
"scripts": {
Expand Down
44 changes: 44 additions & 0 deletions tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ describe('#Server', () => {
});
});

describe('#lairMetaRoute', () => {
it('should have default value', () => {
expect(Server.getServer().lairMetaRoute).to.be.equal('/lair/meta');
});
});

describe('#addFactory', () => {
it('should register factory in the Lair', () => {
expect(this.lair.getDevInfo()).to.be.eql({});
Expand Down Expand Up @@ -201,4 +207,42 @@ describe('#Server integration', () => {
});
});

describe('#lairMetaRoute', () => {
it('should return lair meta info', done => {
this.server.addFactory(modelA, 'a');
this.server.addFactory(modelA, 'b');
this.server.createRecords('a', 2);
this.server.createRecords('b', 3);
this.server.startServer(() => chai.request(this.server.server)
.get('/lair/meta')
.end((err, res) => {
expect(res.body).to.be.eql({
a: {
count: 2,
id: 3,
meta: {
name: {
defaultValue: 'test',
type: 1,
value: 'test',
},
},
},
b: {
count: 3,
id: 4,
meta: {
name: {
defaultValue: 'test',
type: 1,
value: 'test',
},
},
},
});
done();
}));
});
});

});

0 comments on commit 1b6fb13

Please sign in to comment.