1 | var assert = require('assert');
|
2 | var async = require('async');
|
3 | var sinon = require('sinon');
|
4 | var fs = require('fs');
|
5 | var _ = require('lodash');
|
6 | var path = require('path');
|
7 | var parseUrl = require('url').parse;
|
8 | var rimraf = require('rimraf');
|
9 | var log = require('../lib/log');
|
10 | var fs = require('fs');
|
11 | var addProfile = require('../commands/add-profile');
|
12 | var os = require('os');
|
13 |
|
14 | require('dash-assert');
|
15 |
|
16 | describe('add-profile', function() {
|
17 | var self;
|
18 |
|
19 | beforeEach(function() {
|
20 | self = this;
|
21 |
|
22 | this.program = {
|
23 | globalConfigPath: path.join(os.tmpdir(), '.4front.json'),
|
24 | globalConfig: {
|
25 | profiles: []
|
26 | }
|
27 | };
|
28 | });
|
29 |
|
30 | afterEach(function(done) {
|
31 | fs.unlink(this.program.globalConfigPath, function() {
|
32 | done();
|
33 | });
|
34 | });
|
35 |
|
36 | before(function() {
|
37 | sinon.stub(log, 'write', _.noop());
|
38 | });
|
39 |
|
40 | after(function() {
|
41 | log.write.restore();
|
42 | });
|
43 |
|
44 | it('adds first profile', function(done) {
|
45 | this.program.profileName = 'production';
|
46 | this.program.endpoint = 'https://4frontapps.com';
|
47 |
|
48 | addProfile(this.program, function(err) {
|
49 | var globalConfig = JSON.parse(fs.readFileSync(self.program.globalConfigPath));
|
50 | assert.deepEqual(globalConfig.profiles[0], {
|
51 | name: self.program.profileName,
|
52 | endpoint: self.program.endpoint,
|
53 | default: true
|
54 | });
|
55 |
|
56 | done();
|
57 | });
|
58 | });
|
59 |
|
60 | it('returns error if profile name missing', function(done) {
|
61 | addProfile(this.program, function(err) {
|
62 | assert.matchesPattern(err, /Please provide a profile name/);
|
63 | done();
|
64 | });
|
65 | });
|
66 |
|
67 | it('returns error if endpoint missing', function(done) {
|
68 | this.program.profileName = 'production';
|
69 |
|
70 | addProfile(this.program, function(err) {
|
71 | assert.matchesPattern(err, /Please provide an endpoint url/);
|
72 | done();
|
73 | });
|
74 | });
|
75 |
|
76 | it('returns error if profile name already exists', function(done) {
|
77 | this.program.globalConfig.profiles.push({
|
78 | name: 'production',
|
79 | endpoint: 'https://4frontapps.com'
|
80 | });
|
81 |
|
82 | this.program.profileName = 'production';
|
83 | this.program.endpoint = 'https://4frontapps.com';
|
84 |
|
85 | addProfile(this.program, function(err) {
|
86 | assert.matchesPattern(err, /There is already a profile/);
|
87 | done();
|
88 | });
|
89 | });
|
90 | });
|