|
|
@ -1753,4 +1753,114 @@ describe('User', function () {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('user blocking methods', function (done) {
|
|
|
|
|
|
|
|
let blockeeUid;
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
|
|
|
|
User.create({
|
|
|
|
|
|
|
|
username: 'blockee',
|
|
|
|
|
|
|
|
email: 'blockee@example.org',
|
|
|
|
|
|
|
|
fullname: 'Block me',
|
|
|
|
|
|
|
|
}, function (err, uid) {
|
|
|
|
|
|
|
|
blockeeUid = uid;
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('.remove()', function () {
|
|
|
|
|
|
|
|
it('should unblock a uid', function (done) {
|
|
|
|
|
|
|
|
User.blocks.remove(blockeeUid, 1, function (err, blocked_uids) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.strictEqual(Array.isArray(blocked_uids), true);
|
|
|
|
|
|
|
|
assert.strictEqual(blocked_uids.length, 0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('.add()', function () {
|
|
|
|
|
|
|
|
it('should block a uid', function (done) {
|
|
|
|
|
|
|
|
User.blocks.add(blockeeUid, 1, function (err, blocked_uids) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.strictEqual(Array.isArray(blocked_uids), true);
|
|
|
|
|
|
|
|
assert.strictEqual(blocked_uids.length, 1);
|
|
|
|
|
|
|
|
assert.strictEqual(blocked_uids.includes(blockeeUid), true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('.list()', function () {
|
|
|
|
|
|
|
|
it('should return a list of blocked uids', function (done) {
|
|
|
|
|
|
|
|
User.blocks.list(1, function (err, blocked_uids) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.strictEqual(Array.isArray(blocked_uids), true);
|
|
|
|
|
|
|
|
assert.strictEqual(blocked_uids.length, 1);
|
|
|
|
|
|
|
|
assert.strictEqual(blocked_uids.includes(blockeeUid), true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('.filter()', function () {
|
|
|
|
|
|
|
|
it('should remove entries by blocked uids and return filtered set', function (done) {
|
|
|
|
|
|
|
|
User.blocks.filter(1, [{
|
|
|
|
|
|
|
|
foo: 'foo',
|
|
|
|
|
|
|
|
uid: blockeeUid,
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
foo: 'bar',
|
|
|
|
|
|
|
|
uid: 1,
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
foo: 'baz',
|
|
|
|
|
|
|
|
uid: blockeeUid,
|
|
|
|
|
|
|
|
}], function (err, filtered) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.strictEqual(Array.isArray(filtered), true);
|
|
|
|
|
|
|
|
assert.strictEqual(filtered.length, 1);
|
|
|
|
|
|
|
|
assert.equal(filtered[0].uid, 1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should allow property argument to be passed in to customise checked property', function (done) {
|
|
|
|
|
|
|
|
User.blocks.filter(1, 'fromuid', [{
|
|
|
|
|
|
|
|
foo: 'foo',
|
|
|
|
|
|
|
|
fromuid: blockeeUid,
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
foo: 'bar',
|
|
|
|
|
|
|
|
fromuid: 1,
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
foo: 'baz',
|
|
|
|
|
|
|
|
fromuid: blockeeUid,
|
|
|
|
|
|
|
|
}], function (err, filtered) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.strictEqual(Array.isArray(filtered), true);
|
|
|
|
|
|
|
|
assert.strictEqual(filtered.length, 1);
|
|
|
|
|
|
|
|
assert.equal(filtered[0].fromuid, 1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should not process invalid sets', function (done) {
|
|
|
|
|
|
|
|
User.blocks.filter(1, [{ foo: 'foo' }, { foo: 'bar' }, { foo: 'baz' }], function (err, filtered) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.strictEqual(Array.isArray(filtered), true);
|
|
|
|
|
|
|
|
assert.strictEqual(filtered.length, 3);
|
|
|
|
|
|
|
|
filtered.forEach(function (obj) {
|
|
|
|
|
|
|
|
assert.strictEqual(obj.hasOwnProperty('foo'), true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should process plain sets that just contain uids', function (done) {
|
|
|
|
|
|
|
|
User.blocks.filter(1, [1, blockeeUid], function (err, filtered) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.strictEqual(filtered.length, 1);
|
|
|
|
|
|
|
|
assert.strictEqual(filtered[0], 1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|