UNPKG

acs

Version:
121 lines (96 loc) 3.67 kB
var chai = require('chai'), should = chai.should(), rewire = require('rewire'), sinon = require('sinon'), util = require('../lib/util'), fs = require('fs-extra'), helper = require('./helper'); var newModule = rewire('../lib/command/new'); var consolelog = console.log; describe('new cli - ', async () => { var outputs = []; var positiveBody = { success: true, message: 'new done' }; before(helper.beforeHandler); after(helper.afterHandler); beforeEach(function(done) { var originalExists = util.exists; sinon.stub(util, 'exists', function(path) { if(originalExists(path)) { fs.removeSync(path); } return false; }); helper.buildBeforeEachHandler(outputs)(done); }); afterEach(function(done) { util.exists.restore(); helper.afterEachHandler(done); }); it('should use host and port from command line', async () => { var args = [helper.testApp]; var opts = { dir: __dirname, host: helper.testHost, port: 8443 }; // { // "uri": "https://admin.unittest.appcelerator.com:8443/create/testApp", // "method": "POST", // "proxy": null, // "headers": { // "Cookie": "fake-cookie-for-request", // "Content-Type": "application/json", // "Authorization": "" // }, // "body": "{}" // } var successRequestMock = helper.buildRequestMock(function(options) { // consolelog(JSON.stringify(options, null, 4)); options['url'].should.eql(helper.testHost + ':8443/create/testApp'); options['method'].should.eql('POST'); options['headers']['Cookie'].should.eql(helper.fakeCookieForReq); }, null, null, positiveBody); newModule.__set__('got', successRequestMock); sinon.stub(process, 'exit', function() { // consolelog(outputs); // [ '\u001b[90mAdmin Hostname: https://admin.unittest.appcelerator.com\u001b[39m', // 'New project created at ...' ] outputs[0].should.contain(helper.hostInfoLine(helper.testHost)); outputs[1].should.contain('New project created at'); }); await newModule.run(args, opts) }); it('should use host from command line', async () => { var args = [helper.testApp]; var opts = { dir: __dirname, host: helper.testHost }; var path = '/create/testApp'; var successRequestMock = helper.buildRequestMockWithReqOptions(helper.testHost, '443', path, 'POST', positiveBody); newModule.__set__('got', successRequestMock); sinon.stub(process, 'exit', function() { outputs[0].should.contain(helper.hostInfoLine(helper.testHost)); outputs[1].should.contain('New project created at'); }); await newModule.run(args, opts) }); it('should use default host', async () => { var args = [helper.testApp]; var opts = { dir: __dirname }; var path = '/create/testApp'; var successRequestMock = helper.buildRequestMockWithReqOptions(helper.defaultHost, '443', path, 'POST', positiveBody); newModule.__set__('got', successRequestMock); sinon.stub(process, 'exit', function() { outputs[0].should.contain('New project created at'); }); await newModule.run(args, opts) }); });