it('outputs message with color when color is supplied', function (done) { const stdout = streamTestUtils.getWritableStream(function (output) { expect(output, 'output exists').to.be.ok; expect(hasAnsi(output), 'output has color').to.be.true; expect(output, 'output value').to.equal(chalk.green('test') + '\n'); done(); }); stdout.on('error', done); const ui = new UI({stdout: stdout}); ui.log('test', 'green'); });
it('can use a proxy to get the service key', function () { var httpsRequestSpy = this.sandbox.spy(https, 'request') defaultConfig.proxy = 'http://127.0.0.1' var collectorApi = CollectorApi.create(defaultConfig) collectorApi.getService() expect(httpsRequestSpy.firstCall.args[0].agent).to.eql(collectorApi.proxyAgent) expect(collectorApi.proxyAgent).to.be.ok })
it('correctly passes through options', function () { const execa = sinon.stub().resolves(); const yarn = setup({execa}); return yarn([], {cwd: 'test'}).then(function () { expect(execa.calledOnce).to.be.true; expect(execa.args[0]).to.be.ok; expect(execa.args[0]).to.have.lengthOf(3); expect(execa.args[0][2]).to.be.an('object'); expect(execa.args[0][2].cwd).to.equal('test'); }); });
it('using orderBy == "productivity:asc" should be ok', function (done) { var orderBy = 'productivity:asc'; var params = 'orderBy=' + orderBy; node.get('/api/delegates?' + params, function (err, res) { node.expect(res.body).to.have.property('success').to.be.ok; node.expect(res.body).to.have.property('delegates').that.is.an('array'); node.expect(res.body.delegates).to.have.lengthOf(51); done(); }); });
it('using invalid username should fail', function (done) { validParams.username = '~!@#$%^&*()_+.,?/'; putDelegates(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; node.expect(res.body).to.have.property('error'); done(); }); });
it('success outputs message with correct symbols', function (done) { const stdout = streamTestUtils.getWritableStream(function (output) { expect(output, 'output exists').to.be.ok; expect(output, 'output value').to.equal(`${logSymbols.success} test\n`); done(); }); stdout.on('error', done); const UI = require(modulePath); const ui = new UI({stdout: stdout}); ui.success('test'); });
it('displays a multi-line help message when called with 4 args', function (done) { const stdout = streamTestUtils.getWritableStream(function (output) { expect(output, 'output exists').to.be.ok; expect(hasAnsi(output), 'output has color').to.be.true; expect(output, 'output value').to.include(chalk.green(`\nmy message: \n\n ${chalk.cyan('testing')}`)); done(); }); stdout.on('error', done); const UI = require(modulePath); const ui = new UI({stdout: stdout}); ui.log('my message', 'testing', 'green', 'link'); });
it('adds verbose option correctly', function () { const execa = sinon.stub().resolves(); const yarn = setup({execa}); return yarn(['cache', 'clear'], {verbose: true}).then(function () { expect(execa.calledOnce).to.be.true; expect(execa.args[0]).to.be.ok; expect(execa.args[0]).to.have.lengthOf(3); expect(execa.args[0][1]).to.deep.equal(['cache', 'clear', '--verbose']); }); });
it('using criteria with length == 20 should be ok', function (done) { var q = 'genesis_123456789012'; // 20 characters node.get('/api/delegates/search?q=' + q, function (err, res) { node.expect(res.body).to.have.property('success').to.be.ok; node.expect(res.body).to.have.property('delegates').that.is.an('array'); done(); }); });
it('fail outputs message with correct formatting', function (done) { const stdout = streamTestUtils.getWritableStream(function (output) { expect(output, 'output exists').to.be.ok; expect(output, 'output value').to.equal(`${logSymbols.error} test\n`); done(); }); stdout.on('error', done); const UI = require(modulePath); const ui = new UI({stdout: stdout}); ui.fail('test'); });
it('using criteria with length > 20 should fail', function (done) { var q = 'genesis_1234567890123'; // 21 characters node.get('/api/delegates/search?q=' + q, function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; node.expect(res.body).to.have.property('error'); done(); }); });
it('using critera == "genesis_1" should return 11 delegates', function (done) { var q = 'genesis_1'; node.get('/api/delegates/search?q=' + q, function (err, res) { node.expect(res.body).to.have.property('success').to.be.ok; node.expect(res.body).to.have.property('delegates').that.is.an('array'); node.expect(res.body.delegates).to.have.length(11); done(); }); });
it('using blank username should fail', function (done) { validParams.username = ''; putDelegates(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; node.expect(res.body).to.have.property('error'); done(); }); });
it('using no limit should be ok', function (done) { var q = 'genesis_'; node.get('/api/delegates/search?q=' + q, function (err, res) { node.expect(res.body).to.have.property('success').to.be.ok; node.expect(res.body).to.have.property('delegates').that.is.an('array'); node.expect(res.body.delegates).to.have.length(51); done(); }); });