Skip to content

Commit

Permalink
Removed version.json file, api version is now set by package.json.
Browse files Browse the repository at this point in the history
Updated bookmarks routes so that latest route always applies to current minor/patch version.
  • Loading branch information
nero120 committed Jul 15, 2018
1 parent d4ff170 commit fa9ea3d
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 38 deletions.
3 changes: 0 additions & 3 deletions config/version.json

This file was deleted.

5 changes: 2 additions & 3 deletions dist/core/config.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/core/config.js.map

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

8 changes: 5 additions & 3 deletions dist/routers/bookmarks.router.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/routers/bookmarks.router.js.map

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
@@ -1,7 +1,7 @@
{
"name": "xbrowsersync-api",
"description": "The REST API service component of the xBrowserSync application.",
"version": "1.1.3",
"version": "1.1.4",
"author": "xBrowserSync",
"license": "MIT",
"main": "dist/api.js",
Expand Down
5 changes: 2 additions & 3 deletions src/core/config.ts
Expand Up @@ -26,12 +26,11 @@ export default class Config {
const settings = merge(defaultSettings, userSettings);

// Get current version number
const pathToVersion = path.join(pathToConfig, 'version.json');
const version = require(pathToVersion);
const { version } = require('../../package.json');

this.config = {
...settings,
...version
version
};

return this.config;
Expand Down
8 changes: 5 additions & 3 deletions src/routers/bookmarks.router.ts
Expand Up @@ -14,15 +14,17 @@ export default class BookmarksRouter extends BaseRouter<BookmarksService> implem
this.app.use('/bookmarks', this.router);
this.createRoute(ApiVerb.post, '/', {
'~1.0.0': this.createBookmarks_v1,
'~1.1.3': this.createBookmarks_v2
// tslint:disable-next-line:object-literal-sort-keys
'^1.1.3': this.createBookmarks_v2
});
this.createRoute(ApiVerb.get, '/:id', { '^1.0.0': this.getBookmarks });
this.createRoute(ApiVerb.put, '/:id', {
'~1.0.0': this.updateBookmarks_v1,
'~1.1.3': this.updateBookmarks_v2
// tslint:disable-next-line:object-literal-sort-keys
'^1.1.3': this.updateBookmarks_v2
});
this.createRoute(ApiVerb.get, '/:id/lastUpdated', { '^1.0.0': this.getLastUpdated });
this.createRoute(ApiVerb.get, '/:id/version', { '~1.1.3': this.getVersion });
this.createRoute(ApiVerb.get, '/:id/version', { '^1.1.3': this.getVersion });
}

// Creates a new bookmarks sync and returns new sync ID
Expand Down
6 changes: 3 additions & 3 deletions test/integration/bookmarks.test.ts
Expand Up @@ -29,10 +29,11 @@ describe('BookmarksRouter', () => {
let testConfig: any;

beforeEach(async () => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
};
version
};
testConfig.db.name = `${testConfig.db.name}test`;
testConfig.log.enabled = false;
sandbox = sinon.createSandbox();
Expand All @@ -51,7 +52,6 @@ describe('BookmarksRouter', () => {
await server.stop();
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('POST /bookmarks should return a NewSyncsForbiddenException error code if new syncs are not allowed', async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/docs.test.ts
Expand Up @@ -17,10 +17,11 @@ describe('Docs', () => {
let testConfig: any;

beforeEach(async () => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
};
version
};
testConfig.db.name = `${testConfig.db.name}test`;
testConfig.log.enabled = false;
sandbox = sinon.createSandbox();
Expand All @@ -36,7 +37,6 @@ describe('Docs', () => {
await server.stop();
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('GET /: Should return a 200 code', async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/info.test.ts
Expand Up @@ -17,10 +17,11 @@ describe('InfoRouter', () => {
let testConfig: any;

beforeEach(async () => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
};
version
};
testConfig.db.name = `${testConfig.db.name}test`;
testConfig.log.enabled = false;
sandbox = sinon.createSandbox();
Expand All @@ -36,7 +37,6 @@ describe('InfoRouter', () => {
await server.stop();
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('GET info: should return api status info', async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/server.test.ts
Expand Up @@ -29,10 +29,11 @@ describe('Server', () => {
let testConfig: any;

beforeEach(async () => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
};
version
};
testConfig.db.name = `${testConfig.db.name}test`;
testConfig.log.enabled = false;
sandbox = sinon.createSandbox();
Expand All @@ -48,7 +49,6 @@ describe('Server', () => {
await server.stop();
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('Should return a NotImplementedException error code for an invalid route', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/bookmarks.service.test.ts
Expand Up @@ -25,9 +25,10 @@ describe('BookmarksService', () => {
let testConfig: any;

beforeEach(() => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
version
};
const log = () => { };
newSyncLogsService = new NewSyncLogsService(null, log);
Expand All @@ -40,7 +41,6 @@ describe('BookmarksService', () => {
afterEach(() => {
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('createBookmarks: should throw a NewSyncsForbiddenException if service is not accepting new syncs', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/info.service.test.ts
Expand Up @@ -16,9 +16,10 @@ describe('InfoService', () => {
let testConfig: any;

beforeEach(() => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
version
};
const log = () => { };
bookmarksService = new BookmarksService(null, log);
Expand All @@ -31,7 +32,6 @@ describe('InfoService', () => {
afterEach(() => {
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('getInfo: should return max sync size config value', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/newSyncLogs.service.test.ts
Expand Up @@ -16,9 +16,10 @@ describe('NewSyncLogsService', () => {
let testConfig: any;

beforeEach(() => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
version
};
const log = () => { };
newSyncLogsService = new NewSyncLogsService(null, log);
Expand All @@ -29,7 +30,6 @@ describe('NewSyncLogsService', () => {
afterEach(() => {
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('createLog: should create a new sync log using the request IP address', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/server.test.ts
Expand Up @@ -12,9 +12,10 @@ describe('Server', () => {
let testConfig: any;

beforeEach(() => {
const { version } = require('../../package.json');
testConfig = {
...require('../../config/settings.default.json'),
...require('../../config/version.json')
version
};
sandbox = sinon.createSandbox();
sandbox.stub(Config, 'get').returns(testConfig);
Expand All @@ -23,7 +24,6 @@ describe('Server', () => {
afterEach(() => {
sandbox.restore();
decache('../../config/settings.default.json');
decache('../../config/version.json');
});

it('checkServiceAvailability: should not throw an error when status set as online in config settings', done => {
Expand Down

0 comments on commit fa9ea3d

Please sign in to comment.