var assertUniformDistributionInt = function(values, min, max) { var range = _.range(Math.floor(min), Math.floor(max)), count; values.forEach(function(val) { assert.ok(_.contains(range, val)); }); range.forEach(function(val) { count = _.filter(values, function(testVal) { return testVal === val }).length; assertApproxEqual(count/values.length, 1/range.length, 0.03); }); }
function isDefaultCommand(command) { // The commands bellow have their default implementation from the command-parser module. var defaultCommands = ['-V', '--version', '-h', '--help']; return _.contains(defaultCommands, command); }
test('include', function() { ok(_.include([1,2,3], 2), 'two is in the array'); ok(!_.include([1,3,9], 2), 'two is not in the array'); ok(_.contains({moe:1, larry:3, curly:9}, 3) === true, '_.include on objects checks their values'); ok(_([1,2,3]).include(2), 'OO-style include'); });
test('sample', function() { var numbers = _.range(10); var all_sampled = _.sample(numbers, 10).sort(); equal(all_sampled.join(','), numbers.join(','), 'contains the same members before and after sample'); all_sampled = _.sample(numbers, 20).sort(); equal(all_sampled.join(','), numbers.join(','), 'also works when sampling more objects than are present'); ok(_.contains(numbers, _.sample(numbers)), 'sampling a single element returns something from the array'); strictEqual(_.sample([]), undefined, 'sampling empty array with no number returns undefined'); notStrictEqual(_.sample([], 5), [], 'sampling empty array with a number returns an empty array'); notStrictEqual(_.sample([1, 2, 3], 0), [], 'sampling an array with 0 picks returns an empty array'); deepEqual(_.sample([1, 2], -1), [], 'sampling a negative number of picks returns an empty array'); });
/** * Sets this actor to forward messages with given topics to a given child. * * @param {Actor} childActor Actor to forward messages to. * @param {String|RegExp} topics Message topic strings or regular expressions. * @returns {P} Operation result promise. */ forwardToChild(childActor, ...topics) { return P.all(this.childPromises).then(children => { if (!_.contains(children, childActor)) { throw new Error('Cannot forward ' + topics + ' messages to ' + childActor + ' actor, because it\'s not a child of ' + this + ' actor.'); } topics.forEach(topic => { this.forwardList.push([topic, childActor]); }); }); }
describe('Wallets', function() { var wallets, wallet; before(function(done){ wallet = { Owners: [john.Id], Currency: 'EUR', Description: 'WALLET IN EUR' }; api.Wallets.create(wallet).then(function(){ api.Users.getWallets(john.Id, function(data, response){ wallets = data; done(); }); }); }); it('should have two wallets', function(){ expect(wallets.length).to.equal(2); }); it('wallet should contain the right data', function(){ assert(_.contains(wallets[0].Owners, john.Id)); }); });
// presence users router.get('/presence/users/:id', function(req, res) { var viewing_id = req.params.id; get_app(req, res, function(application) { var response = []; var users = instance.engine.app_users[application.get('id')]; if (users) { var children = req.query.children !== undefined; _.each(users, function(user) { if (!user.get('anonymous') && user.get('socket') && (user.get('viewing') == viewing_id || (children && _.contains(user.get('viewing_path'), viewing_id)) ) ) { response.push(serialize_user(user)); } }, this); } res.json(response); }); });
describe('Resubmit Dispute', function() { var dispute, resubmitted; before(function(done){ dispute = _.find(disputes, function(disputeItem){ return (_.contains(['CONTESTABLE', 'RETRIEVAL'], disputeItem.DisputeType) && disputeItem.Status === 'REOPENED_PENDING_CLIENT_ACTION' ); }); if (!dispute) { console.warn('Cannot test contesting dispute because there\'s no disputes that can be resubmited in the disputes list.'); this.skip(); } api.Disputes.resubmitDispute(dispute.Id, function(data, response){ resubmitted = data; done(); }); }); it('should be resubmitted', function(){ expect(resubmitted).not.to.be.undefined; expect(resubmitted.Id).to.equal(dispute.Id); expect(resubmitted.Status).to.equal('SUBMITTED'); }); });
var isDirectory = /\/$/.test(fileName); if (!isDirectory && _.contains(fileNames, fileName)) {
describe('Create Dispute Document', function() { var dispute, document; before(function(done){ dispute = _.find(disputes, function(disputeItem){ return _.contains(['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'], disputeItem.Status); }); if (!dispute) { console.warn('Cannot test creating dispute document because there\'s no dispute with expected status in the disputes list.'); this.skip(); } api.Disputes.createDisputeDocument(dispute.Id, { Type: 'DELIVERY_PROOF' }, function(data, response){ document = data; done(); }); }); it('should be created', function(){ expect(document.Type).to.equal('DELIVERY_PROOF'); }); });
return _.contains(['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'], disputeItem.Status); });
// presence overview viewing a document router.get('/presence/overview/:id', function(req, res) { var viewing_id = req.params.id; get_app(req, res, function(application) { var response = { total: 0, anonymous: 0, authenticated: 0, }; var users = instance.engine.app_users[application.get('id')]; if (users) { var children = req.query.children !== undefined; _.each(users, function(user) { if (user.get('socket') && (user.get('viewing') == viewing_id || (children && _.contains(user.get('viewing_path'), viewing_id)) ) ) { response.total++; if (user.get('anonymous')) response.anonymous++; else response.authenticated++; } }, this); } res.json(response); }); });
describe('Close Dispute', function() { var dispute, closedDispute; before(function(done){ dispute = _.find(disputes, function(disputeItem){ return _.contains(['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'], disputeItem.Status); }); if (!dispute) { console.warn('Cannot test closing dispute because there\'s no available disputes with expected status in the disputes list.'); this.skip(); } api.Disputes.closeDispute(dispute.Id, function(data, response){ closedDispute = data; done(); }); }); it('should be closed', function(){ expect(closedDispute).not.to.be.undefined; expect(closedDispute.Status).to.equal('CLOSED'); }); });
describe('Get Document', function() { var dispute, document, createdDoc; before(function(done){ dispute = _.find(disputes, function(disputeItem){ return _.contains(['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'], disputeItem.Status); }); if (!dispute) { console.warn('Cannot test getting dispute\'s document because there\'s no dispute with expected status in the disputes list.'); this.skip(); } api.Disputes.createDisputeDocument(dispute.Id, { Type: 'OTHER' }, function(data, response){ createdDoc = data; api.DisputeDocuments.get(createdDoc.Id, function(data, response){ document = data; done(); }); }); }); it('should be retrieved', function(){ expect(document).not.to.be.undefined; expect(document).to.eql(createdDoc); }); });