// helper function to allow user logout var removeAudienceMember = function(id) { var member = _.findWhere(audience, { id : id }); if (member) { audience.splice(audience.indexOf(member), 1); io.sockets.emit('audience', audience); console.log('Left: %s (%s audience members)', member.name, audience.length); } }
test('findWhere', function() { var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 4}]; var result = _.findWhere(list, {a: 1}); deepEqual(result, {a: 1, b: 2}); result = _.findWhere(list, {b: 4}); deepEqual(result, {a: 1, b: 4}); result = _.findWhere(list, {c:1}) ok(_.isUndefined(result), "undefined when not found"); result = _.findWhere([], {c:1}); ok(_.isUndefined(result), "undefined when searching empty list"); });
testRingpop({async: true}, 'self evict completes when membership is empty', function t(deps, assert, cleanup) { var ringpop = deps.ringpop; var selfEvict = new SelfEvict(ringpop); selfEvict.initiate(function afterSelfEvict(err){ assert.notOk(err); var evictingPhase = _.findWhere(selfEvict.phases, {phase: SelfEvict.PhaseNames.Evicting}); assert.equal(evictingPhase.numberOfPings, 0, 'number of pings is correct'); assert.equal(evictingPhase.numberOfSuccessfulPings, 0, 'successful pings is correct'); cleanup(); }); });
describe('Get Transactions', function() { var dispute, transactions; before(function(done){ dispute = _.findWhere(disputes, {DisputeType: 'NOT_CONTESTABLE'}); if (!dispute) { console.warn('Cannot test getting transactions for dispute because there\'s no not costestable disputes in the disputes list.'); this.skip(); } api.Disputes.getTransactions(dispute.Id, function(data, response){ transactions = data; done(); }); }); it('should be retrieved', function(){ expect(transactions.length).to.be.above(0); }); });
testRingpop({async: true}, 'self evict does not ping more than number of members', function t(deps, assert, cleanup) { var ringpop = deps.ringpop; ringpop.config.set('selfEvictionMaxPingRatio', 2.0); //set above 1 on purpose ringpop.membership.makeChange('127.0.0.1:30002', Date.now(), Member.Status.alive); ringpop.membership.makeChange('127.0.0.1:30003', Date.now(), Member.Status.alive); assert.plan(3); var numberOfPings = 0; ringpop.client = { protocolPing: function(opts, body, cb) { numberOfPings++; cb(null, {changes: []}); }, destroy: function noop() { } }; var selfEvict = new SelfEvict(ringpop); selfEvict.initiate(function afterEvict() { var evictingPhase = _.findWhere(selfEvict.phases, {phase: SelfEvict.PhaseNames.Evicting}); assert.equal(evictingPhase.numberOfPings, 2, 'number of pings is correct'); assert.equal(evictingPhase.numberOfSuccessfulPings, 2, 'successful pings is correct'); assert.equal(numberOfPings, 2, 'does not ping more than number of members'); cleanup(); }); });
describe('Get KYC Documents', function () { var kycDocument, events; before(function(done){ api.Users.createKycDocument(john.Id, { Status: 'CREATED', Type: 'IDENTITY_PROOF' }).then(function(document){ kycDocument = document; api.Events.getAll(function(data, response){ events = data; done(); }, { parameters: { BeforeDate: kycDocument.CreationDate+10, AfterDate: kycDocument.CreationDate-10, EventType: 'KYC_CREATED' } }); }); }); it('should find KYC Document event', function () { expect(events.length).to.be.above(0); expect(_.findWhere(events, {ResourceId: kycDocument.Id})).to.exist; }); });
return reject('getConnection must be called with a mongo connection string'); var pool = _.findWhere(mongoDBPool, { connectionString: connectionString });
expect(_.findWhere(documents, {Id: document.Id})).to.exist; }); });
describe('Get Disputes for User', function() { var dispute, disputesForUser; before(function(done){ dispute = _.findWhere(disputes, {DisputeType: 'NOT_CONTESTABLE'}); if (!dispute) { console.warn('Cannot test getting disputes for user because there\'s no not costestable disputes in the disputes list.'); this.skip(); } api.Disputes.getTransactions(dispute.Id, function(data, response){ api.Disputes.getDisputesForUser(data[0].AuthorId, function(data, response){ disputesForUser = data; done(); }); }); }); it('should be retrieved', function(){ expect(disputesForUser.length).to.be.above(0); }); });
var selfEvict = new SelfEvict(ringpop); selfEvict.initiate(function afterEvict() { var evictingPhase = _.findWhere(selfEvict.phases, {phase: SelfEvict.PhaseNames.Evicting});
describe('Get Documents for Dispute', function() { var dispute, documents; before(function(done){ dispute = _.findWhere(disputes, {Status: 'SUBMITTED'}); if (!dispute) { console.warn('Cannot test getting dispute\'s documents because there\'s no available disputes with SUBMITTED status in the disputes list.'); this.skip(); } api.Disputes.getDocumentsForDispute(dispute.Id, function(data, response){ documents = data; done(); }); }); it('should be retrieved', function(){ expect(documents.length).to.be.above(0); }); });
testRingpop({async: true}, 'self evict completes when membership is empty', function t(deps, assert, cleanup) { var ringpop = deps.ringpop; var selfEvict = new SelfEvict(ringpop); selfEvict.initiate(function afterSelfEvict(err){ assert.notOk(err); var evictingPhase = _.findWhere(selfEvict.phases, {phase: SelfEvict.PhaseNames.Evicting}); assert.equal(evictingPhase.numberOfPings, 0, 'number of pings is correct'); assert.equal(evictingPhase.numberOfSuccessfulPings, 0, 'successful pings is correct'); cleanup(); }); });
testRingpop({async: true}, 'self evict does not ping more than number of members', function t(deps, assert, cleanup) { var ringpop = deps.ringpop; ringpop.config.set('selfEvictionMaxPingRatio', 2.0); //set above 1 on purpose ringpop.membership.makeChange('127.0.0.1:30002', Date.now(), Member.Status.alive); ringpop.membership.makeChange('127.0.0.1:30003', Date.now(), Member.Status.alive); assert.plan(3); var numberOfPings = 0; ringpop.client = { protocolPing: function(opts, body, cb) { numberOfPings++; cb(null, {changes: []}); }, destroy: function noop() { } }; var selfEvict = new SelfEvict(ringpop); selfEvict.initiate(function afterEvict() { var evictingPhase = _.findWhere(selfEvict.phases, {phase: SelfEvict.PhaseNames.Evicting}); assert.equal(evictingPhase.numberOfPings, 2, 'number of pings is correct'); assert.equal(evictingPhase.numberOfSuccessfulPings, 2, 'successful pings is correct'); assert.equal(numberOfPings, 2, 'does not ping more than number of members'); cleanup(); }); });
var selfEvict = new SelfEvict(ringpop); selfEvict.initiate(function afterEvict() { var evictingPhase = _.findWhere(selfEvict.phases, {phase: SelfEvict.PhaseNames.Evicting});