UNPKG

acs

Version:
95 lines (71 loc) 2.83 kB
var chai = require('chai'), should = chai.should(), rewire = require('rewire'), sinon = require('sinon'), util = require('../lib/util'), helper = require('./helper'); var listModule = rewire('../lib/command/list'); var consolelog = console.log; describe('list cli - ', () => { var outputs = []; var positiveBody = { success: true }; before(helper.beforeHandler); after(helper.afterHandler); beforeEach(helper.buildBeforeEachHandler(outputs)); afterEach(helper.afterEachHandler); it('should use host and port from command line', async () => { var args = []; var opts = { host: helper.testHost, port: 8443 }; // { // "uri": "https://admin.unittest.appcelerator.com:8443/list", // "method": "GET", // "proxy": null, // "headers": { // "Cookie": "fake-cookie-for-request", // "Content-Type": "application/x-www-form-urlencoded", // "Authorization": "" // } // } var successRequestMock = helper.buildRequestMock(function(options) { // consolelog(JSON.stringify(options, null, 4)); options['uri'].should.eql(helper.testHost + ':8443/list'); options['method'].should.eql('GET'); options['headers']['Cookie'].should.eql(helper.fakeCookieForReq); }, null, null, positiveBody); listModule.__set__('got', successRequestMock); await listModule.run(args, opts) // consolelog(outputs) // [ '\u001b[90mAdmin Hostname: https://admin.unittest.appcelerator.com\u001b[39m', // 'No app found.' ] outputs[0].should.contain(helper.hostInfoLine(helper.testHost)); outputs[1].should.contain('No app found.'); }); it('should use host from command line', async () => { var args = []; var opts = { host: helper.testHost }; var path = '/list'; var successRequestMock = helper.buildRequestMockWithReqOptions(helper.testHost, '443', path, 'GET', positiveBody); listModule.__set__('got', successRequestMock); await listModule.run(args, opts) outputs[0].should.contain(helper.hostInfoLine(helper.testHost)); outputs[1].should.contain('No app found.'); }); it('should use default host', async () => { var args = []; var opts = {}; var path = '/list'; var successRequestMock = helper.buildRequestMockWithReqOptions(helper.defaultHost, '443', path, 'GET', positiveBody); listModule.__set__('got', successRequestMock); await listModule.run(args, opts) outputs[0].should.contain('No app found.'); }); });