|
| 1 | +const BooleanMatch = require('../../../../../lib/filters/options_processor/options/boolean') |
| 2 | + |
| 3 | +const filterContext = undefined |
| 4 | + |
| 5 | +const filter = { |
| 6 | + name: 'payload', |
| 7 | + supportedOptions: [ |
| 8 | + 'boolean', |
| 9 | + 'must_exclude', |
| 10 | + 'must_include'] |
| 11 | +} |
| 12 | + |
| 13 | +const verify = (match, input, result) => { |
| 14 | + const rule = { boolean: { match } } |
| 15 | + const res = BooleanMatch.process(filterContext, filter, input, rule) |
| 16 | + expect(res.status).toBe(result) |
| 17 | + return res |
| 18 | +} |
| 19 | + |
| 20 | +test('return pass if input is a string that meets the criteria', () => { |
| 21 | + verify(true, 'true', 'pass') |
| 22 | + verify(false, 'false', 'pass') |
| 23 | +}) |
| 24 | + |
| 25 | +test('return pass if input is a boolean that meets the criteria', () => { |
| 26 | + verify(true, true, 'pass') |
| 27 | + verify(false, false, 'pass') |
| 28 | +}) |
| 29 | + |
| 30 | +test('return fail if input does not meet the criteria', () => { |
| 31 | + verify(true, false, 'fail') |
| 32 | + verify(false, 'true', 'fail') |
| 33 | +}) |
| 34 | + |
| 35 | +test('return error if inputs are not in expected format', async () => { |
| 36 | + const rule = { boolean: { match: true } } |
| 37 | + const input = ['true'] |
| 38 | + try { |
| 39 | + const config = BooleanMatch.process(filterContext, filter, input, rule) |
| 40 | + expect(config).toBeUndefined() |
| 41 | + } catch (e) { |
| 42 | + expect(e.message).toBe('Input type invalid, expected strings "true" or "false", or boolean literal `true` or `false` as input') |
| 43 | + } |
| 44 | +}) |
0 commit comments