|
| 1 | +import { When } from 'commitlint-github-utils/@types'; |
| 2 | + |
| 3 | +import { RuleResolverResult } from '../../../../@types'; |
| 4 | +import wipAllowedRuleResolver from '../isWipAllowed'; |
| 5 | +import runRule from '../../utils/tests/utils'; |
| 6 | + |
| 7 | +const parse = (when: When, rawCommitMessage: string): RuleResolverResult => |
| 8 | + runRule(wipAllowedRuleResolver, [when], rawCommitMessage); |
| 9 | + |
| 10 | +describe('wipAllowedRuleResolver', () => { |
| 11 | + it('should always return an error response if an empty commit message is provided', () => { |
| 12 | + expect(parse(When.ALWAYS, '')[0]).toEqual(false); |
| 13 | + expect(parse(When.NEVER, '')[0]).toEqual(false); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should return a success response if the commit is not a WIP', () => { |
| 17 | + expect(parse(When.ALWAYS, '(#1) my commit message')[0]).toEqual(true); |
| 18 | + expect(parse(When.ALWAYS, '(#1) chore: my commit message')[0]).toEqual(true); |
| 19 | + |
| 20 | + expect(parse(When.ALWAYS, '(#1, #2) my commit message')[0]).toEqual(true); |
| 21 | + expect(parse(When.ALWAYS, '(#1,#2) my commit message')[0]).toEqual(true); |
| 22 | + |
| 23 | + expect(parse(When.ALWAYS, '(#123, #23) chore: my commit message')[0]).toEqual(true); |
| 24 | + expect(parse(When.ALWAYS, '(#123,#23) chore: my commit message')[0]).toEqual(true); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return a success response if the commit is WIP and not disallowed', () => { |
| 28 | + expect(parse(When.ALWAYS, '(#1) WIP: my commit message')[0]).toEqual(true); |
| 29 | + expect(parse(When.ALWAYS, '(#1, #2, #3, #4) WIP: my commit message')[0]).toEqual(true); |
| 30 | + expect(parse(When.ALWAYS, '(#1,#2,#3,#4) WIP: my commit message')[0]).toEqual(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should return a success response if the commit is not a WIP even if disallowed', () => { |
| 34 | + expect(parse(When.NEVER, '(#1) my commit message')[0]).toEqual(true); |
| 35 | + expect(parse(When.NEVER, '(#1) chore: my commit message')[0]).toEqual(true); |
| 36 | + |
| 37 | + expect(parse(When.NEVER, '(#1, #2) my commit message')[0]).toEqual(true); |
| 38 | + expect(parse(When.NEVER, '(#1,#2) my commit message')[0]).toEqual(true); |
| 39 | + |
| 40 | + expect(parse(When.NEVER, '(#123, #23) chore: my commit message')[0]).toEqual(true); |
| 41 | + expect(parse(When.NEVER, '(#123,#23) chore: my commit message')[0]).toEqual(true); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should return an error response if the commit is WIP and disallowed', () => { |
| 45 | + expect(parse(When.NEVER, '(#1) WIP: my commit message')[0]).toEqual(false); |
| 46 | + expect(parse(When.NEVER, '(#1, #2, #3, #4) WIP: my commit message')[0]).toEqual(false); |
| 47 | + expect(parse(When.NEVER, '(#1,#2,#3,#4) WIP: my commit message')[0]).toEqual(false); |
| 48 | + }); |
| 49 | +}); |
0 commit comments