2019-05-08 15:45:37 +00:00
|
|
|
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
|
|
|
|
// Node module: loopback-datasource-juggler
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2017-01-06 03:32:41 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bdd = require('../helpers/bdd-if');
|
|
|
|
const helpers = require('./_helpers');
|
|
|
|
const should = require('should');
|
|
|
|
|
|
|
|
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
2018-12-07 14:54:29 +00:00
|
|
|
const supportsDeleteAll = 'deleteAll' in dataSourceFactory().connector;
|
2017-01-06 03:32:41 +00:00
|
|
|
|
2017-01-10 08:18:04 +00:00
|
|
|
bdd.describeIf(supportsDeleteAll, 'deleteAll', () => {
|
2017-01-06 03:32:41 +00:00
|
|
|
let CacheItem;
|
2017-01-10 08:18:04 +00:00
|
|
|
beforeEach(setupCacheItem);
|
2017-01-06 03:32:41 +00:00
|
|
|
|
2017-01-10 08:18:04 +00:00
|
|
|
it('removes all key-value pairs for the given model', () => {
|
2017-01-06 03:32:41 +00:00
|
|
|
return helpers.givenKeys(CacheItem, ['key1', 'key2'])
|
|
|
|
.then(() => CacheItem.deleteAll())
|
|
|
|
.then(() => CacheItem.keys())
|
2017-01-10 08:18:04 +00:00
|
|
|
.then(keys => should(keys).eql([]));
|
2017-01-06 03:32:41 +00:00
|
|
|
});
|
|
|
|
|
2017-01-10 08:18:04 +00:00
|
|
|
it('does not remove data from other existing models', () => {
|
|
|
|
let AnotherModel;
|
2017-01-13 08:19:10 +00:00
|
|
|
return helpers.givenModel(dataSourceFactory, 'AnotherModel')
|
2017-01-10 08:18:04 +00:00
|
|
|
.then(ModelCtor => AnotherModel = ModelCtor)
|
|
|
|
.then(() => helpers.givenKeys(CacheItem, ['key1', 'key2']))
|
2017-01-06 03:32:41 +00:00
|
|
|
.then(() => helpers.givenKeys(AnotherModel, ['key3', 'key4']))
|
|
|
|
.then(() => CacheItem.deleteAll())
|
|
|
|
.then(() => AnotherModel.keys())
|
2017-01-10 08:18:04 +00:00
|
|
|
.then(keys => should(keys.sort()).eql(['key3', 'key4']));
|
2017-01-06 03:32:41 +00:00
|
|
|
});
|
2017-01-10 08:18:04 +00:00
|
|
|
|
|
|
|
function setupCacheItem() {
|
|
|
|
return helpers.givenCacheItem(dataSourceFactory)
|
|
|
|
.then(ModelCtor => CacheItem = ModelCtor);
|
|
|
|
}
|
2017-01-06 03:32:41 +00:00
|
|
|
});
|
|
|
|
};
|