Skip to content

Commit

Permalink
#1185 - supporting classes for the integration test for report cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 15, 2023
1 parent e72ae6c commit 8c89012
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import IntegrationTestRunner, {TestSuite} from "./IntegrationTestRunner";
import UtilTest from "./UtilTest";
import UserInfoServiceTest from "./UserInfoServiceTest";
import RealmProxyTest from "./RealmProxyTest";
import ReportCardServiceIntegrationTest from "./ReportCardServiceIntegrationTest";

const itemCommonStyle = {
padding: 10,
Expand Down Expand Up @@ -61,7 +62,7 @@ class IntegrationTestApp extends Component {
super(props, context);
FileSystem.init();
this.getBean = this.getBean.bind(this);
this.integrationTestRunner = new IntegrationTestRunner(UserInfoServiceTest, DatabaseTest, PersonRegisterActionsIntegrationTest, UtilTest, RealmProxyTest);
this.integrationTestRunner = new IntegrationTestRunner(ReportCardServiceIntegrationTest, UserInfoServiceTest, DatabaseTest, PersonRegisterActionsIntegrationTest, UtilTest, RealmProxyTest);
this.state = {isInitialisationDone: false, integrationTests: this.integrationTestRunner.testSuite};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import BaseIntegrationTest from "./BaseIntegrationTest";
import {
EntityApprovalStatus,
AddressLevel,
Concept,
Form,
StandardReportCardType,
FormElement,
FormElementGroup,
FormMapping,
Gender,
Individual,
OrganisationConfig,
Settings,
SubjectType,
CustomFilter,
ReportCard
} from "openchs-models";
import TestConceptFactory from "../test/model/TestConceptFactory";
import TestAddressLevelFactory from "../test/model/TestAddressLevelFactory";
import TestGenderFactory from "../test/model/TestGenderFactory";
import TestSettingsFactory from "../test/model/user/TestSettingsFactory";
import TestSubjectTypeFactory from "../test/model/TestSubjectTypeFactory";
import TestFormFactory from "../test/model/form/TestFormFactory";
import TestFormElementGroupFactory from "../test/model/form/TestFormElementGroupFactory";
import TestFormElementFactory from "../test/model/form/TestFormElementFactory";
import TestKeyValueFactory from "../test/model/TestKeyValueFactory";
import TestFormMappingFactory from "../test/model/form/TestFormMappingFactory";
import TestOrganisationConfigFactory from "../test/model/TestOrganisationConfigFactory";
import TestSubjectFactory from "../test/model/txn/TestSubjectFactory";
import TestObsFactory from "../test/model/TestObsFactory";
import TestEntityApprovalStatusFactory from "../test/model/TestEntityApprovalStatusFactory";
import ReportCardService from "../src/service/customDashboard/ReportCardService";
import TestStandardReportCardTypeFactory from "../test/model/reportNDashboard/TestStandardReportCardTypeFactory";
import TestReportCardFactory from "../test/model/reportNDashboard/TestReportCardFactory";
import TestDashboardReportRuleInputFactory from "../test/model/reportNDashboard/TestDashboardReportRuleInputFactory";
import TestDashboardReportFilterRuleInputFactory from "../test/model/reportNDashboard/TestDashboardReportFilterRuleInputFactory";

class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
approvedCard; subjectType;

setup() {
super.setup();
this.executeInWrite((db) => {
this.concept = db.create(Concept, TestConceptFactory.createWithDefaults({dataType: Concept.dataType.Text}));
this.addressLevel = db.create(AddressLevel, TestAddressLevelFactory.createWithDefaults({level: 1}));
this.gender = db.create(Gender, TestGenderFactory.createWithDefaults({name: "Male"}));
db.create(Settings, TestSettingsFactory.createWithDefaults({}));

this.subjectType = db.create(SubjectType, TestSubjectTypeFactory.createWithDefaults({type: SubjectType.types.Person, name: 'Beneficiary'}));
const form = db.create(Form, TestFormFactory.createWithDefaults({formType: Form.formTypes.IndividualProfile}));
const formElementGroup = db.create(FormElementGroup, TestFormElementGroupFactory.create({form: form}));
db.create(FormElement, TestFormElementFactory.create({
uuid: "FOO",
concept: this.concept,
displayOrder: 1,
formElementGroup: formElementGroup,
mandatory: true,
keyValues: [TestKeyValueFactory.create({key: "unique", value: "true"})]
}));
db.create(FormMapping, TestFormMappingFactory.createWithDefaults({subjectType: this.subjectType, form: form}));
db.create(OrganisationConfig, TestOrganisationConfigFactory.createWithDefaults({}));
const subject = db.create(Individual, TestSubjectFactory.createWithDefaults({subjectType: this.subjectType, address: this.addressLevel, firstName: "foo", lastName: "bar", observations: [TestObsFactory.create({concept: this.concept, valueJSON: JSON.stringify(this.concept.getValueWrapperFor("ABC"))})]}));
db.create(EntityApprovalStatus, TestEntityApprovalStatusFactory.create({entityType: EntityApprovalStatus.entityType.Subject, entityUUID: subject.uuid, entityTypeUuid: this.subjectType.uuid}));

const approvedCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.Approved}));
this.approvedCard = db.create(ReportCard, TestReportCardFactory.create({name: "foo", standardReportCardType: approvedCardType}));
});
}

getResultForApprovalCardsType() {
const dashboardReportRuleInput = TestDashboardReportRuleInputFactory.create({filterValues: [TestDashboardReportFilterRuleInputFactory.create({type: CustomFilter.type.Concept, filterValue: [this.addressLevel]})]});
this.getService(ReportCardService).getReportCardCount(this.approvedCard, dashboardReportRuleInput);
}
}

export default ReportCardServiceIntegrationTest;
14 changes: 7 additions & 7 deletions packages/openchs-android/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// These classes are created to document the contract with the rules. Objects has been used in place of arrays to allow for flexibility in contract in the future.
// Objects has been used in place of arrays to allow for flexibility in contract in the future.

export class DashboardReportFilterRuleInput {
type;
Expand All @@ -10,7 +10,7 @@ export class DashboardReportFilterRuleInput {
}

class DashboardReportRuleInput {
filterValues;
filterValues; // array of DashboardReportFilterRuleInput

constructor(filterValues) {
this.filterValues = filterValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CommentService from "../comment/CommentService";
import _ from "lodash";
import TaskService from "../task/TaskService";
import General from "../../utility/General";
import {JSONStringify} from "../../utility/JsonStringify";

function getApprovalStatusForType(type) {
const typeToStatusMap = {
Expand All @@ -29,16 +30,16 @@ class ReportCardService extends BaseService {
return ReportCard.schema.name;
}

getCountForApprovalCardsType(type, filterValuePairs) {
const {result} = this.getResultForApprovalCardsType(type, filterValuePairs);
getCountForApprovalCardsType(type) {
const {result} = this.getResultForApprovalCardsType(type);
return {
primaryValue: _.map(result, ({data}) => data.length).reduce((total, l) => total + l, 0),
secondaryValue: null,
clickable: true
};
}

getResultForApprovalCardsType(type, filterValuePairs) {
getResultForApprovalCardsType(type) {
const approvalStatus = getApprovalStatusForType(type);
return this.getService(EntityApprovalStatusService).getAllEntitiesWithStatus(approvalStatus);
}
Expand Down Expand Up @@ -107,6 +108,7 @@ class ReportCardService extends BaseService {

getReportCardCount(reportCard, ruleInputArray) {
General.logDebug("ReportCardService", `Executing report card: ${reportCard.name}`);
General.logDebugTemp("ReportCardService", JSONStringify(ruleInputArray, 5));
const standardReportCardType = reportCard.standardReportCardType;
switch (true) {
case _.isNil(standardReportCardType) :
Expand Down
2 changes: 1 addition & 1 deletion packages/openchs-android/src/utility/JsonStringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const duckCheckNativeRealmCollection = function (obj) {

const JSONStringifyInternal = function (obj, depth, objectMap: Map, arrayWidth, objectKey) {
if (depth === 0)
return undefined;
return "BELOW_DEPTH";
// Boolean and Number behave in a same way and String we need to add extra quotes
if (restOfDataTypes(obj)) {
const passQuotes = isString(obj) ? `"` : '';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {EntityApprovalStatus} from 'openchs-models';
import General from "../../src/utility/General";

class TestEntityApprovalStatusFactory {
static create({uuid = General.randomUUID(), entityType, entityUUID, entityTypeUuid, statusDateTime = new Date()}) {
const entityApprovalStatus = new EntityApprovalStatus();
entityApprovalStatus.uuid = uuid;
entityApprovalStatus.entityUUID = entityUUID;
entityApprovalStatus.entityType = entityType;
entityApprovalStatus.entityTypeUuid = entityTypeUuid;
entityApprovalStatus.statusDateTime = statusDateTime;
return entityApprovalStatus;
}
}

export default TestEntityApprovalStatusFactory;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {OrganisationConfig} from 'openchs-models';
import General from "../../src/utility/General";

class TestOrganisationConfigFactory {
static createWithDefaults({worklistUpdationRule = null, settings = "{\"languages\": [\"en\"]}"}) {
static createWithDefaults({worklistUpdationRule = "", settings = "{\"languages\": [\"en\"]}"}) {
const organisationConfig = new OrganisationConfig();
organisationConfig.uuid = General.randomUUID();
organisationConfig.settings = settings;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {DashboardReportFilterRuleInput} from "../../../src/model/DashboardReportRuleInput";

class TestDashboardReportFilterRuleInputFactory {
static create({type, dataType, subjectType, groupSubjectTypeFilter, observationBasedFilter, filterValue}) {
const dashboardReportFilterRuleInput = new DashboardReportFilterRuleInput();
dashboardReportFilterRuleInput.type = type;
dashboardReportFilterRuleInput.dataType = dataType;
dashboardReportFilterRuleInput.subjectType = subjectType;
dashboardReportFilterRuleInput.groupSubjectTypeFilter = groupSubjectTypeFilter;
dashboardReportFilterRuleInput.observationBasedFilter = observationBasedFilter;
dashboardReportFilterRuleInput.filterValue = filterValue;
return dashboardReportFilterRuleInput;
}
}

export default TestDashboardReportFilterRuleInputFactory;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import DashboardReportRuleInput from "../../../src/model/DashboardReportRuleInput";

class TestDashboardReportRuleInputFactory {
static create({filterValues = []}) {
const dashboardReportRuleInput = new DashboardReportRuleInput();
dashboardReportRuleInput.filterValues = filterValues;
return dashboardReportRuleInput;
}
}

export default TestDashboardReportRuleInputFactory;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {ReportCard} from 'openchs-models';
import General from "../../../src/utility/General";

class TestReportCardFactory {
static create({uuid = General.randomUUID(), name, standardReportCardType, colour = "red"}) {
const reportCard = new ReportCard();
reportCard.uuid = uuid;
reportCard.name = name;
reportCard.standardReportCardType = standardReportCardType;
reportCard.colour = colour;
return reportCard;
}
}

export default TestReportCardFactory;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {StandardReportCardType} from 'openchs-models';
import General from "../../../src/utility/General";

class TestStandardReportCardTypeFactory {
static create({name, uuid = General.randomUUID()}) {
const standardReportCardType = new StandardReportCardType();
standardReportCardType.uuid = uuid;
standardReportCardType.name = name;
return standardReportCardType;
}
}

export default TestStandardReportCardTypeFactory;

0 comments on commit 8c89012

Please sign in to comment.