@@ -710,6 +710,69 @@ describe('observation entities', function() {
710710 expect ( invalid . hasErrors ) . to . be . false
711711 } )
712712
713+ it ( 'passes when a required numeric field value is zero' , function ( ) {
714+
715+ const form : Form = {
716+ id : 0 ,
717+ fields : [
718+ {
719+ id : 1 ,
720+ name : FormFieldType . Numeric ,
721+ required : true ,
722+ title : 'Field 8' ,
723+ type : FormFieldType . Numeric ,
724+ min : 0 ,
725+ max : 100 ,
726+ } ,
727+ ] ,
728+ archived : false ,
729+ color : 'green' ,
730+ name : 'form0' ,
731+ userFields : [ ] ,
732+ }
733+ mageEventAttrs = {
734+ ...mageEventAttrs ,
735+ forms : [ form ]
736+ }
737+ const invalidFormEntryUndef : FormEntry = {
738+ id : 'entry0' ,
739+ formId : form . id ,
740+ }
741+ const invalidFormEntryNull : FormEntry = {
742+ ...invalidFormEntryUndef ,
743+ [ FormFieldType . Numeric ] : null
744+ }
745+ const validFormEntry : FormEntry = {
746+ id : invalidFormEntryUndef . id ,
747+ formId : form . id ,
748+ [ FormFieldType . Numeric ] : 0 ,
749+ }
750+ const observationAttrs = makeObservationAttrs ( mageEventAttrs . id )
751+ const mageEvent = new MageEvent ( mageEventAttrs )
752+ observationAttrs . properties . forms = [ invalidFormEntryUndef ]
753+ let invalid = validateObservation ( observationAttrs , mageEvent )
754+
755+ expect ( invalid . formEntryErrors . length ) . to . equal ( 1 )
756+ let formEntryError = new Map ( invalid . formEntryErrors ) . get ( 0 )
757+ expect ( formEntryError ) . to . exist
758+ expect ( formEntryError ?. fieldErrors . size ) . to . equal ( 1 )
759+ expect ( formEntryError ?. fieldErrors ) . to . have . keys ( FormFieldType . Numeric )
760+
761+ observationAttrs . properties . forms = [ invalidFormEntryNull ]
762+ invalid = validateObservation ( observationAttrs , mageEvent )
763+
764+ expect ( invalid . formEntryErrors . length ) . to . equal ( 1 )
765+ formEntryError = new Map ( invalid . formEntryErrors ) . get ( 0 )
766+ expect ( formEntryError ) . to . exist
767+ expect ( formEntryError ?. fieldErrors . size ) . to . equal ( 1 )
768+ expect ( formEntryError ?. fieldErrors ) . to . have . keys ( FormFieldType . Numeric )
769+
770+ observationAttrs . properties . forms = [ validFormEntry ]
771+ invalid = validateObservation ( observationAttrs , mageEvent )
772+
773+ expect ( invalid . hasErrors ) . to . be . false
774+ } )
775+
713776 describe ( 'attachment validation' , function ( ) {
714777
715778 let field : FormField
0 commit comments