|
| 1 | +import {Issue} from '../src/classes/issue'; |
| 2 | +import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options'; |
| 3 | +import {IssuesProcessorMock} from './classes/issues-processor-mock'; |
| 4 | +import {DefaultProcessorOptions} from './constants/default-processor-options'; |
| 5 | +import {generateIssue} from './functions/generate-issue'; |
| 6 | +import {alwaysFalseStateMock} from './classes/state-mock'; |
| 7 | + |
| 8 | +describe('only-issue-types option', () => { |
| 9 | + test('should only process issues with allowed type', async () => { |
| 10 | + const opts: IIssuesProcessorOptions = { |
| 11 | + ...DefaultProcessorOptions, |
| 12 | + onlyIssueTypes: 'bug,question' |
| 13 | + }; |
| 14 | + const TestIssueList: Issue[] = [ |
| 15 | + generateIssue( |
| 16 | + opts, |
| 17 | + 1, |
| 18 | + 'A bug', |
| 19 | + '2020-01-01T17:00:00Z', |
| 20 | + '2020-01-01T17:00:00Z', |
| 21 | + false, |
| 22 | + false, |
| 23 | + [], |
| 24 | + false, |
| 25 | + false, |
| 26 | + undefined, |
| 27 | + [], |
| 28 | + 'bug' |
| 29 | + ), |
| 30 | + generateIssue( |
| 31 | + opts, |
| 32 | + 2, |
| 33 | + 'A feature', |
| 34 | + '2020-01-01T17:00:00Z', |
| 35 | + '2020-01-01T17:00:00Z', |
| 36 | + false, |
| 37 | + false, |
| 38 | + [], |
| 39 | + false, |
| 40 | + false, |
| 41 | + undefined, |
| 42 | + [], |
| 43 | + 'feature' |
| 44 | + ), |
| 45 | + generateIssue( |
| 46 | + opts, |
| 47 | + 3, |
| 48 | + 'A question', |
| 49 | + '2020-01-01T17:00:00Z', |
| 50 | + '2020-01-01T17:00:00Z', |
| 51 | + false, |
| 52 | + false, |
| 53 | + [], |
| 54 | + false, |
| 55 | + false, |
| 56 | + undefined, |
| 57 | + [], |
| 58 | + 'question' |
| 59 | + ) |
| 60 | + ]; |
| 61 | + const processor = new IssuesProcessorMock( |
| 62 | + opts, |
| 63 | + alwaysFalseStateMock, |
| 64 | + async p => (p === 1 ? TestIssueList : []), |
| 65 | + async () => [], |
| 66 | + async () => new Date().toDateString() |
| 67 | + ); |
| 68 | + await processor.processIssues(1); |
| 69 | + expect(processor.staleIssues.map(i => i.title)).toEqual([ |
| 70 | + 'A bug', |
| 71 | + 'A question' |
| 72 | + ]); |
| 73 | + }); |
| 74 | + |
| 75 | + test('should process all issues if onlyIssueTypes is unset', async () => { |
| 76 | + const opts: IIssuesProcessorOptions = { |
| 77 | + ...DefaultProcessorOptions, |
| 78 | + onlyIssueTypes: '' |
| 79 | + }; |
| 80 | + const TestIssueList: Issue[] = [ |
| 81 | + generateIssue( |
| 82 | + opts, |
| 83 | + 1, |
| 84 | + 'A bug', |
| 85 | + '2020-01-01T17:00:00Z', |
| 86 | + '2020-01-01T17:00:00Z', |
| 87 | + false, |
| 88 | + false, |
| 89 | + [], |
| 90 | + false, |
| 91 | + false, |
| 92 | + undefined, |
| 93 | + [], |
| 94 | + 'bug' |
| 95 | + ), |
| 96 | + generateIssue( |
| 97 | + opts, |
| 98 | + 2, |
| 99 | + 'A feature', |
| 100 | + '2020-01-01T17:00:00Z', |
| 101 | + '2020-01-01T17:00:00Z', |
| 102 | + false, |
| 103 | + false, |
| 104 | + [], |
| 105 | + false, |
| 106 | + false, |
| 107 | + undefined, |
| 108 | + [], |
| 109 | + 'feature' |
| 110 | + ) |
| 111 | + ]; |
| 112 | + const processor = new IssuesProcessorMock( |
| 113 | + opts, |
| 114 | + alwaysFalseStateMock, |
| 115 | + async p => (p === 1 ? TestIssueList : []), |
| 116 | + async () => [], |
| 117 | + async () => new Date().toDateString() |
| 118 | + ); |
| 119 | + await processor.processIssues(1); |
| 120 | + expect(processor.staleIssues.map(i => i.title)).toEqual([ |
| 121 | + 'A bug', |
| 122 | + 'A feature' |
| 123 | + ]); |
| 124 | + }); |
| 125 | +}); |
0 commit comments