UNPKG

2.23 kBJavaScriptView Raw
1var assert = require('assert');
2var async = require('async');
3var sinon = require('sinon');
4var fs = require('fs');
5var _ = require('lodash');
6var path = require('path');
7var parseUrl = require('url').parse;
8var rimraf = require('rimraf');
9var log = require('../lib/log');
10var fs = require('fs');
11var addProfile = require('../commands/add-profile');
12var os = require('os');
13
14require('dash-assert');
15
16describe('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});