How to use validateSpecs method in Best

Best JavaScript code snippet using best

specs.js

Source:specs.js Github

copy

Full Screen

...21 "bar'foo",22 "foo)bar"23]24function boolValuePropertyTest(t, specs, key, path) {25 validateSpecs({ ...specs, [key]: true })26 validateSpecs({ ...specs, [key]: false })27 var error = t.throws(() => {28 validateSpecs({...specs, [key]: 42})29 }, {instanceOf: ValidationError})30 t.deepEqual(error.path, path.concat(key))31 t.is(error.message, "value must be a bool")32 var error = t.throws(() => {33 validateSpecs({...specs, [key]: "Hello world!"})34 }, {instanceOf: ValidationError})35 t.deepEqual(error.path, path.concat(key))36 t.is(error.message, "value must be a bool")37}38function numberValuePropertyTest(t, specs, key, path) {39 // To be written.40}41function stringValuePropertyTest(t, specs, key, path) {42 validateSpecs({ ...specs, [key]: "Hello world!" })43 var error = t.throws(() => {44 validateSpecs({...specs, [key]: false})45 }, {instanceOf: ValidationError})46 t.deepEqual(error.path, path.concat(key))47 t.is(error.message, "value must be a string")48 error = t.throws(() => {49 validateSpecs({...specs, [key]: true})50 }, {instanceOf: ValidationError})51 t.deepEqual(error.path, path.concat(key))52 t.is(error.message, "value must be a string")53 error = t.throws(() => {54 validateSpecs({...specs, [key]: 42})55 }, {instanceOf: ValidationError})56 t.deepEqual(error.path, path.concat(key))57 t.is(error.message, "value must be a string")58}59function namePropertyTest(t, specs) {60 stringValuePropertyTest(t, specs, "name", [])61}62function descriptionPropertyTest(t, specs) {63 stringValuePropertyTest(t, specs, "description", [])64}65function optionPropertyTest(t, specs, path) {66 boolValuePropertyTest(t, specs, "option", path)67}68function missingPropertyTest(t, specs, property) {69 const error = t.throws(() => {70 validateSpecs(specs)71 }, {instanceOf: ValidationError})72 t.deepEqual(error.path, [])73 t.is(error.message, `'${property}' property is missing`)74}75function additionalPropertiesTest(t, specs) {76 var errors = []77 validateSpecs({ ...specs, foo: 'bar', bar: 'foo' }, errors=errors)78 t.deepEqual(errors[0].path, [])79 t.is(errors[0].message, "'foo' property is unexpected")80 t.deepEqual(errors[1].path, [])81 t.is(errors[1].message, "'bar' property is unexpected")82}83function lengthPropertyTest(t, specs) {84 validateSpecs({ ...specs, length: 42 })85 validateSpecs({ ...specs, length: { minimum: 42 } })86 validateSpecs({ ...specs, length: { maximum: 42 } })87 validateSpecs({ ...specs, length: { minimum: 0, maximum: 42 } })88 var error = t.throws(() => {89 validateSpecs({ ...specs, length: -1 })90 }, {instanceOf: ValidationError})91 t.deepEqual(error.path, ['length'])92 t.is(error.message, "must be greater or equal to zero")93 var warnings = []94 validateSpecs({ ...specs, length: 42.5 }, undefined, warnings)95 t.is(warnings.length, 1)96 t.deepEqual(warnings[0].path, ['length'])97 t.is(warnings[0].message, "should be an integer (got decimal)")98 var error = t.throws(() => {99 validateSpecs({ ...specs, length: { minimum: -1 }})100 }, {instanceOf: ValidationError})101 t.deepEqual(error.path, ['length', 'minimum'])102 t.is(error.message, "must be greater or equal to zero")103 var warnings = []104 validateSpecs({ ...specs, length: { minimum: 42.5 }}, undefined, warnings)105 t.is(warnings.length, 1)106 t.deepEqual(warnings[0].path, ['length', 'minimum'])107 t.is(warnings[0].message, "should be an integer (got decimal)")108 var error = t.throws(() => {109 validateSpecs({ ...specs, length: { maximum: -1 }})110 }, {instanceOf: ValidationError})111 t.deepEqual(error.path, ['length', 'maximum'])112 t.is(error.message, "must be greater or equal to zero")113 var warnings = []114 validateSpecs({ ...specs, length: { maximum: 42.5 }}, undefined, warnings)115 t.is(warnings.length, 1)116 t.deepEqual(warnings[0].path, ['length', 'maximum'])117 t.is(warnings[0].message, "should be an integer (got decimal)")118 for (const [minimum, maximum] of [[42, 0], [1, 0]]) {119 var error = t.throws(() => {120 validateSpecs({ ...specs, length: { minimum, maximum }})121 }, {instanceOf: ValidationError})122 t.deepEqual(error.path, ['length'])123 t.is(error.message, "minimum must be lower than maximum")124 }125 var error = t.throws(() => {126 validateSpecs({ ...specs, length: { foo: 'bar' }})127 }, {instanceOf: ValidationError})128 t.deepEqual(error.path, ['length'])129 t.is(error.message, "'foo' property is unexpected")130}131test('type-block', t => {132 // type blocks must be an object133 for (const specs in [false, true, 42, 42.5, "Hello world!"]) {134 var error = t.throws(() => {135 validateSpecs(specs)136 }, {instanceOf: ValidationError})137 t.deepEqual(error.path, [])138 t.is(error.message, "value must be an object")139 }140 // 'type' property is missing141 missingPropertyTest(t, {}, 'type')142 // value of 'type' property is incorrect143 var error = t.throws(() => {144 validateSpecs({ type: 'foo' })145 }, {instanceOf: ValidationError})146 t.deepEqual(error.path, [])147 t.is(error.message, "value of 'type' is incorrect")148})149test('flag-type', t => {150 // test minimal specs151 var specs = { type: 'flag' }152 validateSpecs(specs)153 t.pass()154 // test 'name' and 'description' properties155 namePropertyTest(t, specs)156 descriptionPropertyTest(t, specs)157 // test the 'option' property158 optionPropertyTest(t, specs, [])159 // test additional properties160 additionalPropertiesTest(t, specs)161 // test lazy validation162 var specs = {163 type: 'flag' ,164 option: 42,165 foo: 'bar'166 }167 var errors = []168 validateSpecs(specs, errors)169 t.deepEqual(errors[0].path, [])170 t.is(errors[0].message, "'foo' property is unexpected")171 t.deepEqual(errors[1].path, ['option'])172 t.is(errors[1].message, "value must be a bool")173})174test('number-type', t => {175 // test minimal specs176 var specs = { type: 'number' }177 validateSpecs(specs)178 // test 'name' and 'description' properties179 namePropertyTest(t, specs)180 descriptionPropertyTest(t, specs)181 // test 'decimal' property182 validateSpecs({ ...specs, decimal: false })183 validateSpecs({ ...specs, decimal: true })184 for (const invalidValue in [42, 42.5, "Hello world!"]) {185 var error = t.throws(() => {186 validateSpecs({ ...specs, decimal: invalidValue })187 }, {instanceOf: ValidationError})188 t.deepEqual(error.path, ['decimal'])189 t.is(error.message, "value must be a bool")190 }191 // test 'minimum' property192 validateSpecs({ ...specs, minimum: 42 })193 validateSpecs({ ...specs, minimum: { value: 42 }})194 validateSpecs({ ...specs, minimum: { exclusive: false, value: 42 }})195 validateSpecs({ ...specs, minimum: { exclusive: true, value: 42 }})196 for (const invalidValue of [false, true, "Hello world!"]) {197 var error = t.throws(() => {198 validateSpecs({ ...specs, minimum: invalidValue })199 }, {instanceOf: ValidationError})200 t.deepEqual(error.path, ['minimum'])201 t.is(error.message, "value must be either a number or an object")202 }203 var error = t.throws(() => {204 validateSpecs({ ...specs, minimum: { exclusive: false}})205 }, {instanceOf: ValidationError})206 t.deepEqual(error.path, ['minimum'])207 t.is(error.message, "'value' property is missing")208 for (const invalidValue of [42, 42.5, "Hello world!"]) {209 var error = t.throws(() => {210 validateSpecs({ ...specs, minimum: { exclusive: invalidValue, value: 42 }})211 }, {instanceOf: ValidationError})212 t.deepEqual(error.path, ['minimum', 'exclusive'])213 t.is(error.message, "value must be a bool")214 }215 for (const invalidValue of [false, true, "Hello world!"]) {216 var error = t.throws(() => {217 validateSpecs({ ...specs, minimum: { exclusive: false, value: invalidValue }})218 }, {instanceOf: ValidationError})219 t.deepEqual(error.path, ['minimum', 'value'])220 t.is(error.message, "value must be a number")221 }222 var error = t.throws(() => {223 validateSpecs({ ...specs, minimum: { value: false, foo: 'bar' }})224 }, {instanceOf: ValidationError})225 t.deepEqual(error.path, ['minimum'])226 t.is(error.message, "'foo' property is unexpected")227 // test 'maximum' property228 validateSpecs({ ...specs, maximum: 42 })229 validateSpecs({ ...specs, maximum: { value: 42 }})230 validateSpecs({ ...specs, maximum: { exclusive: false, value: 42 }})231 validateSpecs({ ...specs, maximum: { exclusive: true, value: 42 }})232 for (const invalidValue of [false, true, "Hello world!"]) {233 var error = t.throws(() => {234 validateSpecs({ ...specs, maximum: invalidValue })235 }, {instanceOf: ValidationError})236 t.deepEqual(error.path, ['maximum'])237 t.is(error.message, "value must be either a number or an object")238 }239 var error = t.throws(() => {240 validateSpecs({ ...specs, maximum: { exclusive: false}})241 }, {instanceOf: ValidationError})242 t.deepEqual(error.path, ['maximum'])243 t.is(error.message, "'value' property is missing")244 for (const invalidValue of [42, 42.5, "Hello world!"]) {245 var error = t.throws(() => {246 validateSpecs({ ...specs, maximum: { exclusive: invalidValue, value: 42 }})247 }, {instanceOf: ValidationError})248 t.deepEqual(error.path, ['maximum', 'exclusive'])249 t.is(error.message, "value must be a bool")250 }251 for (const invalidValue of [false, true, "Hello world!"]) {252 var error = t.throws(() => {253 validateSpecs({ ...specs, maximum: { exclusive: false, value: invalidValue }})254 }, {instanceOf: ValidationError})255 t.deepEqual(error.path, ['maximum', 'value'])256 t.is(error.message, "value must be a number")257 }258 var error = t.throws(() => {259 validateSpecs({ ...specs, maximum: { value: false, foo: 'bar' }})260 }, {instanceOf: ValidationError})261 t.deepEqual(error.path, ['maximum'])262 t.is(error.message, "'foo' property is unexpected")263 // test minimum must be lower than maximum264 for (const [minimum, maximum] of [[42, 0], [-9, -10], [1, -1]]) {265 var error = t.throws(() => {266 validateSpecs({ ...specs, minimum, maximum })267 }, {instanceOf: ValidationError})268 t.deepEqual(error.path, [])269 t.is(error.message, "minimum must be lower than maximum")270 }271 // test the 'option' property272 optionPropertyTest(t, specs, [])273 // test additional properties274 additionalPropertiesTest(t, specs)275 // test lazy validation276 var specs = {277 type: 'number',278 decimal: 'foo',279 minimum: false,280 maximum: "Hello world!",281 option: 42,282 foo: 'bar'283 }284 var errors = []285 validateSpecs(specs, errors)286 t.deepEqual(errors[0].path, [])287 t.is(errors[0].message, "'foo' property is unexpected")288 t.deepEqual(errors[1].path, ['decimal'])289 t.is(errors[1].message, "value must be a bool")290 t.deepEqual(errors[2].path, ['minimum'])291 t.is(errors[2].message, "value must be either a number or an object")292 t.deepEqual(errors[3].path, ['maximum'])293 t.is(errors[3].message, "value must be either a number or an object")294 t.deepEqual(errors[4].path, ['option'])295 t.is(errors[4].message, "value must be a bool")296})297test('string-type', t => {298 // test minimal specs299 var specs = { type: 'string' }300 validateSpecs(specs)301 // test 'name' and 'description' properties302 namePropertyTest(t, specs)303 descriptionPropertyTest(t, specs)304 // test the 'length' property305 lengthPropertyTest(t, specs)306 // test the 'pattern' property307 validateSpecs({ ...specs, pattern: "^[a-z]+(-[a-z]+)*$"})308 stringValuePropertyTest(t, specs, 'pattern', [])309 // test the 'option' property310 optionPropertyTest(t, specs, [])311 // test additional properties312 additionalPropertiesTest(t, specs)313 // test lazy validation314 var specs = {315 type: 'string',316 length: false,317 pattern: 42,318 option: 42,319 foo: 'bar'320 }321 var errors = []322 validateSpecs(specs, errors)323 t.deepEqual(errors[0].path, [])324 t.is(errors[0].message, "'foo' property is unexpected")325 t.deepEqual(errors[1].path, ['length'])326 t.is(errors[1].message, "value must be either a number or an object")327 t.deepEqual(errors[2].path, ['pattern'])328 t.is(errors[2].message, "value must be a string")329 t.deepEqual(errors[3].path, ['option'])330 t.is(errors[3].message, "value must be a bool")331})332test('array-type', t => {333 // test minimal specs334 var specs = {335 type: 'array',336 value: {337 type: 'string'338 }339 }340 missingPropertyTest(t, { type: 'array' }, 'value')341 validateSpecs({ type: 'array', value: { type: 'flag' }})342 validateSpecs({ type: 'array', value: { type: 'number' }})343 validateSpecs(specs)344 // test 'name' and 'description' properties345 namePropertyTest(t, specs)346 descriptionPropertyTest(t, specs)347 // test the 'value' property348 var error = t.throws(() => {349 validateSpecs({ type: 'array', value: { type: 'foo' } })350 }, {instanceOf: ValidationError})351 t.deepEqual(error.path, ['[]'])352 t.is(error.message, "value of 'type' is incorrect")353 // test the 'length' property354 lengthPropertyTest(t, specs)355 // test the 'option' property356 optionPropertyTest(t, specs, [])357 // test additional properties358 additionalPropertiesTest(t, specs)359 // test nested arrays360 const nestedArrays = {361 type: 'array',362 value: {363 type: 'array',364 value: {365 type: 'array',366 value: { type: 'string' }367 }368 }369 }370 validateSpecs(nestedArrays)371 // test lazy validation372 var specs = {373 type: 'array',374 value: 42,375 length: false,376 option: 42,377 foo: 'bar'378 }379 var errors = []380 validateSpecs(specs, errors)381 t.deepEqual(errors[0].path, [])382 t.is(errors[0].message, "'foo' property is unexpected")383 t.deepEqual(errors[1].path, ['[]'])384 t.is(errors[1].message, "value must be an object")385 t.deepEqual(errors[2].path, ['length'])386 t.is(errors[2].message, "value must be either a number or an object")387 t.deepEqual(errors[3].path, ['option'])388 t.is(errors[3].message, "value must be a bool")389})390test('object-type', t => {391 // test minimal specs392 var specs = {393 type: 'object',394 key: 'string',395 value: {396 type: 'string'397 }398 }399 validateSpecs(specs)400 missingPropertyTest(t, {type: 'object', value: { type: 'string'}}, 'key')401 missingPropertyTest(t, {type: 'object', key: 'string'}, 'value')402 // test 'name' and 'description' properties403 namePropertyTest(t, specs)404 descriptionPropertyTest(t, specs)405 // test the 'key' property406 for (const key of ['integer', 'string']) {407 validateSpecs({ type: 'object', key: key, value: { type: 'string' } })408 }409 var error = t.throws(() => {410 validateSpecs({ type: 'object', key: 'foo', value: { type: 'string' } })411 }, {instanceOf: ValidationError})412 t.deepEqual(error.path, [])413 t.is(error.message, "value of 'key' must be either 'integer' or 'string'")414 // test the 'value' property415 var error = t.throws(() => {416 validateSpecs({ type: 'object', value: { type: 'foo' } })417 }, {instanceOf: ValidationError})418 t.deepEqual(error.path, ['{}'])419 t.is(error.message, "value of 'type' is incorrect")420 // test the 'length' property421 lengthPropertyTest(t, specs)422 // test the 'option' property423 optionPropertyTest(t, specs, [])424 // test additional properties425 additionalPropertiesTest(t, specs)426 // test nested objects427 const nestedObjects = {428 type: 'object',429 key: 'integer',430 value: {431 type: 'object',432 key: 'string',433 value: {434 type: 'string'435 }436 }437 }438 validateSpecs(nestedObjects)439 // test lazy validation440 var specs = {441 type: 'object',442 key: 'foo',443 value: 42,444 length: false,445 option: 42,446 foo: 'bar'447 }448 var errors = []449 validateSpecs(specs, errors)450 t.deepEqual(errors[0].path, [])451 t.is(errors[0].message, "'foo' property is unexpected")452 t.deepEqual(errors[1].path, ['{}'])453 t.is(errors[1].message, "value must be an object")454 t.deepEqual(errors[2].path, [])455 t.is(errors[2].message, "value of 'key' must be either 'integer' or 'string'")456 t.deepEqual(errors[3].path, ['length'])457 t.is(errors[3].message, "value must be either a number or an object")458 t.deepEqual(errors[4].path, ['option'])459 t.is(errors[4].message, "value must be a bool")460})461test('tuple-type', t => {462 // test minimal specs463 var specs = {464 type: 'tuple',465 items: [466 { type: 'flag' },467 { type: 'number' },468 { type: 'string' }469 ]470 }471 validateSpecs(specs)472 missingPropertyTest(t, { type: 'tuple'}, 'items')473 // test 'name' and 'description' properties474 namePropertyTest(t, specs)475 descriptionPropertyTest(t, specs)476 // test the 'items' property477 for (const value in [false, true, 42, 42.5, "Hello world!"]) {478 const error = t.throws(() => {479 validateSpecs({ type: 'tuple', items: value })480 }, {instanceOf: ValidationError})481 t.deepEqual(error.path, ['items'])482 t.is(error.message, "value must be an array")483 }484 var error = t.throws(() => {485 validateSpecs({ type: 'tuple', items: [] })486 }, {instanceOf: ValidationError})487 t.deepEqual(error.path, ['items'])488 t.is(error.message, "must contain at least one value")489 for (const value in [false, true, 42, 42.5, "Hello world!"]) {490 const error = t.throws(() => {491 validateSpecs({ type: 'tuple', items: [value] })492 }, {instanceOf: ValidationError})493 t.deepEqual(error.path, ['<0>'])494 t.is(error.message, "value must be an object")495 }496 error = t.throws(() => {497 validateSpecs({ type: 'tuple', items: [{ type: 'foo' }] })498 }, {instanceOf: ValidationError})499 t.deepEqual(error.path, ['<0>'])500 t.is(error.message, "value of 'type' is incorrect")501 // test the 'option' property502 optionPropertyTest(t, specs, [])503 // test additional properties504 additionalPropertiesTest(t, specs)505 // test nested tuples506 const nestedTuples = {507 type: 'tuple',508 items: [509 {510 type: 'tuple',511 items: [512 {513 type: 'tuple',514 items: [{ type: 'string' }]515 }516 ]517 }518 ]519 }520 validateSpecs(nestedTuples)521 // test lazy validation522 var specs = {523 type: 'tuple',524 items: [525 { type: 'foo' },526 { type: 'bar' },527 { type: 'quz' }528 ],529 option: 42,530 foo: 'bar'531 }532 var errors = []533 validateSpecs(specs, errors)534 t.deepEqual(errors[0].path, [])535 t.is(errors[0].message, "'foo' property is unexpected")536 t.deepEqual(errors[1].path, ['<0>'])537 t.is(errors[1].message, "value of 'type' is incorrect")538 t.deepEqual(errors[2].path, ['<1>'])539 t.is(errors[2].message, "value of 'type' is incorrect")540 t.deepEqual(errors[3].path, ['<2>'])541 t.is(errors[3].message, "value of 'type' is incorrect")542 t.deepEqual(errors[4].path, ['option'])543 t.is(errors[4].message, "value must be a bool")544})545test('map-type', t => {546 // test minimal specs547 var specs = {548 type: 'map',549 fields: {550 foo: { type: 'flag' },551 bar: { type: 'number' },552 quz: { type: 'string' }553 }554 }555 validateSpecs(specs)556 missingPropertyTest(t, { type: 'map'}, 'fields')557 // test 'name' and 'description' properties558 namePropertyTest(t, specs)559 descriptionPropertyTest(t, specs)560 // test the 'fields' property561 for (const value in [false, true, 42, 42.5, "Hello world!"]) {562 const error = t.throws(() => {563 validateSpecs({ type: 'map', fields: value })564 }, {instanceOf: ValidationError})565 t.deepEqual(error.path, ['fields'])566 t.is(error.message, "value must be an object")567 }568 var error = t.throws(() => {569 validateSpecs({ type: 'map', fields: {} })570 }, {instanceOf: ValidationError})571 t.deepEqual(error.path, ['fields'])572 t.is(error.message, "must contain at least one field")573 for (const name of VALID_NAMES) {574 const specs = {575 type: 'map',576 fields: {577 [name]: {578 type: 'flag'579 }580 }581 }582 validateSpecs(specs)583 }584 for (const name of INVALID_NAMES) {585 const specs = {586 type: 'map',587 fields: {588 [name]: {589 type: 'flag'590 }591 }592 }593 const error = t.throws(() => {594 validateSpecs(specs)595 }, {instanceOf: ValidationError})596 t.deepEqual(error.path, ['fields'])597 t.is(error.message, `'${name}' is an incorrect key name`)598 }599 for (const value in [false, true, 42, 42.5, "Hello world!"]) {600 const error = t.throws(() => {601 validateSpecs({ type: 'map', fields: { foo: value } })602 }, {instanceOf: ValidationError})603 t.deepEqual(error.path, ['$foo'])604 t.is(error.message, "value must be an object")605 }606 error = t.throws(() => {607 validateSpecs({ type: 'map', fields: { foo: { type: 'bar' } }})608 }, {instanceOf: ValidationError})609 t.deepEqual(error.path, ['$foo'])610 t.is(error.message, "value of 'type' is incorrect")611 // test the 'option' property612 optionPropertyTest(t, specs, [])613 // test additional properties614 additionalPropertiesTest(t, specs)615 // test nested maps616 const nestedMaps = {617 type: 'map',618 fields: {619 foo: {620 type: 'map',621 fields: {622 bar: {623 type: 'map',624 fields: {625 quz: { type: 'string' }626 }627 }628 }629 }630 }631 }632 validateSpecs(nestedMaps)633 // test lazy validation634 var specs = {635 type: 'map',636 fields: {637 '@foo': { type: 'flag' },638 bar: { type: 'foo' }639 },640 option: 42,641 foo: 'bar'642 }643 var errors = []644 validateSpecs(specs, errors)645 t.deepEqual(errors[0].path, [])646 t.is(errors[0].message, "'foo' property is unexpected")647 t.deepEqual(errors[1].path, ['fields'])648 t.is(errors[1].message, "'@foo' is an incorrect key name")649 t.deepEqual(errors[2].path, ['$bar'])650 t.is(errors[2].message, "value of 'type' is incorrect")651 t.deepEqual(errors[3].path, ['option'])652 t.is(errors[3].message, "value must be a bool")653})654test('enum-type', t => {655 // test minimal specs656 var specs = {657 type: 'enum',658 values: ['foo', 'bar', 'quz']659 }660 validateSpecs(specs)661 var error = t.throws(() => {662 validateSpecs({type: 'enum'})663 }, {instanceOf: ValidationError})664 t.deepEqual(error.path, [])665 t.is(error.message, "'values' property is missing")666 // test the 'values' property667 for (const value in [true, false, 42, 42.5, "Hello world!"]) {668 var error = t.throws(() => {669 validateSpecs({type: 'enum', values: value})670 }, {instanceOf: ValidationError})671 t.deepEqual(error.path, ['values'])672 t.is(error.message, "value must be an array")673 }674 var error = t.throws(() => {675 validateSpecs({type: 'enum', values: []})676 }, {instanceOf: ValidationError})677 t.deepEqual(error.path, ['values'])678 t.is(error.message, "must contain at least one value")679 var error = t.throws(() => {680 validateSpecs({type: 'enum', values: ['@foo', 'bar', 'quz']})681 }, {instanceOf: ValidationError})682 t.deepEqual(error.path, ['values'])683 t.is(error.message, "'@foo' is an incorrect value")684 var error = t.throws(() => {685 validateSpecs({type: 'enum', values: ['foo', 'bar', 'quz', 'foo']})686 }, {instanceOf: ValidationError})687 t.deepEqual(error.path, ['values'])688 t.is(error.message, "'foo' value is duplicated")689 // test the 'option' property690 optionPropertyTest(t, specs, [])691 // test additional properties692 additionalPropertiesTest(t, specs)693 // test 'name' and 'description' properties694 namePropertyTest(t, specs)695 descriptionPropertyTest(t, specs)696 // test lazy validation697 var specs = {698 type: 'enum',699 values: ['@foo', 'bar', 'quz', 'bar'],700 option: 42,701 foo: 'bar'702 }703 var errors = []704 validateSpecs(specs, errors)705 t.deepEqual(errors[0].path, [])706 t.is(errors[0].message, "'foo' property is unexpected")707 t.deepEqual(errors[1].path, ['values'])708 t.is(errors[1].message, "'@foo' is an incorrect value")709 t.deepEqual(errors[2].path, ['values'])710 t.is(errors[2].message, "'bar' value is duplicated")711 t.deepEqual(errors[3].path, ['option'])712 t.is(errors[3].message, "value must be a bool")...

Full Screen

Full Screen

corpIDService.js

Source:corpIDService.js Github

copy

Full Screen

...25 });26 }27 var _validateCreate = function(products, ABSelected, ABSpecs, CDSelected, CDSpecs, success) {28 var errorMsg = [];29 function validateSpecs(specs, side) {30 angular.forEach(specs, function(spec) {31 if (spec.Required && !spec.Value && !spec.CanSetForLineItem) {32 var name = spec.Label ? spec.Label : spec.Name;33 errorMsg.push("Please provide a value for " + name + " on the " + side + " side form");34 }35 });36 }37 if (ABSelected) {38 validateSpecs(ABSpecs, "left");39 }40 if (CDSelected) {41 validateSpecs(CDSpecs, "right");42 }43 _then(success, errorMsg);44 }45 var _createVariants = function(products, ABSpecs, CDSpecs, success) {46 var variants = [];47 angular.forEach(products, function(product) {48 var productType = (product.ExternalID.indexOf('A') > -1 || product.ExternalID.indexOf('B') > -1) ? "AB" : "CD";49 var variant = {};50 variant.Specs = (productType == 'AB') ? ABSpecs : CDSpecs;51 if (variant.Specs['Address']) {52 variant.Specs['Address1'] = {};53 variant.Specs['Address1'].Value = variant.Specs['Address'].Value;54 }55 else {...

Full Screen

Full Screen

validate.spec.ts

Source:validate.spec.ts Github

copy

Full Screen

1import { Spec } from '..';2import { validate } from '../../app/modules/validation';3import { ValidateOptions } from '../../app/modules/validation/validate-options.interface';4import { strictEqual } from 'assert';5export const validateSpecs: Spec = {};6validateSpecs[`validate: Should return trimmed string if min or max not defined`] = (done) => {7 const testValue = ' test string ';8 const options: ValidateOptions = {9 type: 'text',10 value: testValue11 };12 const testResult = validate(options);13 strictEqual(testResult, testValue.trim());14 done();15};16validateSpecs[`validate: Should return false if min option less then value's length option`] = (done) => {17 const testValue = ' test ';18 const trimmedTestValue = testValue.trim();19 const options: ValidateOptions = {20 type: 'text',21 value: testValue,22 min: 523 };24 const testResult = validate(options);25 const expected = trimmedTestValue.length >= options.min ? trimmedTestValue : false;26 strictEqual(testResult, expected);27 done();28};29validateSpecs[`validate: Should return false if value is type of string when type option is number`] = (done) => {30 const testValue = ' test ';31 const options: ValidateOptions = {32 type: 'number',33 value: testValue34 };35 const testResult = validate(options);36 const expected = typeof testValue === 'number' ? testValue : false;37 strictEqual(testResult, expected);38 done();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuy = require("./BestBuy.js");2var bestBuy = new BestBuy();3 {4 },5 {6 }7];8console.log(bestBuy.validateSpecs(specs));9var BestBuy = require("./BestBuy.js");10var bestBuy = new BestBuy();11 {12 },13 {14 }15];16bestBuy.getProducts(specs, function (err, products) {17 if (err) {18 console.log(err);19 }20 else {21 console.log(products);22 }23});24var BestBuy = require("./BestBuy.js");25var bestBuy = new BestBuy();26 {27 },28 {29 }30];31bestBuy.getProducts(specs, function (err, products) {32 if (err) {33 console.log(err);34 }35 else {36 console.log(products);37 }38});39var BestBuy = require("./BestBuy.js");40var bestBuy = new BestBuy();41 {42 },43 {44 }45];46bestBuy.getProducts(specs, function (err, products) {47 if (err) {48 console.log(err);49 }50 else {51 console.log(products);52 }53});54var BestBuy = require("./BestBuy.js");55var bestBuy = new BestBuy();56 {57 },58 {59 }60];61bestBuy.getProducts(specs, function (err, products) {62 if (err)

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuy = require('./bestbuy');2var bestbuy = new BestBuy();3var specs = {4};5var result = bestbuy.validateSpecs(specs);6console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestSpecs = require('./BestSpecs');2var bs = new BestSpecs();3var specs = {4};5var bestSpecs = bs.validateSpecs(specs);6console.log(bestSpecs);7console.log(bs.getCost());8console.log(bs.getCostWithTax());9console.log(bs.getCostWithTaxAndDiscount());10console.log(bs.getCostWithTaxAndDiscountAndShipping());11console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBack());12console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsurance());13console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsuranceAndWarranty());14console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsuranceAndWarrantyAndUpgrade());15console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsuranceAndWarrantyAndUpgradeAndGiftCard());16console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsuranceAndWarrantyAndUpgradeAndGiftCardAndRebate());17console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsuranceAndWarrantyAndUpgradeAndGiftCardAndRebateAndReward());18console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsuranceAndWarrantyAndUpgradeAndGiftCardAndRebateAndRewardAndPoints());19console.log(bs.getCostWithTaxAndDiscountAndShippingAndCashBackAndInsuranceAndWarranty

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuy = require('./BestBuy.js');2var bb = new BestBuy();3bb.validateSpecs('test1.js', function(err, data) {4 console.log(data);5});6{ result: 'success',7 test: 'test1.js' }8var BestBuy = require('./BestBuy.js');9var bb = new BestBuy();10bb.validateSpecs('test1.js')11 .then(function(data) {12 console.log(data);13 })14 .catch(function(err) {15 console.log(err);16 });17{ result: 'success',18 test: 'test1.js' }19var BestBuy = require('./BestBuy.js');20var bb = new BestBuy();21async function validate() {22 try {23 var data = await bb.validateSpecs('test1.js');24 console.log(data);25 } catch (err) {26 console.log(err);27 }28}29validate();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuySpecsPage = require('../pageObjects/bestBuySpecsPage.js');2var data = require('../data/bestBuySpecsData.json');3describe('BestBuySpecsPage', function() {4 var bestBuySpecsPage = new BestBuySpecsPage();5 beforeEach(function() {6 bestBuySpecsPage.get();7 });8 it('should validate the specs', function() {9 bestBuySpecsPage.validateSpecs(data);10 });11});12var BestBuySpecsPage = function() {13 var specs = element.all(by.repeater('spec in product.specs'));14 var specsList = element.all(by.repeater('spec in product.specs')).all(by.tagName('li'));15 this.validateSpecs = function(data) {16 expect(specs.count()).toEqual(data.specsCount);17 specsList.each(function(spec, index) {18 expect(spec.getText()).toEqual(data.specsList[index]);19 });20 };21};22{23}

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestBuy = require('./bestBuy.js');2var product = new bestBuy.Product();3var productSpecs = {4};5product.validateSpecs(productSpecs, function (err, result) {6 if (err) {7 console.log(err);8 } else {9 console.log(result);10 }11});12{ name: 'Samsung 55" Class LED 1080p 120Hz HDTV',13 valid: true }

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful