Skip to content

Commit

Permalink
Add questionnaire view model save draft unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rkareko committed Nov 11, 2024
1 parent d9589c6 commit eec186f
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,38 @@ class QuestionnaireViewModelTest : RobolectricTest() {
coVerify { defaultRepository.addOrUpdate(resource = questionnaireResponse) }
}

@Test
fun testSaveDraftQuestionnaireShouldUpdateSubjectAndQuestionnaireValues() = runTest {
val questionnaireResponse =
QuestionnaireResponse().apply {
addItem(
QuestionnaireResponse.QuestionnaireResponseItemComponent().apply {
addAnswer(
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent()
.setValue(StringType("Sky is the limit")),
)
},
)
}
questionnaireViewModel.saveDraftQuestionnaire(
questionnaireResponse,
QuestionnaireConfig(
"dc-household-registration",
resourceIdentifier = "group-id-1",
resourceType = ResourceType.Group
),
)
Assert.assertEquals(
"Questionnaire/dc-household-registration",
questionnaireResponse.questionnaire,
)
Assert.assertEquals(
"Group/group-id-1",
questionnaireResponse.subject.reference,
)
coVerify { defaultRepository.addOrUpdate(resource = questionnaireResponse) }
}

@Test
fun testUpdateResourcesLastUpdatedProperty() = runTest {
val yesterday = yesterday()
Expand Down

0 comments on commit eec186f

Please sign in to comment.