Skip to content

Commit 0cbca85

Browse files
committed
fix observation collection inclusion based on media rules
1 parent aa8063e commit 0cbca85

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

lib/models/project.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ const Project = class Project extends Model {
372372
if ( field === "quality_grade" && !_.includes( value, observation.quality_grade ) ) {
373373
return false;
374374
}
375-
if ( field === "photos" && _.isEmpty( observation.photos ) ) {
375+
if ( field === "photos" && !( observation.photos_count > 0 ) ) {
376376
return false;
377377
}
378-
if ( field === "sounds" && _.isEmpty( observation.sounds ) ) {
378+
if ( field === "sounds" && !( observation.sounds_count > 0 ) ) {
379379
return false;
380380
}
381381
if ( field === "native" && !observation.taxon?.native ) {

test/models/project.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,13 @@ describe( "Project", ( ) => {
436436

437437
it( "photos requires photos to be present", ( ) => {
438438
project = buildProject( { photos: true } );
439-
observation = { photos: [{ id: 1 }] };
439+
observation = { photos_count: 1 };
440440
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.true;
441-
observation = { photos: [] };
441+
observation = { photos_count: 0 };
442442
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
443-
observation = { sounds: [{ id: 1 }] };
443+
observation = { photos_count: null };
444+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
445+
observation = { sounds_count: 1 };
444446
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
445447

446448
observation = { };
@@ -449,11 +451,30 @@ describe( "Project", ( ) => {
449451

450452
it( "sounds requires sounds to be present", ( ) => {
451453
project = buildProject( { sounds: true } );
452-
observation = { sounds: [{ id: 1 }] };
454+
observation = { sounds_count: 1 };
455+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.true;
456+
observation = { sounds_count: 0 };
457+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
458+
observation = { sounds_count: null };
459+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
460+
observation = { photos_count: 1 };
461+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
462+
463+
observation = { };
464+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
465+
} );
466+
467+
it( "photos and sounds can both be required", ( ) => {
468+
project = buildProject( { photos: true, sounds: true } );
469+
observation = { photos_count: 1 };
470+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
471+
observation = { sounds_count: 1 };
472+
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
473+
observation = { photos_count: 1, sounds_count: 1 };
453474
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.true;
454-
observation = { sounds: [] };
475+
observation = { photos_count: 0, sounds_count: 1 };
455476
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
456-
observation = { photos: [{ id: 1 }] };
477+
observation = { photos_count: null, sounds_count: 1 };
457478
expect( Project.collectionProjectRulesAllowObservation( project, observation ) ).to.be.false;
458479

459480
observation = { };

0 commit comments

Comments
 (0)