1- import { inputSchema , parseAjvError } from '@apify/input_schema' ;
1+ import { inputSchema } from '@apify/input_schema' ;
22import Ajv from 'ajv' ;
33
44/**
@@ -301,7 +301,7 @@ describe('input_schema.json', () => {
301301 } ) ;
302302
303303 describe ( 'special cases for datepicker editor type' , ( ) => {
304- it ( 'should accept allowAbsolute and allowRelative fields omitted' , ( ) => {
304+ it ( 'should accept dateType field omitted' , ( ) => {
305305 expect ( ajv . validate ( inputSchema , {
306306 title : 'Test input schema' ,
307307 type : 'object' ,
@@ -317,96 +317,8 @@ describe('input_schema.json', () => {
317317 } ) ) . toBe ( true ) ;
318318 } ) ;
319319
320- it ( 'should accept allowAbsolute and allowRelative both set to true' , ( ) => {
321- expect ( ajv . validate ( inputSchema , {
322- title : 'Test input schema' ,
323- type : 'object' ,
324- schemaVersion : 1 ,
325- properties : {
326- myField : {
327- title : 'Field title' ,
328- description : 'My test field' ,
329- type : 'string' ,
330- editor : 'datepicker' ,
331- allowAbsolute : true ,
332- allowRelative : true ,
333- } ,
334- } ,
335- } ) ) . toBe ( true ) ;
336- } ) ;
337-
338- it ( 'should accept allowAbsolute=true and allowRelative=false' , ( ) => {
339- expect ( ajv . validate ( inputSchema , {
340- title : 'Test input schema' ,
341- type : 'object' ,
342- schemaVersion : 1 ,
343- properties : {
344- myField : {
345- title : 'Field title' ,
346- description : 'My test field' ,
347- type : 'string' ,
348- editor : 'datepicker' ,
349- allowAbsolute : true ,
350- allowRelative : false ,
351- } ,
352- } ,
353- } ) ) . toBe ( true ) ;
354- } ) ;
355-
356- it ( 'should accept allowAbsolute=false and allowRelative=true' , ( ) => {
357- expect ( ajv . validate ( inputSchema , {
358- title : 'Test input schema' ,
359- type : 'object' ,
360- schemaVersion : 1 ,
361- properties : {
362- myField : {
363- title : 'Field title' ,
364- description : 'My test field' ,
365- type : 'string' ,
366- editor : 'datepicker' ,
367- allowAbsolute : false ,
368- allowRelative : true ,
369- } ,
370- } ,
371- } ) ) . toBe ( true ) ;
372- } ) ;
373-
374- it ( 'should accept allowAbsolute=true' , ( ) => {
375- expect ( ajv . validate ( inputSchema , {
376- title : 'Test input schema' ,
377- type : 'object' ,
378- schemaVersion : 1 ,
379- properties : {
380- myField : {
381- title : 'Field title' ,
382- description : 'My test field' ,
383- type : 'string' ,
384- editor : 'datepicker' ,
385- allowAbsolute : true ,
386- } ,
387- } ,
388- } ) ) . toBe ( true ) ;
389- } ) ;
390-
391- it ( 'should accept allowRelative=true' , ( ) => {
392- expect ( ajv . validate ( inputSchema , {
393- title : 'Test input schema' ,
394- type : 'object' ,
395- schemaVersion : 1 ,
396- properties : {
397- myField : {
398- title : 'Field title' ,
399- description : 'My test field' ,
400- type : 'string' ,
401- editor : 'datepicker' ,
402- allowRelative : true ,
403- } ,
404- } ,
405- } ) ) . toBe ( true ) ;
406- } ) ;
407-
408- it ( 'should accept allowRelative=false' , ( ) => {
409- expect ( ajv . validate ( inputSchema , {
320+ const isSchemaValid = ( dateType : string ) => {
321+ return ajv . validate ( inputSchema , {
410322 title : 'Test input schema' ,
411323 type : 'object' ,
412324 schemaVersion : 1 ,
@@ -416,53 +328,22 @@ describe('input_schema.json', () => {
416328 description : 'My test field' ,
417329 type : 'string' ,
418330 editor : 'datepicker' ,
419- allowRelative : false ,
331+ dateType ,
420332 } ,
421333 } ,
422- } ) ) . toBe ( true ) ;
423- } ) ;
334+ } ) ;
335+ } ;
424336
425- it ( 'should not accept allowAbsolute=false' , ( ) => {
426- expect ( ajv . validate ( inputSchema , {
427- title : 'Test input schema' ,
428- type : 'object' ,
429- schemaVersion : 1 ,
430- properties : {
431- myField : {
432- title : 'Field title' ,
433- description : 'My test field' ,
434- type : 'string' ,
435- editor : 'datepicker' ,
436- allowAbsolute : false ,
437- } ,
438- } ,
439- } ) ) . toBe ( false ) ;
440- expect ( ajv . errorsText ( ) ) . toContain ( 'data/properties/myField must have required property \'allowRelative\'' ) ;
441- expect ( parseAjvError ( ajv . errors ! [ 0 ] , 'schema.properties.myField' ) ?. message )
442- . toEqual ( 'Field schema.properties.myField must accept absolute, relative or both dates. '
443- + 'Set "allowAbsolute", "allowRelative" or both properties.' ) ;
337+ it ( 'should accept valid dateType' , ( ) => {
338+ [ 'absolute' , 'relative' , 'absoluteOrRelative' ] . forEach ( ( dateType ) => {
339+ expect ( isSchemaValid ( dateType ) ) . toBe ( true ) ;
340+ } ) ;
444341 } ) ;
445342
446- it ( 'should not accept allowAbsolute=false allowRelative=false' , ( ) => {
447- expect ( ajv . validate ( inputSchema , {
448- title : 'Test input schema' ,
449- type : 'object' ,
450- schemaVersion : 1 ,
451- properties : {
452- myField : {
453- title : 'Field title' ,
454- description : 'My test field' ,
455- type : 'string' ,
456- editor : 'datepicker' ,
457- allowAbsolute : false ,
458- allowRelative : false ,
459- } ,
460- } ,
461- } ) ) . toBe ( false ) ;
462- expect ( ajv . errorsText ( ) ) . toContain ( 'data/properties/myField/allowAbsolute must be equal to constant' ) ;
463- expect ( parseAjvError ( ajv . errors ! [ 0 ] , 'schema.properties.myField' ) ?. message )
464- . toEqual ( 'Field schema.properties.myField must accept absolute, relative or both dates. '
465- + 'Set "allowAbsolute", "allowRelative" or both properties.' ) ;
343+ it ( 'should not accept invalid dateType' , ( ) => {
344+ [ 'xxx' , 'invalid' ] . forEach ( ( dateType ) => {
345+ expect ( isSchemaValid ( dateType ) ) . toBe ( false ) ;
346+ } ) ;
466347 } ) ;
467348 } ) ;
468349
0 commit comments