|
|
|
@ -38,27 +38,19 @@ describe('BlockedNumberController', () => {
|
|
|
|
|
describe('load', () => {
|
|
|
|
|
it('should load data from the database', async () => {
|
|
|
|
|
const normal = TestUtils.generateFakePubKey();
|
|
|
|
|
const group = TestUtils.generateFakePubKey();
|
|
|
|
|
memoryDB.blocked = [normal.key];
|
|
|
|
|
memoryDB['blocked-groups'] = [group.key];
|
|
|
|
|
await BlockedNumberController.load();
|
|
|
|
|
|
|
|
|
|
const blockedNumbers = BlockedNumberController.getBlockedNumbers();
|
|
|
|
|
const blockedGroups = BlockedNumberController.getBlockedGroups();
|
|
|
|
|
|
|
|
|
|
expect(blockedNumbers).to.have.lengthOf(1);
|
|
|
|
|
expect(blockedNumbers).to.include(normal.key);
|
|
|
|
|
expect(blockedGroups).to.have.lengthOf(1);
|
|
|
|
|
expect(blockedGroups).to.include(group.key);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return empty if nothing in the db exists', async () => {
|
|
|
|
|
await BlockedNumberController.load();
|
|
|
|
|
const blockedNumbers = BlockedNumberController.getBlockedNumbers();
|
|
|
|
|
const blockedGroups = BlockedNumberController.getBlockedGroups();
|
|
|
|
|
|
|
|
|
|
expect(blockedNumbers).to.be.empty;
|
|
|
|
|
expect(blockedGroups).to.be.empty;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -72,7 +64,6 @@ describe('BlockedNumberController', () => {
|
|
|
|
|
expect(blockedNumbers).to.have.lengthOf(1);
|
|
|
|
|
expect(blockedNumbers).to.include(other.key);
|
|
|
|
|
expect(memoryDB.blocked).to.include(other.key);
|
|
|
|
|
expect(BlockedNumberController.getBlockedGroups()).to.be.empty;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -103,52 +94,15 @@ describe('BlockedNumberController', () => {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('blockGroup', () => {
|
|
|
|
|
it('should block a group', async () => {
|
|
|
|
|
const group = TestUtils.generateFakePubKey();
|
|
|
|
|
|
|
|
|
|
await BlockedNumberController.blockGroup(group);
|
|
|
|
|
|
|
|
|
|
const blockedGroups = BlockedNumberController.getBlockedGroups();
|
|
|
|
|
expect(blockedGroups).to.have.lengthOf(1);
|
|
|
|
|
expect(blockedGroups).to.include(group.key);
|
|
|
|
|
expect(memoryDB['blocked-groups']).to.have.lengthOf(1);
|
|
|
|
|
expect(memoryDB['blocked-groups']).to.include(group.key);
|
|
|
|
|
expect(BlockedNumberController.getBlockedNumbers()).to.be.empty;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('unblockGroup', () => {
|
|
|
|
|
it('should unblock a group', async () => {
|
|
|
|
|
const group = TestUtils.generateFakePubKey();
|
|
|
|
|
const another = TestUtils.generateFakePubKey();
|
|
|
|
|
memoryDB['blocked-groups'] = [group.key, another.key];
|
|
|
|
|
|
|
|
|
|
await BlockedNumberController.unblockGroup(group);
|
|
|
|
|
|
|
|
|
|
const blockedGroups = BlockedNumberController.getBlockedGroups();
|
|
|
|
|
expect(blockedGroups).to.have.lengthOf(1);
|
|
|
|
|
expect(blockedGroups).to.include(another.key);
|
|
|
|
|
expect(memoryDB['blocked-groups']).to.have.lengthOf(1);
|
|
|
|
|
expect(memoryDB['blocked-groups']).to.include(another.key);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isBlocked', () => {
|
|
|
|
|
it('should return true if number is blocked', async () => {
|
|
|
|
|
const pubKey = TestUtils.generateFakePubKey();
|
|
|
|
|
const groupPubKey = TestUtils.generateFakePubKey();
|
|
|
|
|
memoryDB.blocked = [pubKey.key];
|
|
|
|
|
memoryDB['blocked-groups'] = [groupPubKey.key];
|
|
|
|
|
await BlockedNumberController.load();
|
|
|
|
|
expect(BlockedNumberController.isBlocked(pubKey.key)).to.equal(
|
|
|
|
|
true,
|
|
|
|
|
'Expected isBlocked to return true for user pubkey'
|
|
|
|
|
);
|
|
|
|
|
expect(BlockedNumberController.isBlocked(groupPubKey.key)).to.equal(
|
|
|
|
|
false,
|
|
|
|
|
'Expected isBlocked to return false for a group pubkey'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return false if number is not blocked', async () => {
|
|
|
|
@ -189,32 +143,4 @@ describe('BlockedNumberController', () => {
|
|
|
|
|
expect(isBlocked).to.equal(false, 'Expected isBlockedAsync to return false.');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isGroupBlocked', () => {
|
|
|
|
|
it('should return true if group is blocked', async () => {
|
|
|
|
|
const pubKey = TestUtils.generateFakePubKey();
|
|
|
|
|
const groupPubKey = TestUtils.generateFakePubKey();
|
|
|
|
|
memoryDB.blocked = [pubKey.key];
|
|
|
|
|
memoryDB['blocked-groups'] = [groupPubKey.key];
|
|
|
|
|
await BlockedNumberController.load();
|
|
|
|
|
expect(BlockedNumberController.isGroupBlocked(pubKey.key)).to.equal(
|
|
|
|
|
false,
|
|
|
|
|
'Expected isGroupBlocked to return false for user pubkey'
|
|
|
|
|
);
|
|
|
|
|
expect(BlockedNumberController.isGroupBlocked(groupPubKey.key)).to.equal(
|
|
|
|
|
true,
|
|
|
|
|
'Expected isGroupBlocked to return true for a group pubkey'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return false if group is not blocked', async () => {
|
|
|
|
|
const groupPubKey = TestUtils.generateFakePubKey();
|
|
|
|
|
memoryDB['blocked-groups'] = [];
|
|
|
|
|
await BlockedNumberController.load();
|
|
|
|
|
expect(BlockedNumberController.isGroupBlocked(groupPubKey.key)).to.equal(
|
|
|
|
|
false,
|
|
|
|
|
'Expected isGroupBlocked to return false'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|