diff --git a/packages/openchs-android/integrationTest/BaseIntegrationTest.js b/packages/openchs-android/integrationTest/BaseIntegrationTest.js index 49140e467..71d547d7f 100644 --- a/packages/openchs-android/integrationTest/BaseIntegrationTest.js +++ b/packages/openchs-android/integrationTest/BaseIntegrationTest.js @@ -41,6 +41,7 @@ class BaseIntegrationTest { } setup() { + this.log("Setup Called"); GlobalContext.getInstance().db.write(() => { GlobalContext.getInstance().db.realmDb.deleteAll(); }); diff --git a/packages/openchs-android/integrationTest/DatabaseTest.js b/packages/openchs-android/integrationTest/DatabaseTest.js index f89882cba..52470b731 100644 --- a/packages/openchs-android/integrationTest/DatabaseTest.js +++ b/packages/openchs-android/integrationTest/DatabaseTest.js @@ -13,8 +13,10 @@ import TestCommentFactory from "../test/model/comment/TestCommentFactory"; class DatabaseTest extends BaseIntegrationTest { shouldReturnFirstElementAsNilIfCollectionIsEmpty() { const db = GlobalContext.getInstance().db; - assert.equal(null, db.objects(Encounter.schema.name)[0]); - assert.equal(null, db.objects(Encounter.schema.name).filtered("uuid = '1'")[0]); + assert.equal(db.objects(Encounter.schema.name).length, 0); + const objects = db.objects(Encounter.schema.name); + assert.equal(objects[0], null); + assert.equal(db.objects(Encounter.schema.name).filtered("uuid = '1'")[0], null); } save_plain_object_graph_causes_circular_saves_leading_to_error() { @@ -90,12 +92,6 @@ class DatabaseTest extends BaseIntegrationTest { }); assert.equal(this.getEntity(FormElement, formElement.uuid).uuid, formElement.uuid); } - - is_object_relationship_optional() { - this.executeInWrite((db) => { - db.create(Comment, TestCommentFactory.create({})); - }); - } } export default DatabaseTest; diff --git a/packages/openchs-android/integrationTest/IntegrationTestApp.js b/packages/openchs-android/integrationTest/IntegrationTestApp.js index 6e4157a68..154d342fd 100644 --- a/packages/openchs-android/integrationTest/IntegrationTestApp.js +++ b/packages/openchs-android/integrationTest/IntegrationTestApp.js @@ -11,6 +11,7 @@ import DatabaseTest from "./DatabaseTest"; import IntegrationTestRunner, {TestSuite} from "./IntegrationTestRunner"; import UtilTest from "./UtilTest"; import UserInfoServiceTest from "./UserInfoServiceTest"; +import RealmProxyTest from "./RealmProxyTest"; const itemCommonStyle = { padding: 10, @@ -60,7 +61,7 @@ class IntegrationTestApp extends Component { super(props, context); FileSystem.init(); this.getBean = this.getBean.bind(this); - this.integrationTestRunner = new IntegrationTestRunner(UserInfoServiceTest, DatabaseTest, PersonRegisterActionsIntegrationTest, UtilTest); + this.integrationTestRunner = new IntegrationTestRunner(UserInfoServiceTest, DatabaseTest, PersonRegisterActionsIntegrationTest, UtilTest, RealmProxyTest); this.state = {isInitialisationDone: false, integrationTests: this.integrationTestRunner.testSuite}; } diff --git a/packages/openchs-android/integrationTest/RealmProxyTest.js b/packages/openchs-android/integrationTest/RealmProxyTest.js new file mode 100644 index 000000000..7d1d61cb6 --- /dev/null +++ b/packages/openchs-android/integrationTest/RealmProxyTest.js @@ -0,0 +1,30 @@ +import BaseIntegrationTest from "./BaseIntegrationTest"; +import {Observation} from "openchs-models"; +import {assert} from "chai"; +import TestObsFactory from "../test/model/TestObsFactory"; + +function shouldFail(baseIntegrationTest, obs, updateMode) { + baseIntegrationTest.executeInWrite((db) => { + try { + db.create(Observation, obs, updateMode); + assert.fail("Comment without subject and CommentThread should have failed to save."); + } catch (error) { + } + }); +} + +function shouldPass(baseIntegrationTest, obs, updateMode) { + baseIntegrationTest.executeInWrite((db) => { + db.create(Observation, obs, updateMode); + }); +} + +class RealmProxyTest extends BaseIntegrationTest { + doNotAllowCreateWithMandatoryObjectTypePropertyAsNull() { + shouldFail(this, TestObsFactory.create({valueJSON: "{}"}), false); + shouldFail(this, TestObsFactory.create({concept: null, valueJSON: "{}"}), true); + shouldPass(this, TestObsFactory.create({valueJSON: "{}"}), true); + } +} + +export default RealmProxyTest; diff --git a/packages/openchs-android/package-lock.json b/packages/openchs-android/package-lock.json index 67e2a8c9a..406cc68cb 100644 --- a/packages/openchs-android/package-lock.json +++ b/packages/openchs-android/package-lock.json @@ -33,7 +33,7 @@ "lodash": "4.17.21", "moment": "2.29.4", "native-base": "3.4.9", - "openchs-models": "1.30.79", + "openchs-models": "1.30.80", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", @@ -16431,9 +16431,9 @@ } }, "node_modules/openchs-models": { - "version": "1.30.79", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.79.tgz", - "integrity": "sha512-Ic+Lu3TQuA5xQIzBpScqIy6CCqnCwBWGbkagvWvw73fe6+zJJV1rnvdExosnka0E5OlvGmxh5A8yIv/dJs6M/g==", + "version": "1.30.80", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.80.tgz", + "integrity": "sha512-GaBNzYiDXkw4HwwBRbUKAPJsZov7CkcHf5bhCiTDd7+aPcFs0NzcJx+NgrO8RlY8Uo+2W3eKlScMLUcag09CQg==", "peerDependencies": { "lodash": "*", "moment": "*" @@ -35131,9 +35131,9 @@ } }, "openchs-models": { - "version": "1.30.79", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.79.tgz", - "integrity": "sha512-Ic+Lu3TQuA5xQIzBpScqIy6CCqnCwBWGbkagvWvw73fe6+zJJV1rnvdExosnka0E5OlvGmxh5A8yIv/dJs6M/g==" + "version": "1.30.80", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.80.tgz", + "integrity": "sha512-GaBNzYiDXkw4HwwBRbUKAPJsZov7CkcHf5bhCiTDd7+aPcFs0NzcJx+NgrO8RlY8Uo+2W3eKlScMLUcag09CQg==" }, "opencollective-postinstall": { "version": "2.0.3", diff --git a/packages/openchs-android/package.json b/packages/openchs-android/package.json index bb4c2a252..e07e36c08 100644 --- a/packages/openchs-android/package.json +++ b/packages/openchs-android/package.json @@ -57,7 +57,7 @@ "lodash": "4.17.21", "moment": "2.29.4", "native-base": "3.4.9", - "openchs-models": "1.30.79", + "openchs-models": "1.30.80", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", diff --git a/packages/openchs-android/test/model/TestObsFactory.js b/packages/openchs-android/test/model/TestObsFactory.js index e3328b826..11c0b9e5f 100644 --- a/packages/openchs-android/test/model/TestObsFactory.js +++ b/packages/openchs-android/test/model/TestObsFactory.js @@ -1,9 +1,11 @@ import {Observation} from 'openchs-models'; +import _ from 'lodash'; class TestObsFactory { static create({concept, valueJSON}) { const observation = new Observation(); - observation.concept = concept; + if (!_.isNil(concept)) + observation.concept = concept; observation.valueJSON = valueJSON; return observation; } diff --git a/packages/openchs-android/test/model/comment/TestCommentFactory.js b/packages/openchs-android/test/model/comment/TestCommentFactory.js index 2832886ca..19ed2a272 100644 --- a/packages/openchs-android/test/model/comment/TestCommentFactory.js +++ b/packages/openchs-android/test/model/comment/TestCommentFactory.js @@ -1,4 +1,3 @@ -import _ from "lodash"; import General from "../../../src/utility/General"; import {Comment} from 'openchs-models'; diff --git a/packages/openchs-android/test/model/txn/TestObservationFactory.js b/packages/openchs-android/test/model/txn/TestObservationFactory.js new file mode 100644 index 000000000..19940022b --- /dev/null +++ b/packages/openchs-android/test/model/txn/TestObservationFactory.js @@ -0,0 +1,12 @@ +import {Observation} from 'openchs-models'; + +class TestObservationFactory { + static create({concept, valueJson}) { + const observation = new Observation(); + observation.concept = concept; + observation.valueJSON = valueJson; + return observation; + } +} + +export default TestObservationFactory;