|
| 1 | +import { it, describe, expect } from '@jest/globals'; |
| 2 | +import { isBlockedValueInParams } from './isBlockedValue'; |
| 3 | +import type { BlockList } from '../../types/BlockList'; |
| 4 | + |
| 5 | +describe('should be disabled', () => { |
| 6 | + it('empty block list options', () => { |
| 7 | + const blockList: BlockList = {}; |
| 8 | + |
| 9 | + expect(isBlockedValueInParams(blockList, {})).toBeFalsy(); |
| 10 | + }); |
| 11 | + |
| 12 | + it('without list', () => { |
| 13 | + const blockList: BlockList = { |
| 14 | + watchVariable: 'email', |
| 15 | + }; |
| 16 | + |
| 17 | + expect(isBlockedValueInParams(blockList, {})).toBeFalsy(); |
| 18 | + }); |
| 19 | + |
| 20 | + it('without watchVariable', () => { |
| 21 | + const blockList: BlockList = { |
| 22 | + list: ['test@emailjs.com'], |
| 23 | + }; |
| 24 | + |
| 25 | + expect(isBlockedValueInParams(blockList, {})).toBeFalsy(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('without data', () => { |
| 29 | + const blockList: BlockList = { |
| 30 | + watchVariable: 'email', |
| 31 | + list: ['test@emailjs.com'], |
| 32 | + }; |
| 33 | + |
| 34 | + expect(isBlockedValueInParams(blockList, {})).toBeFalsy(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('wrong type', () => { |
| 38 | + const blockList: BlockList = { |
| 39 | + watchVariable: 'email', |
| 40 | + list: ['test@emailjs.com'], |
| 41 | + }; |
| 42 | + |
| 43 | + expect( |
| 44 | + isBlockedValueInParams(blockList, { |
| 45 | + email: ['item', 'item'], |
| 46 | + }), |
| 47 | + ).toBeFalsy(); |
| 48 | + }); |
| 49 | + |
| 50 | + it('not found in the list', () => { |
| 51 | + const blockList: BlockList = { |
| 52 | + watchVariable: 'email', |
| 53 | + list: ['test@emailjs.com', 'bar@emailjs.com'], |
| 54 | + }; |
| 55 | + |
| 56 | + expect( |
| 57 | + isBlockedValueInParams(blockList, { |
| 58 | + email: 'foo@emailjs.com', |
| 59 | + }), |
| 60 | + ).toBeFalsy(); |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
| 64 | +describe('should be enabled', () => { |
| 65 | + it('template params', () => { |
| 66 | + const blockList: BlockList = { |
| 67 | + watchVariable: 'email', |
| 68 | + list: ['test@emailjs.com', 'foo@emailjs.com', 'bar@emailjs.com'], |
| 69 | + }; |
| 70 | + |
| 71 | + expect( |
| 72 | + isBlockedValueInParams(blockList, { |
| 73 | + email: 'test@emailjs.com', |
| 74 | + other: 'other data', |
| 75 | + }), |
| 76 | + ).toBeTruthy(); |
| 77 | + }); |
| 78 | + |
| 79 | + it('form data', () => { |
| 80 | + const blockList: BlockList = { |
| 81 | + watchVariable: 'email', |
| 82 | + list: ['test@emailjs.com', 'foo@emailjs.com', 'bar@emailjs.com'], |
| 83 | + }; |
| 84 | + |
| 85 | + const formData = new FormData(); |
| 86 | + formData.append('email', 'test@emailjs.com'); |
| 87 | + formData.append('other', 'other data'); |
| 88 | + |
| 89 | + expect(isBlockedValueInParams(blockList, formData)).toBeTruthy(); |
| 90 | + }); |
| 91 | +}); |
0 commit comments