UNPKG

1.66 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 log = require('../lib/log');
8var fs = require('fs');
9var removeProfile = require('../commands/remove-profile');
10var os = require('os');
11
12require('dash-assert');
13
14describe('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});