mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-10-07 02:22:38 -04:00
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
import ObservationFieldValue from "realmModels/ObservationFieldValue";
|
|
import safeRealmWrite from "sharedHelpers/safeRealmWrite";
|
|
import * as uuid from "uuid";
|
|
|
|
describe( "ObservationFieldValue", () => {
|
|
describe( "new", () => {
|
|
it( "should construct an OFV", () => {
|
|
const ofv = ObservationFieldValue.new( 7, 99, "male" );
|
|
expect( ofv.uuid ).toBe( ofv.uuid.toLowerCase() );
|
|
expect( ofv.projectId ).toBe( 7 );
|
|
expect( ofv.obsFieldId ).toBe( 99 );
|
|
expect( ofv.value ).toBe( "male" );
|
|
expect( ofv._created_at ).toBeInstanceOf( Date );
|
|
expect( ofv._updated_at ).toBeInstanceOf( Date );
|
|
} );
|
|
} );
|
|
|
|
describe( "findForProject", () => {
|
|
it( "should find an OFV scoped by projectId and obsFieldId", () => {
|
|
const obsUuid = uuid.v4();
|
|
safeRealmWrite(
|
|
global.realm,
|
|
() => {
|
|
global.realm.create( "Observation", {
|
|
uuid: obsUuid,
|
|
observationFieldValues: [
|
|
ObservationFieldValue.new( 1, 10, "a" ),
|
|
ObservationFieldValue.new( 2, 10, "b" ),
|
|
],
|
|
} );
|
|
},
|
|
"create Observation with scoped OFVs",
|
|
);
|
|
|
|
const obs = global.realm.objectForPrimaryKey( "Observation", obsUuid );
|
|
expect( ObservationFieldValue.findForProject( obs, 2, 10 )?.value ).toBe( "b" );
|
|
expect( ObservationFieldValue.findForProject( obs, 1, 10 )?.value ).toBe( "a" );
|
|
expect( ObservationFieldValue.findForProject( obs, 3, 10 ) ).toBeUndefined();
|
|
} );
|
|
} );
|
|
} );
|