IGNITE-3262 Review.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a48f8f27 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a48f8f27 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a48f8f27 Branch: refs/heads/ignite-3262 Commit: a48f8f27f5e6d0e7463c1d1bd5d7f01cc72856b3 Parents: c6fdd00 Author: Andrey Novikov <[email protected]> Authored: Fri Jul 1 11:17:18 2016 +0700 Committer: Andrey Novikov <[email protected]> Committed: Fri Jul 1 11:17:18 2016 +0700 ---------------------------------------------------------------------- .../src/main/js/serve/services/cache.js | 17 ++- .../src/main/js/serve/services/space.js | 4 +- .../js/test/backend/unit/CacheService.test.js | 120 ++++++++++--------- .../src/main/js/test/unit/JavaTypes.test.js | 2 +- 4 files changed, 72 insertions(+), 71 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/a48f8f27/modules/web-console/src/main/js/serve/services/cache.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/serve/services/cache.js b/modules/web-console/src/main/js/serve/services/cache.js index 94a85ad..b296fe4 100644 --- a/modules/web-console/src/main/js/serve/services/cache.js +++ b/modules/web-console/src/main/js/serve/services/cache.js @@ -21,10 +21,7 @@ module.exports = { implements: 'services/cache', - inject: ['require(lodash)', - 'mongo', - 'services/space', - 'errors'] + inject: ['require(lodash)', 'mongo', 'services/space', 'errors'] }; module.exports.factory = (_, mongo, spaceService, errors) => { @@ -37,7 +34,7 @@ module.exports.factory = (_, mongo, spaceService, errors) => { /** * Update existing cache * @param {Object} cache - The cache for updating - * @returns {Promise.<Integer>} that resolves cache id + * @returns {Promise.<Number>} that resolves cache id */ const update = (cache) => { const cacheId = cache._id; @@ -53,7 +50,7 @@ module.exports.factory = (_, mongo, spaceService, errors) => { /** * Create new cache. * @param {Object} cache - The cache for creation. - * @returns {Promise.<Integer>} that resolves cache id. + * @returns {Promise.<Number>} that resolves cache id. */ const create = (cache) => { return mongo.Cache.create(cache) @@ -70,8 +67,8 @@ module.exports.factory = (_, mongo, spaceService, errors) => { /** * Remove all caches by space ids. - * @param {Integer[]} spaceIds - The space ids for cache deletion. - * @returns {Promise.<Integer>} that resolves number of affected rows. + * @param {Number[]} spaceIds - The space ids for cache deletion. + * @returns {Promise.<Number>} that resolves number of affected rows. */ const removeAllBySpaces = (spaceIds) => { return mongo.Cluster.update({space: {$in: spaceIds}}, {caches: []}, {multi: true}).exec() @@ -86,7 +83,7 @@ module.exports.factory = (_, mongo, spaceService, errors) => { /** * Create or update cache. * @param {Object} cache - The cache. - * @returns {Promise.<Integer>} that resolves cache id of merge operation. + * @returns {Promise.<Number>} that resolves cache id of merge operation. */ static merge(cache) { if (cache._id) @@ -122,7 +119,7 @@ module.exports.factory = (_, mongo, spaceService, errors) => { * @returns {Promise.<{rowsAffected}>} - The number of affected rows. */ static remove(cacheId) { - if(!cacheId) + if (!cacheId) throw new errors.IllegalArgumentException('Cache id can not be undefined or null'); return mongo.Cluster.update({caches: {$in: [cacheId]}}, {$pull: {caches: cacheId}}, {multi: true}).exec() http://git-wip-us.apache.org/repos/asf/ignite/blob/a48f8f27/modules/web-console/src/main/js/serve/services/space.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/serve/services/space.js b/modules/web-console/src/main/js/serve/services/space.js index eb37858..28a8897 100644 --- a/modules/web-console/src/main/js/serve/services/space.js +++ b/modules/web-console/src/main/js/serve/services/space.js @@ -25,7 +25,6 @@ module.exports = { }; module.exports.factory = (mongo, errors) => { - class SpaceService { /** * Query for user spaces. @@ -38,7 +37,7 @@ module.exports.factory = (mongo, errors) => { return mongo.Space.find({owner: userId, demo: !!demo}).lean().exec() .then((spaces) => { if (!spaces.length) - throw new errors.NotFoundException('Spaces not found'); + throw new errors.NotFoundException('Failed to find space'); return spaces; }); @@ -55,7 +54,6 @@ module.exports.factory = (mongo, errors) => { return this.spaces(userId, demo) .then((spaces) => spaces.map((space) => space._id)); } - } return SpaceService; http://git-wip-us.apache.org/repos/asf/ignite/blob/a48f8f27/modules/web-console/src/main/js/test/backend/unit/CacheService.test.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/test/backend/unit/CacheService.test.js b/modules/web-console/src/main/js/test/backend/unit/CacheService.test.js index d75c72a..2764dad 100644 --- a/modules/web-console/src/main/js/test/backend/unit/CacheService.test.js +++ b/modules/web-console/src/main/js/test/backend/unit/CacheService.test.js @@ -25,25 +25,23 @@ let cacheService; let mongo; let errors; -suite('CacheService', () => { - +suite('CacheServiceTestsSuite', () => { const prepareUserSpaces = () => { return mongo.Account.create(testAccounts) .then((accounts) => { - return Promise.all(accounts.map((account)=> { - return mongo.Space.create([ + return Promise.all(accounts.map((account) => mongo.Space.create([ {name: 'Personal space', owner: account._id, demo: false}, {name: 'Demo space', owner: account._id, demo: true} ]) - })) - .then((spaces)=> { - return [accounts, spaces]; - }); + )) + .then((spaces) => [accounts, spaces]); }); }; suiteSetup(() => { - return Promise.all([fireUp('services/cache'), fireUp('mongo'), fireUp('errors')]) + return Promise.all([fireUp('services/cache'), + fireUp('mongo'), + fireUp('errors')]) .then(([_cacheService, _mongo, _errors]) => { mongo = _mongo; cacheService = _cacheService; @@ -59,99 +57,98 @@ suite('CacheService', () => { ]); }); - test('Cache merge.', (done) => { + test('Create new cache', (done) => { cacheService.merge(testCaches[0]) .then((cacheId) => { assert.isNotNull(cacheId); return cacheId; }) - .then((cacheId) => { - return mongo.Cache.findById(cacheId) - .then((cache) => { - assert.isNotNull(cache); - }) + .then((cacheId) => mongo.Cache.findById(cacheId)) + .then((cache) => { + assert.isNotNull(cache); }) .then(done) .catch(done); }); - test('Try to save same cache twice.', (done) => { - cacheService.merge(testCaches[0]) - .then(() => cacheService.merge(testCaches[0])) - .catch((err) => { - assert.instanceOf(err, errors.DuplicateKeyException); - done(); - }); - }); + test('Update existed cache', (done) => { + const newName = 'NewUniqueName'; - test('Try to update cache.', (done) => { cacheService.merge(testCaches[0]) .then((cacheId) => { - const cacheBeforeMerge = {...testCaches[0], _id: cacheId}; - cacheBeforeMerge.name = 'NewUniqueName'; + const cacheBeforeMerge = {...testCaches[0], _id: cacheId, name: newName}; - return cacheService.merge(cacheBeforeMerge) - .then((cacheId) => { - return mongo.Cache.findById(cacheId) - .then((cacheAfterMerge) => { - assert.equal(cacheBeforeMerge.name, cacheAfterMerge.name); - }) - .then(done); - }); + return cacheService.merge(cacheBeforeMerge); + }) + .then((cacheId) => mongo.Cache.findById(cacheId)) + .then((cacheAfterMerge) => { + assert.equal(newName, cacheAfterMerge.name); }) + .then(done) .catch(done); }); + test('Create duplicated cache', (done) => { + cacheService.merge(testCaches[0]) + .then(() => cacheService.merge(testCaches[0])) + .catch((err) => { + assert.instanceOf(err, errors.DuplicateKeyException); + + done(); + }); + }); - test('Remove cache.', (done) => { + test('Remove existed cache', (done) => { cacheService.merge(testCaches[0]) .then((cacheId) => { return mongo.Cache.findById(cacheId) .then((cache) => cache._id) .then(cacheService.remove) - .then((results) => { - assert.equal(results.rowsAffected, 1); - - return mongo.Cache.findById(cacheId) - .then((notFoundCache) => { - assert.isNull(notFoundCache); - }); + .then(({rowsAffected}) => { + assert.equal(rowsAffected, 1); + }) + .then(() => mongo.Cache.findById(cacheId)) + .then((notFoundCache) => { + assert.isNull(notFoundCache); }); }) .then(done) .catch(done); }); - test('Remove null cache must be throw exception.', (done) => { + test('Remove missed cache', (done) => { cacheService.merge(testCaches[0]) - .then(()=> cacheService.remove()) + .then(() => cacheService.remove()) .catch((err) => { assert.instanceOf(err, errors.IllegalArgumentException); + done(); - }) + }); }); + test('Remove cache without identifier', (done) => { + // TODO IGNITE-3262 Add test. + done(); + }); - test('Remove all caches by user.', (done) => { + test('Remove all caches in space', (done) => { prepareUserSpaces() .then(([accounts, spaces]) => { const currentUser = accounts[0]; const userCache = {...testCaches[0], space: spaces[0][0]._id}; return cacheService.merge(userCache) - .then(() => { - return cacheService.removeAll(currentUser._id, false) - .then(({rowsAffected})=> { - assert.equal(rowsAffected, 1); - }) - }); + .then(() => cacheService.removeAll(currentUser._id, false)); + }) + .then(({rowsAffected}) => { + assert.equal(rowsAffected, 1); }) .then(done) .catch(done); }); - test('Load all caches by space.', (done) => { + test('Get all caches by space', (done) => { prepareUserSpaces() .then(([accounts, spaces]) => { const currentUser = accounts[0]; @@ -170,9 +167,18 @@ suite('CacheService', () => { .catch(done); }); - // TODO - // test('Test link entities on merge', () => {}) + test('Update linked entities on update cache', (done) => { + // TODO IGNITE-3262 Add test. + done(); + }); + + test('Update linked entities on remove cache', (done) => { + // TODO IGNITE-3262 Add test. + done(); + }); - // TODO - // test('Test link entities on remove', () => {}) + test('Update linked entities on remove all caches in space', (done) => { + // TODO IGNITE-3262 Add test. + done(); + }); }); http://git-wip-us.apache.org/repos/asf/ignite/blob/a48f8f27/modules/web-console/src/main/js/test/unit/JavaTypes.test.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/test/unit/JavaTypes.test.js b/modules/web-console/src/main/js/test/unit/JavaTypes.test.js index c6f459d..ebb0560 100644 --- a/modules/web-console/src/main/js/test/unit/JavaTypes.test.js +++ b/modules/web-console/src/main/js/test/unit/JavaTypes.test.js @@ -21,7 +21,7 @@ import { assert } from 'chai'; const { nonBuiltInClass, fullClassName, validIdentifier, validPackage, packageSpecified, isKeywords, isJavaPrimitive} = JavaTypes[1](); -describe('JavaTypes Service Test', () => { +describe('JavaTypesTestsSuite', () => { describe('nonBuiltInClass', () => { it('BigDecimal', () => { assert.equal(nonBuiltInClass('BigDecimal'), false);
