|
| 1 | +import checkRequirement from '../../src/extensions/functions/checkRequirement' |
| 2 | +import { toPairs } from 'ramda' |
| 3 | +const examplePlugin = require('examplePlugin') |
| 4 | +const mockContext = examplePlugin(require('mockContext')) |
| 5 | + |
| 6 | +describe('checkRequirement Plugins', () => { |
| 7 | + test('successful CUSTOM rule check', async () => { |
| 8 | + const rule = toPairs({ |
| 9 | + TestRequirement: [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkThing' }], |
| 10 | + })[0] |
| 11 | + const result = await checkRequirement(rule, mockContext) |
| 12 | + expect(result).toEqual([[]]) |
| 13 | + }) |
| 14 | + |
| 15 | + test('failed CUSTOM rule check', async () => { |
| 16 | + const rule = toPairs({ |
| 17 | + TestRequirement: [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkSecondThing' }], |
| 18 | + })[0] |
| 19 | + const result = await checkRequirement(rule, mockContext) |
| 20 | + expect(result).toEqual(['Boooo failed check']) |
| 21 | + }) |
| 22 | + |
| 23 | + test('failed to find plugin', async () => { |
| 24 | + const rule = toPairs({ |
| 25 | + TestRequirement: [{ rule: 'custom', plugin: 'I do not exist', name: 'checkSecondThing' }], |
| 26 | + })[0] |
| 27 | + const result = await checkRequirement(rule, mockContext) |
| 28 | + expect(result).toEqual(["Plugin not found 'I do not exist'"]) |
| 29 | + }) |
| 30 | + |
| 31 | + test('failed to find check function', async () => { |
| 32 | + const rule = toPairs({ |
| 33 | + TestRequirement: [{ rule: 'custom', plugin: 'Example Plugin', name: 'notRealName' }], |
| 34 | + })[0] |
| 35 | + const result = await checkRequirement(rule, mockContext) |
| 36 | + expect(result).toEqual(["NOT FOUND: Custom rule from 'Example Plugin' plugin with check function 'notRealName'"]) |
| 37 | + }) |
| 38 | + |
| 39 | + test('failed CUSTOM rule with custom message', async () => { |
| 40 | + const error = 'CUSTOM ERROR' |
| 41 | + const rule = toPairs({ |
| 42 | + TestRequirement: [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkSecondThing', error }], |
| 43 | + })[0] |
| 44 | + const result = await checkRequirement(rule, mockContext) |
| 45 | + expect(result).toEqual([error]) |
| 46 | + }) |
| 47 | + |
| 48 | +}) |
0 commit comments