@ammar-ahmed/automation-app-bot
Version:
Automation made easy and fun OH Yeah!
87 lines (77 loc) • 2.79 kB
JavaScript
const max = require('../../../../../lib/validators/options_processor/options/max')
const validatorContext = {
name: 'label',
supportedOptions: [
'and',
'or',
'begins_with',
'ends_with',
'max',
'min',
'must_exclude',
'must_include',
'no_empty',
'required']
}
describe('max option applied to arrays', () => {
test('return pass if input meets the criteria', async () => {
const rule = { max: { count: 3 } }
const input = ['A', 'B']
const res = max.process(validatorContext, input, rule)
expect(res.status).toBe('pass')
})
test('return pass if input exactly meets the criteria', async () => {
const rule = { max: { count: 3 } }
const input = ['A', 'B', 'C']
const res = max.process(validatorContext, input, rule)
expect(res.status).toBe('pass')
})
test('return fail if input does not meet the criteria', async () => {
const rule = { max: { count: 3 } }
const input = ['A', 'B', 'C', 'D']
const res = max.process(validatorContext, input, rule)
expect(res.status).toBe('fail')
})
})
describe('max option applied to integers', () => {
test('return pass if input meets the criteria', async () => {
const rule = { max: { count: 20 } }
const input = 10
const res = max.process(validatorContext, input, rule)
expect(res.status).toBe('pass')
})
test('return pass if input exactly meets criteria', async () => {
const rule = { max: { count: 10 } }
const input = 10
const res = max.process(validatorContext, input, rule)
expect(res.status).toBe('pass')
})
test('return fail if input does not meet the criteria', async () => {
const rule = { max: { count: 10 } }
const input = 20
const res = max.process(validatorContext, input, rule)
expect(res.status).toBe('fail')
})
})
describe('max option configured incorrectly', () => {
test('return error if rule config is not in expected format', async () => {
const rule = { max: { regex: 3 } }
const input = ['the test']
try {
const config = max.process(validatorContext, input, rule)
expect(config).toBeUndefined()
} catch (e) {
expect(e.message).toBe('Failed to run the test because \'count\' is not provided for \'max\' option. Please check README for more information about configuration')
}
})
test('return error if input is not supported type', async () => {
const rule = { max: { count: 3 } }
const input = 'hello'
try {
const config = max.process(validatorContext, input, rule)
expect(config).toBeUndefined()
} catch (e) {
expect(e.message).toBe('Input type invalid, expected Array or Integer as input')
}
})
})