@@ -438,11 +438,11 @@ describe('datasets and entities', () => {
438438 publishedAt . should . not . be . null ( ) ;
439439 return p ;
440440 } ) . should . be . eql ( [
441- { name : 'age' , forms : [ { name : 'simpleEntity' , xmlFormId : 'simpleEntity' } , ] } ,
442441 { name : 'first_name' , forms : [
443442 { name : 'simpleEntity' , xmlFormId : 'simpleEntity' } ,
444443 { name : 'simpleEntity2' , xmlFormId : 'simpleEntity2' }
445444 ] } ,
445+ { name : 'age' , forms : [ { name : 'simpleEntity' , xmlFormId : 'simpleEntity' } , ] } ,
446446 { name : 'address' , forms : [ { name : 'simpleEntity2' , xmlFormId : 'simpleEntity2' } , ] }
447447 ] ) ;
448448
@@ -480,6 +480,215 @@ describe('datasets and entities', () => {
480480 } ) ;
481481
482482 } ) ) ;
483+
484+ it ( 'should return properties of a dataset in order' , testService ( async ( service ) => {
485+ const asAlice = await service . login ( 'alice' , identity ) ;
486+
487+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
488+ . send ( testData . forms . multiPropertyEntity )
489+ . set ( 'Content-Type' , 'application/xml' )
490+ . expect ( 200 ) ;
491+
492+ await asAlice . get ( '/v1/projects/1/datasets/foo' )
493+ . expect ( 200 )
494+ . then ( ( { body } ) => {
495+ const { properties } = body ;
496+ properties . map ( ( p ) => p . name )
497+ . should . be . eql ( [
498+ 'b_q1' ,
499+ 'd_q2' ,
500+ 'a_q3' ,
501+ 'c_q4'
502+ ] ) ;
503+ } ) ;
504+ } ) ) ;
505+
506+ it ( 'should return dataset properties from multiple forms in order' , testService ( async ( service ) => {
507+ const asAlice = await service . login ( 'alice' , identity ) ;
508+
509+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
510+ . send ( testData . forms . multiPropertyEntity )
511+ . set ( 'Content-Type' , 'application/xml' )
512+ . expect ( 200 ) ;
513+
514+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
515+ . send ( testData . forms . multiPropertyEntity
516+ . replace ( 'multiPropertyEntity' , 'multiPropertyEntity2' )
517+ . replace ( 'b_q1' , 'f_q1' )
518+ . replace ( 'd_q2' , 'e_q2' ) )
519+ . set ( 'Content-Type' , 'application/xml' )
520+ . expect ( 200 ) ;
521+
522+ await asAlice . get ( '/v1/projects/1/datasets/foo' )
523+ . expect ( 200 )
524+ . then ( ( { body } ) => {
525+ const { properties } = body ;
526+ properties . map ( ( p ) => p . name )
527+ . should . be . eql ( [
528+ 'b_q1' ,
529+ 'd_q2' ,
530+ 'a_q3' ,
531+ 'c_q4' ,
532+ 'f_q1' ,
533+ 'e_q2'
534+ ] ) ;
535+ } ) ;
536+ } ) ) ;
537+
538+ it ( 'should return dataset properties from multiple forms including updated form with updated schema' , testService ( async ( service ) => {
539+ const asAlice = await service . login ( 'alice' , identity ) ;
540+
541+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
542+ . send ( testData . forms . multiPropertyEntity )
543+ . set ( 'Content-Type' , 'application/xml' )
544+ . expect ( 200 ) ;
545+
546+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
547+ . send ( testData . forms . multiPropertyEntity
548+ . replace ( 'multiPropertyEntity' , 'multiPropertyEntity2' )
549+ . replace ( 'b_q1' , 'f_q1' )
550+ . replace ( 'd_q2' , 'e_q2' ) )
551+ . set ( 'Content-Type' , 'application/xml' )
552+ . expect ( 200 ) ;
553+
554+ await asAlice . post ( '/v1/projects/1/forms/multiPropertyEntity/draft' )
555+ . send ( testData . forms . multiPropertyEntity
556+ . replace ( 'orx:version="1.0"' , 'orx:version="2.0"' )
557+ . replace ( 'b_q1' , 'g_q1' ) )
558+ . set ( 'Content-Type' , 'application/xml' )
559+ . expect ( 200 ) ;
560+
561+ await asAlice . post ( '/v1/projects/1/forms/multiPropertyEntity/draft/publish' ) . expect ( 200 ) ;
562+
563+ await asAlice . get ( '/v1/projects/1/datasets/foo' )
564+ . expect ( 200 )
565+ . then ( ( { body } ) => {
566+ const { properties } = body ;
567+ properties . map ( ( p ) => p . name )
568+ . should . be . eql ( [
569+ 'b_q1' ,
570+ 'd_q2' ,
571+ 'a_q3' ,
572+ 'c_q4' ,
573+ 'f_q1' ,
574+ 'e_q2' ,
575+ 'g_q1'
576+ ] ) ;
577+ } ) ;
578+ } ) ) ;
579+
580+ it ( 'should return dataset properties when purged draft form shares some properties' , testService ( async ( service , { Forms } ) => {
581+ const asAlice = await service . login ( 'alice' , identity ) ;
582+
583+ await asAlice . post ( '/v1/projects/1/forms' )
584+ . send ( testData . forms . multiPropertyEntity )
585+ . set ( 'Content-Type' , 'application/xml' )
586+ . expect ( 200 ) ;
587+
588+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
589+ . send ( testData . forms . multiPropertyEntity
590+ . replace ( 'multiPropertyEntity' , 'multiPropertyEntity2' )
591+ . replace ( 'b_q1' , 'f_q1' )
592+ . replace ( 'd_q2' , 'e_q2' ) )
593+ . set ( 'Content-Type' , 'application/xml' )
594+ . expect ( 200 ) ;
595+
596+ await asAlice . delete ( '/v1/projects/1/forms/multiPropertyEntity' )
597+ . expect ( 200 ) ;
598+
599+ await Forms . purge ( true ) ;
600+
601+ await asAlice . get ( '/v1/projects/1/datasets/foo' )
602+ . expect ( 200 )
603+ . then ( ( { body } ) => {
604+ const { properties } = body ;
605+ properties . map ( ( p ) => p . name )
606+ . should . be . eql ( [
607+ 'f_q1' ,
608+ 'e_q2' ,
609+ 'a_q3' ,
610+ 'c_q4'
611+ ] ) ;
612+ } ) ;
613+ } ) ) ;
614+
615+ it ( 'should return dataset properties when draft form (purged before second form publish) shares some properties' , testService ( async ( service , { Forms } ) => {
616+ const asAlice = await service . login ( 'alice' , identity ) ;
617+
618+ await asAlice . post ( '/v1/projects/1/forms' )
619+ . send ( testData . forms . multiPropertyEntity )
620+ . set ( 'Content-Type' , 'application/xml' )
621+ . expect ( 200 ) ;
622+
623+ await asAlice . post ( '/v1/projects/1/forms' )
624+ . send ( testData . forms . multiPropertyEntity
625+ . replace ( 'multiPropertyEntity' , 'multiPropertyEntity2' )
626+ . replace ( 'b_q1' , 'f_q1' )
627+ . replace ( 'd_q2' , 'e_q2' ) )
628+ . set ( 'Content-Type' , 'application/xml' )
629+ . expect ( 200 ) ;
630+
631+ await asAlice . delete ( '/v1/projects/1/forms/multiPropertyEntity' )
632+ . expect ( 200 ) ;
633+
634+ await Forms . purge ( true ) ;
635+
636+ await asAlice . post ( '/v1/projects/1/forms/multiPropertyEntity2/draft/publish' ) ;
637+
638+ await asAlice . get ( '/v1/projects/1/datasets/foo' )
639+ . expect ( 200 )
640+ . then ( ( { body } ) => {
641+ const { properties } = body ;
642+ properties . map ( ( p ) => p . name )
643+ . should . be . eql ( [
644+ 'f_q1' ,
645+ 'e_q2' ,
646+ 'a_q3' ,
647+ 'c_q4'
648+ ] ) ;
649+ } ) ;
650+ } ) ) ;
651+
652+ it . skip ( 'should return ordered dataset properties including from deleted published form' , testService ( async ( service , { Forms } ) => {
653+ const asAlice = await service . login ( 'alice' , identity ) ;
654+
655+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
656+ . send ( testData . forms . multiPropertyEntity )
657+ . set ( 'Content-Type' , 'application/xml' )
658+ . expect ( 200 ) ;
659+
660+ await asAlice . delete ( '/v1/projects/1/forms/multiPropertyEntity' )
661+ . expect ( 200 ) ;
662+
663+ await Forms . purge ( true ) ;
664+
665+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
666+ . send ( testData . forms . multiPropertyEntity
667+ . replace ( 'multiPropertyEntity' , 'multiPropertyEntity2' )
668+ . replace ( 'b_q1' , 'f_q1' )
669+ . replace ( 'd_q2' , 'e_q2' ) )
670+ . set ( 'Content-Type' , 'application/xml' )
671+ . expect ( 200 ) ;
672+
673+ await asAlice . get ( '/v1/projects/1/datasets/foo' )
674+ . expect ( 200 )
675+ . then ( ( { body } ) => {
676+ const { properties } = body ;
677+ // Properties are coming out in this other order:
678+ // [ 'a_q3', 'c_q4', 'b_q1', 'd_q2', 'f_q1', 'e_q2' ]
679+ // It's not terrible but would rather all the props of the first form
680+ // show up first.
681+ properties . map ( ( p ) => p . name )
682+ . should . be . eql ( [
683+ 'b_q1' ,
684+ 'd_q2' ,
685+ 'a_q3' ,
686+ 'c_q4' ,
687+ 'f_q1' ,
688+ 'e_q2'
689+ ] ) ;
690+ } ) ;
691+ } ) ) ;
483692 } ) ;
484693 } ) ;
485694
0 commit comments