Skip to content

Commit bd1ebf4

Browse files
Merge pull request #1 from codefresh-io/endpoints-generation
endpoints generation
2 parents e183e24 + f325c5d commit bd1ebf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3331
-86
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
'plugins': [
3-
'mocha'
3+
'jest'
44
],
55
'extends': 'airbnb-base',
66
'rules': {
@@ -15,6 +15,6 @@ module.exports = {
1515
'class-methods-use-this': 0
1616
},
1717
'env': {
18-
'mocha': true,
18+
'jest': true,
1919
}
2020
};

__tests__/__app__/events-interface.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class EventsInterface {
2+
constructor() {
3+
this.callback = null;
4+
this.subscribeCalls = 0;
5+
this.publishCalls = 0;
6+
this.subscribe = this.subscribe.bind(this);
7+
this.publish = this.publish.bind(this);
8+
}
9+
10+
subscribe(callback) {
11+
this.subscribeCalls = this.subscribeCalls + 1;
12+
this.callback = callback;
13+
}
14+
15+
publish(data) {
16+
this.publishCalls = this.publishCalls + 1;
17+
return this.callback(data);
18+
}
19+
}
20+
21+
module.exports = new EventsInterface();

__tests__/__app__/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
const express = require('express');
3+
const Promise = require('bluebird');
4+
5+
const config = require('./service.config');
6+
const { openapi } = require('../../index');
7+
const globalMiddleware = require('./server/global.middleware');
8+
const eventsInterface = require('./events-interface');
9+
10+
class App {
11+
constructor() {
12+
this.server = null;
13+
this.port = null;
14+
this.app = express();
15+
}
16+
17+
async start() {
18+
const deferred = Promise.defer();
19+
openapi.init(config);
20+
openapi.events().setSubscribeInterface(eventsInterface.subscribe);
21+
openapi.events().setPublishInterface(eventsInterface.publish);
22+
openapi.endpoints().addSpecMiddleware(globalMiddleware.specMiddleware);
23+
openapi.endpoints().addDependenciesSpecMiddleware(globalMiddleware.dependenciesSpecMiddleware);
24+
openapi.endpoints().register(this.app);
25+
openapi.dependencies().fetch();
26+
this.server = this.app.listen(0, () => {
27+
openapi.events().subscribe();
28+
openapi.events().publish();
29+
deferred.resolve();
30+
});
31+
this.port = this.server.address().port;
32+
return deferred.promise;
33+
}
34+
35+
async stop() {
36+
this.server.close();
37+
}
38+
}
39+
40+
module.exports = new App();

0 commit comments

Comments
 (0)