@@ -431,7 +431,7 @@ describe('Entities from Repeats', () => {
431431 } ) ) ;
432432 } ) ;
433433
434- describe ( 'entity sources and backlog' , ( ) => {
434+ describe ( 'errors, entity sources and backlog' , ( ) => {
435435 it ( 'should assign the same entity source to multiple entities created by the same submission' , testService ( async ( service , container ) => {
436436 const asAlice = await service . login ( 'alice' ) ;
437437
@@ -486,6 +486,72 @@ describe('Entities from Repeats', () => {
486486 . then ( ( { body } ) => { body . length . should . equal ( 0 ) ; } ) ;
487487 } ) ) ;
488488
489+ it ( 'should log an error when one of multiple entities fails' , testService ( async ( service , container ) => {
490+ const asAlice = await service . login ( 'alice' ) ;
491+
492+ const subXml = `<data xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" id="repeatEntityTrees" version="1">
493+ <plot_id>1</plot_id>
494+ <tree>
495+ <species>pine</species>
496+ <circumference>12</circumference>
497+ <meta>
498+ <entity dataset="trees" create="1" id="f73ea0a0-f51f-4d13-a7cb-c2123ba06f34">
499+ <label>Pine</label>
500+ </entity>
501+ </meta>
502+ </tree>
503+ <tree>
504+ <species>oak</species>
505+ <circumference>13</circumference>
506+ <meta>
507+ <entity dataset="trees" create="1" id="090c56ff-25f4-4503-b760-f6bef8528152">
508+ </entity>
509+ </meta>
510+ </tree>
511+ <tree>
512+ <species>maple</species>
513+ <circumference>14</circumference>
514+ <meta>
515+ <entity dataset="trees" create="1" id="invalid-uuid">
516+ <label>Maple</label>
517+ </entity>
518+ </meta>
519+ </tree>
520+ <meta>
521+ <instanceID>one</instanceID>
522+ </meta>
523+ </data>` ;
524+
525+ await asAlice . post ( '/v1/projects/1/forms?publish=true' )
526+ . send ( testData . forms . repeatEntityTrees )
527+ . set ( 'Content-Type' , 'application/xml' )
528+ . expect ( 200 ) ;
529+
530+ await asAlice . post ( '/v1/projects/1/forms/repeatEntityTrees/submissions' )
531+ . send ( subXml )
532+ . set ( 'Content-Type' , 'application/xml' )
533+ . expect ( 200 ) ;
534+
535+ await exhaust ( container ) ;
536+
537+ await asAlice . get ( '/v1/projects/1/forms/repeatEntityTrees/submissions/one/audits' )
538+ . then ( ( { body } ) => {
539+ body [ 0 ] . action . should . equal ( 'entity.error' ) ;
540+ body [ 0 ] . details . problem . problemCode . should . equal ( 400.43 ) ;
541+
542+ body [ 0 ] . details . errorMessage . includes ( 'Failed to process 3 entities in submission due to 2 errors' ) . should . be . true ( ) ;
543+ body [ 0 ] . details . errorMessage . includes ( '(Entity 2) Required parameter label missing' ) . should . be . true ( ) ;
544+ body [ 0 ] . details . errorMessage . includes ( '(Entity 3) Invalid input data type: expected (uuid)' ) . should . be . true ( ) ;
545+
546+ const { problemDetails } = body [ 0 ] . details . problem ;
547+ problemDetails . should . containEql ( { count : 2 , total : 3 } ) ;
548+ const detailErrors = problemDetails . errors ;
549+ detailErrors . length . should . equal ( 2 ) ;
550+ detailErrors [ 0 ] . problem . problemCode . should . equal ( 400.2 ) ;
551+ detailErrors [ 1 ] . problem . problemCode . should . equal ( 400.11 ) ;
552+ } ) ;
553+ } ) ) ;
554+
489555 it ( 'should note what happens when two entities hold submission into backlog' , testService ( async ( service , container ) => {
490556 const asAlice = await service . login ( 'alice' ) ;
491557
0 commit comments