Skip to content

Commit

Permalink
fix: optional config field fixOverride to not break the app
Browse files Browse the repository at this point in the history
closes #7
  • Loading branch information
leonardoanalista committed Nov 18, 2015
1 parent 070fd69 commit 56ca988
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = {

prompter: function(cz, commit) {
var config = readConfigFile();
config.scopeOverrides = config.scopeOverrides || {};

log.info('\n\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n');

Expand Down Expand Up @@ -131,7 +132,6 @@ module.exports = {

var commitStr = buildCommit(answers);
commit(commitStr);
// log.info('<<< this is dry run >>>');
});
}
};
59 changes: 57 additions & 2 deletions spec/czCustomizableSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('cz-customizable', function() {
scope: 'myScope',
subject: 'create a new cool feature'
};
expect(getQuestion(6).message(answers)).toMatch('Are you sure');
expect(getQuestion(6).message(answers)).toMatch('Are you sure you want to proceed with the commit above?');
});

it('should call not call commit() function if there is no final confirmation', function() {
Expand All @@ -90,7 +90,7 @@ describe('cz-customizable', function() {
expect(commit).not.toHaveBeenCalled();
});

it('should call commit() function with commit message when user confirms commit', function() {
it('should call commit() function with commit message when user confirms commit and split body when pipes are present', function() {
module.prompter(cz, commit);
var commitAnswers = cz.prompt.mostRecentCall.args[1];

Expand Down Expand Up @@ -168,4 +168,59 @@ describe('cz-customizable', function() {

});




//###############
describe('optional fixOverride', function() {

beforeEach(function() {
module.__set__({
readConfigFile: function() {
return {
types: [{value: 'feat', name: 'feat: my feat'}],
scopes: [{name: 'myScope'}]
};
}
});

cz = {prompt: jasmine.createSpy()};
commit = jasmine.createSpy();
});


it('should call cz.prompt with questions', function() {
module.prompter(cz, commit);

var getQuestion = function(number) {
return cz.prompt.mostRecentCall.args[0][number - 1];
};

//question 1
expect(getQuestion(1).name).toEqual('type');
expect(getQuestion(1).type).toEqual('list');
expect(getQuestion(1).choices[0]).toEqual({value: 'feat', name: 'feat: my feat'});

//question 2
expect(getQuestion(2).name).toEqual('scope');
expect(getQuestion(2).choices({})[0]).toEqual({name: 'myScope'});
expect(getQuestion(2).choices({type: 'fix'})[0]).toEqual({name: 'myScope'}); //should override scope
expect(getQuestion(2).when({type: 'fix'})).toEqual(true);
expect(getQuestion(2).when({type: 'WIP'})).toEqual(false);
expect(getQuestion(2).when({type: 'wip'})).toEqual(false);

var answers = {
confirmCommit: true,
type: 'feat',
scope: 'myScope',
subject: 'create a new cool feature'
};
expect(getQuestion(6).message(answers)).toMatch('Are you sure you want to proceed with the commit above?');
});
});
//###############




});

0 comments on commit 56ca988

Please sign in to comment.