Skip to content

Commit 7b8f60f

Browse files
authored
fix: set fallback for no_empty options processor (#657)
* fix: set fallback for `no_empty` options processor * chore: update changelog * chore: add failing test for `no_empty` input type error * chore: fix `no_empty` input type error message
1 parent c574a86 commit 7b8f60f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

__tests__/unit/validators/options_processor/options/no_empty.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,30 @@ test('return pass if input meets the criteria', () => {
3131

3232
test('return fail if input does not meet the criteria', () => {
3333
verify(true, '', [], 'fail')
34+
verify(true, null, [], 'fail')
35+
verify(true, undefined, [], 'fail')
3436
verify(false, '', [''], 'pass')
3537
})
3638

39+
test('return error if input does not meet the criteria', () => {
40+
const rule = { no_empty: { enabled: true } }
41+
let input = 1
42+
try {
43+
const config = noEmpty.process(validatorContext, input, rule)
44+
expect(config).toBeDefined()
45+
} catch (e) {
46+
expect(e.message).toBe('Input type invalid, expected string or Array as input')
47+
}
48+
49+
input = [1]
50+
try {
51+
const config = noEmpty.process(validatorContext, input, rule)
52+
expect(config).toBeDefined()
53+
} catch (e) {
54+
expect(e.message).toBe('Input type invalid, expected string or Array as input')
55+
}
56+
})
57+
3758
test('return error if inputs are not in expected format', async () => {
3859
const rule = { no_empty: { regex: true } }
3960
const input = 'the test'

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CHANGELOG
22
=====================================
3+
| August 26, 2022: set fallback for `no_empty` options processor `#657 <https://github.com/mergeability/mergeable/pull/657>`_
34
| August 25, 2022: fix: set fallback value for `description` payload `#655 <https://github.com/mergeability/mergeable/pull/655>`_
45
| August 20, 2022: fix: supported events for `request_review` action `#651 <https://github.com/mergeability/mergeable/pull/651>`_
56
| August 2, 2022: feat: Add newest_only commit validation setting `#649 <https://github.com/mergeability/mergeable/pull/649>`_

lib/validators/options_processor/options/no_empty.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
const _ = require('lodash')
2+
13
const ENABLED_NOT_FOUND_ERROR = 'Failed to run the test because \'enabled\' is not provided for \'no_empty\' option. Please check README for more information about configuration'
2-
const UNKNOWN_INPUT_TYPE_ERROR = 'Input type invalid, expected string as input'
4+
const UNKNOWN_INPUT_TYPE_ERROR = 'Input type invalid, expected string or Array as input'
35

46
class NoEmpty {
57
static process (validatorContext, input, rule) {
@@ -18,7 +20,7 @@ class NoEmpty {
1820
}
1921
}
2022

21-
let isMergeable
23+
let isMergeable = false
2224

2325
const DEFAULT_SUCCESS_MESSAGE = `The ${validatorContext.name} is not empty`
2426
if (!description) description = `The ${validatorContext.name} can't be empty`
@@ -27,7 +29,7 @@ class NoEmpty {
2729
isMergeable = input.trim().length !== 0
2830
} else if (Array.isArray(input)) {
2931
isMergeable = input.length !== 0
30-
} else {
32+
} else if (!(input == null || _.isUndefined(input))) {
3133
throw new Error(UNKNOWN_INPUT_TYPE_ERROR)
3234
}
3335

0 commit comments

Comments
 (0)