test('that description is correct when mergeable', async () => { const assignee = new Assignee() const settings = { do: 'assignee', min: { count: 5 } } let validation = await assignee.validate(createMockPR(5), settings) expect(validation.validations[0].description).toBe("assignee does have a minimum of '5'") })
test('return error if unsupported options are provided', async () => { const rule = {do: 'label', must_be_include: {regex: 'A'}} const input = ['A'] const res = options.process('label', input, rule) expect(res.status).toBe('error') expect(res.validations[0].description).toBe(`Cannot find module './options/must_be_include' from 'options.js'`) })
test('description is correct', async () => { let label = new Label() let settings = { do: 'label', must_exclude: { regex: 'Work in Progress' } } let validation = await label.validate(createMockContext('Work in Progress'), settings) expect(validation.status).toBe('fail') expect(validation.validations[0].description).toBe('label included "Work in Progress"') validation = await label.validate(createMockContext('Just Label'), settings) expect(validation.validations[0].description).toBe("label must exclude 'Work in Progress'") })
expect(titleValidation.validations[0].description).toBe(`title must begins with "${match}"`) expect(titleValidation.validations[0].description).toBe(`title must begins with "${match}"`)
test('must_include works', async () => { const description = new Description() const settings = { do: 'description', must_include: { regex: 'test string', message: 'failed test' } } let descriptionValidation = await description.validate(createMockPR('test string included'), settings) expect(descriptionValidation.status).toBe('pass') descriptionValidation = await description.validate(createMockPR('Non empty Description'), settings) expect(descriptionValidation.status).toBe('fail') expect(descriptionValidation.validations[0].description).toBe('failed test') })
expect(validation.validations[0].description).toBe('((Please include a language label) ***OR*** Please include release note: no)') expect(validation.validations[0].description).toBe('((Please include release note: yes) ***OR*** Please include release note: no)')
test('checks that it fail when include regex is in title', async () => { let title = new Title() let includeList = `^\\(feat\\)|^\\(doc\\)|^\\(fix\\)` let settings = { do: 'title', must_include: { regex: includeList }, must_exclude: { regex: 'wip' } } let titleValidation = await title.validate(mockContext('include Title'), settings) expect(titleValidation.status).toBe('fail') expect(titleValidation.validations[0].description).toBe(`title does not include "${includeList}"`) titleValidation = await title.validate(mockContext('(feat) WIP Title'), settings) expect(titleValidation.status).toBe('fail') })
test('description should be correct', async () => { const milestone = new Milestone() const settings = { do: 'milestone', must_include: { regex: 'Version 1' } } let validation = await milestone.validate(createMockContext(), settings) expect(validation.validations[0].description).toBe(`milestone does not include "Version 1"`) })
test('must_exclude works', async () => { const description = new Description() const settings = { do: 'description', must_exclude: { regex: 'test string', message: 'failed test' } } let descriptionValidation = await description.validate(createMockPR('test string included'), settings) expect(descriptionValidation.status).toBe('fail') expect(descriptionValidation.validations[0].description).toBe('failed test') descriptionValidation = await description.validate(createMockPR('Non empty Description'), settings) expect(descriptionValidation.status).toBe('pass') })
test('description is correct', async () => { const description = new Description() const settings = { do: 'description', no_empty: { enabled: true } } let descriptionValidation = await description.validate(createMockPR(''), settings) expect(descriptionValidation.status).toBe('fail') expect(descriptionValidation.validations[0].description).toBe("The description can't be empty") descriptionValidation = await description.validate(createMockPR('Non empty Description'), settings) expect(descriptionValidation.validations[0].description).toBe('The description is not empty') })
test('that it validates ends_with correctly', async () => { let label = new Label() let match = 'test' let settings = { do: 'label', ends_with: { match: match } } let labelValidation = await label.validate(createMockContext(['Some Label']), settings) expect(labelValidation.status).toBe('fail') expect(labelValidation.validations[0].description).toBe(`label must end with "${match}"`) labelValidation = await label.validate(createMockContext(['Label test']), settings) expect(labelValidation.status).toBe('pass') })
test('checks that max is working', async () => { const assignee = new Assignee() const settings = { do: 'assignee', max: { count: 2 } } let validation = await assignee.validate(createMockPR(3), settings) expect(validation.status).toBe('fail') expect(validation.validations[0].description).toBe('assignee count is more than "2"') validation = await assignee.validate(createMockPR(2), settings) expect(validation.status).toBe('pass') })
test('that description is dynamic based on minimum', async () => { const assignee = new Assignee() const settings = { do: 'assignee', min: { count: 5 } } let validation = await assignee.validate(createMockPR(1), settings) expect(validation.validations[0].description).toBe('assignee count is less than "5"') })
test('checks that advance_setting message is working', async () => { const assignee = new Assignee() const settings = { do: 'assignee', max: { count: 2, message: 'test string' } } let validation = await assignee.validate(createMockPR(3), settings) expect(validation.status).toBe('fail') expect(validation.validations[0].description).toBe('test string') validation = await assignee.validate(createMockPR(2), settings) expect(validation.status).toBe('pass') })
test('checks that advance setting of must_include works', async () => { let title = new Title() let includeList = `^\\(feat\\)|^\\(doc\\)|^\\(fix\\)` let testMessage = 'this is a test message' let settings = { do: 'title', must_include: { regex: includeList, message: testMessage }, must_exclude: { regex: 'wip' } } let titleValidation = await title.validate(mockContext('include Title'), settings) expect(titleValidation.status).toBe('fail') expect(titleValidation.validations[0].description).toBe(testMessage) titleValidation = await title.validate(mockContext('(feat) WIP Title'), settings) expect(titleValidation.status).toBe('fail') })