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 log = require('../lib/log');
|
8 | var fs = require('fs');
|
9 | var removeProfile = require('../commands/remove-profile');
|
10 | var os = require('os');
|
11 |
|
12 | require('dash-assert');
|
13 |
|
14 | describe('remove-profile', function() {
|
15 | var self;
|
16 |
|
17 | beforeEach(function() {
|
18 | self = this;
|
19 |
|
20 | this.program = {
|
21 | globalConfigPath: path.join(os.tmpdir(), '.4front.json'),
|
22 | globalConfig: {
|
23 | profiles: [{
|
24 | name: 'test',
|
25 | url: 'http://4front.test'
|
26 | }]
|
27 | }
|
28 | };
|
29 | });
|
30 |
|
31 | before(function() {
|
32 | sinon.stub(log, 'write', _.noop());
|
33 | });
|
34 |
|
35 | after(function() {
|
36 | log.write.restore();
|
37 | });
|
38 |
|
39 | afterEach(function(done) {
|
40 | fs.unlink(this.program.globalConfigPath, function() {
|
41 | done();
|
42 | });
|
43 | });
|
44 |
|
45 | it('removes profile', function(done) {
|
46 | this.program.profileName = 'test';
|
47 |
|
48 | removeProfile(this.program, function(err) {
|
49 | var globalConfig = JSON.parse(fs.readFileSync(self.program.globalConfigPath));
|
50 | assert.equal(globalConfig.profiles.length, 0);
|
51 | done();
|
52 | });
|
53 | });
|
54 |
|
55 | it('returns error if profile name does not exist', function(done) {
|
56 | this.program.profileName = 'missing';
|
57 |
|
58 | removeProfile(this.program, function(err) {
|
59 | assert.matchesPattern(err, /no registered profile named missing/);
|
60 | done();
|
61 | });
|
62 | });
|
63 |
|
64 | it('returns error if profile name missing', function(done) {
|
65 | removeProfile(this.program, function(err) {
|
66 | assert.matchesPattern(err, /Please provide a profile name/);
|
67 | done();
|
68 | });
|
69 | });
|
70 | });
|