Skip to content

Commit 3ab83a5

Browse files
committed
include tests and code to list all groups
1 parent 788487d commit 3ab83a5

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

lib/level-storage.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,20 @@ LevelStorage.prototype.listEntitiesByEntityType = function (entity_type) {
511511

512512
};
513513

514+
LevelStorage.prototype.listGroups = function () {
515+
console.log("arguments for listEntitiesGroups leveldb " + JSON.stringify(arguments));
516+
517+
function keyAction(entity_type, key) {
518+
return true;
519+
}
520+
521+
function dataAction(value) {
522+
return true;
523+
}
524+
return iterateDbAndSearch("groups", keyAction.bind(this), dataAction.bind(this), transaction(this.groups), true);
525+
526+
};
527+
514528
LevelStorage.prototype.listEntitiesByGroup = function (group_name, owner) {
515529
console.log("arguments for listEntitiesByGroupId leveldb " + JSON.stringify(arguments));
516530
var that = this;

lib/storage.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ Storage.prototype.listEntitiesByEntityType = function (entity_type) {
6969
return promise;
7070
};
7171

72+
Storage.prototype.listGroups = function () {
73+
var conf = this.conf;
74+
var promise = new Promise(function (resolve, reject) {
75+
connectionPoolPromisse(conf).then(function (storage) {
76+
//console.log(attribute_type + attribute_value +''+storage.listEntitiesByAttributeValueAndType)
77+
storage.listGroups().then(resolve, reject);
78+
}, handleFail.bind(this, reject));
79+
});
80+
return promise;
81+
};
82+
7283
Storage.prototype.listEntitiesByAttributeValueAndType = function (attribute_constraints, entity_type) {
7384
var conf = this.conf;
7485
var promise = new Promise(function (resolve, reject) {

tests/level-storage-test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,48 @@ describe('LevelStorage', function () {
10001000

10011001
});
10021002

1003+
describe('#List Groups', function () {
1004+
1005+
it('should resolve with an empty array when there are no groups', function (done) {
1006+
var storage = createLevelStorage();
1007+
1008+
storage.listGroups()
1009+
.then(function (result) {
1010+
if (result.length === 0) {
1011+
storage.cleanDb(done);
1012+
}
1013+
}, function reject(error) {
1014+
throw Error("should not fail but return an empty array");
1015+
1016+
});
1017+
});
1018+
it('should return all groups', function (done) {
1019+
var storage = createLevelStorage();
1020+
var owner = "1";
1021+
var group1;
1022+
var group2;
1023+
var group_name = "mygroup";
1024+
var group_name2 = "mygroup2";
1025+
Promise.all([storage.createGroupPromise(group_name, owner), storage.createGroupPromise(group_name2, owner)])
1026+
.then(function (array) {
1027+
return storage.listGroups();
1028+
})
1029+
.then(function (groups) {
1030+
if (groups[0].owner === owner && groups[1].owner === owner) {
1031+
var b = true;
1032+
groups.forEach(function (v) {
1033+
b = b && (v.group_name === group_name || v.group_name === group_name2);
1034+
})
1035+
if (b)
1036+
storage.cleanDb(done);
1037+
}
1038+
1039+
}, function reject(error) {
1040+
throw error;
1041+
});
1042+
});
1043+
});
1044+
10031045
describe('#List entities in a Group', function () {
10041046
//called after each test to delete the database
10051047
afterEach(function () {

0 commit comments

Comments
 (0)