@@ -327,6 +327,71 @@ describe('datasets and entities', () => {
327327 . expect ( 200 )
328328 . then ( ( ) => asAlice . get ( '/v1/projects/1/datasets/people/entities.csv' )
329329 . expect ( 404 ) ) ) ) ) ;
330+
331+ it ( 'should return csv file with data' , testService ( async ( service , container ) => {
332+ const asAlice = await service . login ( 'alice' ) ;
333+
334+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
335+ . send ( testData . forms . simpleEntity )
336+ . set ( 'Content-Type' , 'application/xml' )
337+ . expect ( 200 ) ;
338+
339+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/submissions' )
340+ . send ( testData . instances . simpleEntity . one )
341+ . set ( 'Content-Type' , 'application/xml' )
342+ . expect ( 200 ) ;
343+
344+ await asAlice . patch ( '/v1/projects/1/forms/simpleEntity/submissions/one' )
345+ . send ( { reviewState : 'approved' } )
346+ . expect ( 200 ) ;
347+
348+ await exhaust ( container ) ;
349+
350+ const result = await asAlice . get ( '/v1/projects/1/datasets/people/entities.csv' )
351+ . expect ( 200 )
352+ . then ( r => r . text ) ;
353+
354+ result . should . be . eql (
355+ 'name,label,first_name,age\n' +
356+ '12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88\n'
357+ ) ;
358+
359+ } ) ) ;
360+
361+ it ( 'should return 304 content not changed if ETag matches' , testService ( async ( service , container ) => {
362+ const asAlice = await service . login ( 'alice' ) ;
363+
364+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
365+ . send ( testData . forms . simpleEntity )
366+ . set ( 'Content-Type' , 'application/xml' )
367+ . expect ( 200 ) ;
368+
369+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/submissions' )
370+ . send ( testData . instances . simpleEntity . one )
371+ . set ( 'Content-Type' , 'application/xml' )
372+ . expect ( 200 ) ;
373+
374+ await asAlice . patch ( '/v1/projects/1/forms/simpleEntity/submissions/one' )
375+ . send ( { reviewState : 'approved' } )
376+ . expect ( 200 ) ;
377+
378+ await exhaust ( container ) ;
379+
380+ const result = await asAlice . get ( '/v1/projects/1/datasets/people/entities.csv' )
381+ . expect ( 200 ) ;
382+
383+ result . text . should . be . eql (
384+ 'name,label,first_name,age\n' +
385+ '12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88\n'
386+ ) ;
387+
388+ const etag = result . get ( 'ETag' ) ;
389+
390+ await asAlice . get ( '/v1/projects/1/datasets/people/entities.csv' )
391+ . set ( 'If-None-Match' , etag )
392+ . expect ( 304 ) ;
393+ } ) ) ;
394+
330395 } ) ;
331396
332397 describe ( 'projects/:id/datasets/:name GET' , ( ) => {
@@ -499,6 +564,52 @@ describe('datasets and entities', () => {
499564 </manifest>` ) ;
500565 } ) ) ) ) ) ;
501566
567+ it ( 'should return md5 of last Entity timestamp in the manifest' , testService ( async ( service , container ) => {
568+ const asAlice = await service . login ( 'alice' ) ;
569+
570+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
571+ . send ( testData . forms . simpleEntity )
572+ . set ( 'Content-Type' , 'application/xml' )
573+ . expect ( 200 ) ;
574+
575+ await asAlice . post ( '/v1/projects/1/forms/simpleEntity/submissions' )
576+ . send ( testData . instances . simpleEntity . one )
577+ . set ( 'Content-Type' , 'application/xml' )
578+ . expect ( 200 ) ;
579+
580+ await asAlice . patch ( '/v1/projects/1/forms/simpleEntity/submissions/one' )
581+ . send ( { reviewState : 'approved' } )
582+ . expect ( 200 ) ;
583+
584+ await exhaust ( container ) ;
585+
586+ const result = await asAlice . get ( '/v1/projects/1/datasets/people/entities.csv' )
587+ . expect ( 200 ) ;
588+
589+ const etag = result . get ( 'ETag' ) ;
590+
591+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
592+ . send ( testData . forms . withAttachments . replace ( / g o o d o n e / g, 'people' ) )
593+ . set ( 'Content-Type' , 'application/xml' )
594+ . expect ( 200 ) ;
595+
596+ await asAlice . get ( '/v1/projects/1/forms/withAttachments/manifest' )
597+ . set ( 'X-OpenRosa-Version' , '1.0' )
598+ . expect ( 200 )
599+ . then ( ( { text } ) => {
600+ const domain = config . get ( 'default.env.domain' ) ;
601+ text . should . be . eql ( `<?xml version="1.0" encoding="UTF-8"?>
602+ <manifest xmlns="http://openrosa.org/xforms/xformsManifest">
603+ <mediaFile>
604+ <filename>people.csv</filename>
605+ <hash>md5:${ etag . replace ( / " / g, '' ) } </hash>
606+ <downloadUrl>${ domain } /v1/projects/1/forms/withAttachments/attachments/people.csv</downloadUrl>
607+ </mediaFile>
608+ </manifest>` ) ;
609+ } ) ;
610+
611+ } ) ) ;
612+
502613 it ( 'should override blob and link dataset' , testService ( ( service , { Forms, FormAttachments, Audits, Datasets } ) =>
503614 service . login ( 'alice' , ( asAlice ) =>
504615 asAlice . post ( '/v1/projects/1/forms' )
0 commit comments