|
1 | 1 | const _isIP = require('../../lib/common/utils/isIP');
|
| 2 | +const { includesConf } = require('./utils'); |
2 | 3 | const assert = require('assert');
|
3 | 4 |
|
4 | 5 | describe('test/test.js', () => {
|
@@ -76,3 +77,150 @@ describe('test/test.js', () => {
|
76 | 77 | assert.equal(_isIP('G:0f:0F:FFFF:5:6:7:8'), false);
|
77 | 78 | });
|
78 | 79 | });
|
| 80 | + |
| 81 | +describe('test/includesConf.js', () => { |
| 82 | + it('shoud return true when conf-item is primitive value', () => { |
| 83 | + const data = { |
| 84 | + testNum: 1, |
| 85 | + testStr: '2', |
| 86 | + testUndefined: undefined, |
| 87 | + testNull: null, |
| 88 | + testExtral: 'extral' |
| 89 | + }; |
| 90 | + const conf = { |
| 91 | + testNum: 1, |
| 92 | + testStr: '2', |
| 93 | + testUndefined: undefined, |
| 94 | + testNull: null |
| 95 | + }; |
| 96 | + assert(includesConf(data, conf)); |
| 97 | + }); |
| 98 | + it('shoud return false when conf-item is primitive value and conf not in data', () => { |
| 99 | + const data = { |
| 100 | + testNum: 1, |
| 101 | + testStr: '2', |
| 102 | + testUndefined: undefined, |
| 103 | + testNull: null, |
| 104 | + testExtral: 'extral' |
| 105 | + }; |
| 106 | + const conf = { |
| 107 | + testNonExist: 1 |
| 108 | + }; |
| 109 | + const conf1 = { |
| 110 | + testExtral: 'test' |
| 111 | + }; |
| 112 | + assert(!includesConf(data, conf)); |
| 113 | + assert(!includesConf(data, conf1)); |
| 114 | + }); |
| 115 | + it('shoud return true when conf-item is simple Array', () => { |
| 116 | + const data = { |
| 117 | + testArray1: ['extral', '1', 0, undefined], |
| 118 | + testExtral: 'extral' |
| 119 | + }; |
| 120 | + const conf = { |
| 121 | + testArray1: ['1', 0, undefined] |
| 122 | + }; |
| 123 | + assert(includesConf(data, conf)); |
| 124 | + }); |
| 125 | + it('shoud return false when conf-item is simple Array and conf not in data', () => { |
| 126 | + const data = { |
| 127 | + testArray1: ['extral', '1', 0, undefined], |
| 128 | + testExtral: 'extral' |
| 129 | + }; |
| 130 | + const conf = { |
| 131 | + testArray1: ['1', 0, undefined, 'noexist'] |
| 132 | + }; |
| 133 | + assert(!includesConf(data, conf)); |
| 134 | + }); |
| 135 | + it('shoud return true when conf-item is simple Object', () => { |
| 136 | + const data = { |
| 137 | + testObject: { test: 1, test1: 2 }, |
| 138 | + testExtral: 'extral' |
| 139 | + }; |
| 140 | + const conf = { |
| 141 | + testObject: { test: 1 } |
| 142 | + }; |
| 143 | + assert(includesConf(data, conf)); |
| 144 | + }); |
| 145 | + it('shoud return false when conf-item is simple Object and conf not in data', () => { |
| 146 | + const data = { |
| 147 | + testObject: { test: 1, test1: 2 }, |
| 148 | + testExtral: 'extral' |
| 149 | + }; |
| 150 | + const conf = { |
| 151 | + testObject: { test: 1, noExist: 'test' } |
| 152 | + }; |
| 153 | + assert(!includesConf(data, conf)); |
| 154 | + }); |
| 155 | + it('shoud return true when conf-item is complex Array', () => { |
| 156 | + const data = { |
| 157 | + testArray: [{ test: 1, test1: 2 }, { test: 2 }], |
| 158 | + testExtral: 'extral' |
| 159 | + }; |
| 160 | + const conf = { |
| 161 | + testArray: [{ test: 2 }] |
| 162 | + }; |
| 163 | + assert(includesConf(data, conf)); |
| 164 | + }); |
| 165 | + it('shoud return false when conf-item is complex Array and conf not in data', () => { |
| 166 | + const data = { |
| 167 | + testArray: [{ test: 1, test1: 2 }, { test: 2 }], |
| 168 | + testExtral: 'extral' |
| 169 | + }; |
| 170 | + const conf = { |
| 171 | + testArray: [{ test: 0 }] |
| 172 | + }; |
| 173 | + assert(!includesConf(data, conf)); |
| 174 | + }); |
| 175 | + it('shoud return true when conf-item is complex Object', () => { |
| 176 | + const data = { |
| 177 | + testObject: { |
| 178 | + test01: { |
| 179 | + test11: { |
| 180 | + a: 1 |
| 181 | + }, |
| 182 | + test12: 1123 |
| 183 | + }, |
| 184 | + test02: [{ test11: 1 }, '123', 0, undefined, '456'] |
| 185 | + }, |
| 186 | + testExtral: 'extral' |
| 187 | + }; |
| 188 | + const conf = { |
| 189 | + testObject: { |
| 190 | + test01: { |
| 191 | + test11: { |
| 192 | + a: 1 |
| 193 | + } |
| 194 | + }, |
| 195 | + test02: [{ test11: 1 }, '123', 0, undefined] |
| 196 | + } |
| 197 | + }; |
| 198 | + assert(includesConf(data, conf)); |
| 199 | + }); |
| 200 | + it('shoud return false when conf-item is complex Object and conf not in data', () => { |
| 201 | + const data = { |
| 202 | + testObject: { |
| 203 | + test01: { |
| 204 | + test11: { |
| 205 | + a: 1 |
| 206 | + }, |
| 207 | + test12: 1123 |
| 208 | + }, |
| 209 | + test02: [{ test11: 1 }, '123', 0, undefined, '456'] |
| 210 | + }, |
| 211 | + testExtral: 'extral' |
| 212 | + }; |
| 213 | + const conf = { |
| 214 | + testObject: { |
| 215 | + test01: { |
| 216 | + test11: { |
| 217 | + a: 1, |
| 218 | + b: 'test cpx' |
| 219 | + } |
| 220 | + }, |
| 221 | + test02: [{ test11: 1 }, '123', 0, undefined] |
| 222 | + } |
| 223 | + }; |
| 224 | + assert(!includesConf(data, conf)); |
| 225 | + }); |
| 226 | +}); |
0 commit comments