Skip to content

Commit

Permalink
Merge pull request #177 from andersonba/fix-falsy-skip
Browse files Browse the repository at this point in the history
fix falsy skip
  • Loading branch information
andersonba authored Aug 4, 2019
2 parents e4c3229 + d2d2754 commit 45b891f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/__tests__/bot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ test('sanitize rule', () => {
synonyms: 1, one, oNe,ONE
- type: SingleChoice
multiline: false
- skip: false
`);
const bot = new YveBot(rules, OPTS);
expect(bot.rules[0].message).toBe('Hello');
Expand All @@ -76,6 +77,7 @@ test('sanitize rule', () => {
expect(bot.rules[2].skip({})).toBeTruthy();
expect(bot.rules[3].options[0].synonyms).toEqual(['1', 'one', 'oNe', 'ONE']);
expect(bot.rules[4].multiline).toBeFalsy();
expect(bot.rules[5].skip({})).toBeFalsy();
});

test('convert flows to rules', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/core/sanitizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export function sanitizeRule(input: IRule): IRule {

if (typeof rule.skip === 'undefined') {
rule.skip = () => false;
} else {
rule.skip = typeof rule.skip === 'function' ? rule.skip : () => !!rule.skip;
} else if (typeof rule.skip !== 'function') {
const value = !!rule.skip;
rule.skip = () => value;
}

// string way
Expand Down

0 comments on commit 45b891f

Please sign in to comment.