UNPKG

acs

Version:
101 lines (77 loc) 3.1 kB
var chai = require('chai'), should = chai.should(), rewire = require('rewire'), sinon = require('sinon'), util = require('../lib/util'), helper = require('./helper'); var configModule = rewire('../lib/command/config'); var consolelog = console.log; describe('config cli - ', () => { var outputs = []; var positiveBody = { success: true, message: 'config done' }; 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 = [helper.testApp]; var opts = { host: helper.testHost, port: 8443, minsize: 3, org: '14301' }; // { // "uri": "https://admin.unittest.appcelerator.com:8443/config/testApp/min/3?orgid=14301", // "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['url'].should.eql(helper.testHost + ':8443/config/testApp/min/3?orgid=14301'); options['method'].should.eql('GET'); options['headers']['Cookie'].should.eql(helper.fakeCookieForReq); }, null, null, positiveBody); configModule.__set__('got', successRequestMock); await configModule.run(args, opts) // consolelog(outputs); // [ '\u001b[90mAdmin Hostname: https://admin.unittest.appcelerator.com\u001b[39m', // 'config done' ] outputs[0].should.contain(helper.hostInfoLine(helper.testHost)); outputs[1].should.eql('config done'); }); it('should use host from command line', async () => { var args = [helper.testApp]; var opts = { host: helper.testHost, minsize: 3 }; var path = '/config/testApp/min/3'; var successRequestMock = helper.buildRequestMockWithReqOptions(helper.testHost, '443', path, 'GET', positiveBody); configModule.__set__('got', successRequestMock); await configModule.run(args, opts) outputs[0].should.contain(helper.hostInfoLine(helper.testHost)); outputs[1].should.eql('config done'); }); it('should use default host', async () => { var args = [helper.testApp]; var opts = { minsize: 3 }; var path = '/config/testApp/min/3'; var successRequestMock = helper.buildRequestMockWithReqOptions(helper.defaultHost, '443', path, 'GET', positiveBody); configModule.__set__('got', successRequestMock); await configModule.run(args, opts) outputs[0].should.eql('config done'); }); });