-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1181 - introduced setup services to reuse across tests.
- Loading branch information
1 parent
adcae13
commit 57470d8
Showing
5 changed files
with
89 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/openchs-android/integrationTest/service/TestChecklistService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import _ from "lodash"; | ||
import {Checklist, ChecklistDetail, ChecklistItem, Concept} from "openchs-models"; | ||
import TestConceptFactory from "../../test/model/TestConceptFactory"; | ||
import General from "../../src/utility/General"; | ||
import moment from "moment/moment"; | ||
|
||
class TestChecklistService { | ||
static createChecklist(programEnrolment, db, withDue = true) { | ||
const checklistConcept = db.create(Concept, TestConceptFactory.createWithDefaults({dataType: Concept.dataType.Text})); | ||
const checklistDetail = db.create(ChecklistDetail, { | ||
uuid: General.randomUUID(), | ||
name: 'ck-detail', | ||
items: [], | ||
voided: false}) | ||
const checklist = { | ||
uuid: General.randomUUID(), | ||
items: [ | ||
{ | ||
uuid: General.randomUUID(), | ||
detail: { | ||
uuid: General.randomUUID(), | ||
concept: checklistConcept, | ||
stateConfig: [{ | ||
state: "Due", | ||
from: {key: "key1", value: 1}, | ||
to: {key: "key2", value: 2}, | ||
color: "red", | ||
displayOrder: 3, | ||
start: -1, | ||
end: +1 | ||
}], | ||
checklistDetail: checklistDetail, | ||
} | ||
}] | ||
} | ||
let checklistToBeCreated = Checklist.create(); | ||
checklistToBeCreated.uuid = _.isNil(checklist.uuid) ? checklistToBeCreated.uuid : checklist.uuid; | ||
checklistToBeCreated.baseDate = withDue ? moment().toDate() : moment().add(-2, "day").toDate(); | ||
checklistToBeCreated.detail = checklistDetail; | ||
const savedChecklist = db.create(Checklist, checklistToBeCreated, true); | ||
const checklistItems = checklist.items.map((item) => { | ||
const checklistItem = ChecklistItem.create({ | ||
uuid: item.uuid, | ||
checklist: savedChecklist, | ||
detail: item.detail | ||
}); | ||
return db.create(ChecklistItem, checklistItem, true); | ||
}); | ||
checklistItems.forEach(ci => savedChecklist.items.push(ci)); | ||
programEnrolment.addChecklist(savedChecklist); | ||
savedChecklist.programEnrolment = programEnrolment; | ||
} | ||
} | ||
|
||
export default TestChecklistService; |
19 changes: 19 additions & 0 deletions
19
packages/openchs-android/integrationTest/service/TestOrganisationService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {AddressLevel, Gender, OrganisationConfig, Settings} from "openchs-models"; | ||
import TestAddressLevelFactory from "../../test/model/TestAddressLevelFactory"; | ||
import TestGenderFactory from "../../test/model/TestGenderFactory"; | ||
import TestSettingsFactory from "../../test/model/user/TestSettingsFactory"; | ||
import TestOrganisationConfigFactory from "../../test/model/TestOrganisationConfigFactory"; | ||
|
||
class TestOrganisationService { | ||
static setupOrganisation(db) { | ||
const returnData = {}; | ||
returnData.addressLevel = db.create(AddressLevel, TestAddressLevelFactory.createWithDefaults({level: 1})); | ||
returnData.addressLevel2 = db.create(AddressLevel, TestAddressLevelFactory.createWithDefaults({level: 1})); | ||
returnData.gender = db.create(Gender, TestGenderFactory.createWithDefaults({name: "Male"})); | ||
db.create(Settings, TestSettingsFactory.createWithDefaults({})); | ||
db.create(OrganisationConfig, TestOrganisationConfigFactory.createWithDefaults({})); | ||
return returnData; | ||
} | ||
} | ||
|
||
export default TestOrganisationService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters