-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 3489-and-3490-and-refactor-pdf-config
- Loading branch information
Showing
5 changed files
with
207 additions
and
94 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
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
93 changes: 93 additions & 0 deletions
93
android/quest/src/test/java/org/smartregister/fhircore/quest/pdf/PdfLauncherViewModelTest.kt
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,93 @@ | ||
/* | ||
* Copyright 2021-2024 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.quest.pdf | ||
|
||
import com.google.android.fhir.FhirEngine | ||
import com.google.android.fhir.SearchResult | ||
import com.google.android.fhir.search.Search | ||
import io.mockk.coEvery | ||
import io.mockk.mockk | ||
import java.util.Date | ||
import kotlinx.coroutines.test.runTest | ||
import org.hl7.fhir.r4.model.Patient | ||
import org.hl7.fhir.r4.model.Questionnaire | ||
import org.hl7.fhir.r4.model.QuestionnaireResponse | ||
import org.hl7.fhir.r4.model.ResourceType | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.smartregister.fhircore.engine.data.local.DefaultRepository | ||
import org.smartregister.fhircore.engine.util.extension.asReference | ||
import org.smartregister.fhircore.engine.util.extension.yesterday | ||
import org.smartregister.fhircore.quest.robolectric.RobolectricTest | ||
import org.smartregister.fhircore.quest.ui.pdf.PdfLauncherViewModel | ||
|
||
class PdfLauncherViewModelTest : RobolectricTest() { | ||
|
||
private lateinit var fhirEngine: FhirEngine | ||
private lateinit var defaultRepository: DefaultRepository | ||
private lateinit var viewModel: PdfLauncherViewModel | ||
|
||
@Before | ||
fun setUp() { | ||
fhirEngine = mockk() | ||
defaultRepository = | ||
DefaultRepository( | ||
fhirEngine = fhirEngine, | ||
dispatcherProvider = mockk(), | ||
sharedPreferencesHelper = mockk(), | ||
configurationRegistry = mockk(), | ||
configService = mockk(), | ||
configRulesExecutor = mockk(), | ||
fhirPathDataExtractor = mockk(), | ||
parser = mockk(), | ||
context = mockk(), | ||
) | ||
viewModel = PdfLauncherViewModel(defaultRepository) | ||
} | ||
|
||
@Test | ||
fun testRetrieveQuestionnaireResponseReturnsLatestResponse() = runTest { | ||
val patient = Patient().apply { id = "p1" } | ||
val questionnaire = Questionnaire().apply { id = "q1" } | ||
val olderQuestionnaireResponse = | ||
QuestionnaireResponse().apply { | ||
id = "qr2" | ||
meta.lastUpdated = yesterday() | ||
subject = patient.asReference() | ||
setQuestionnaire(questionnaire.asReference().reference) | ||
} | ||
val latestQuestionnaireResponse = | ||
QuestionnaireResponse().apply { | ||
id = "qr1" | ||
meta.lastUpdated = Date() | ||
subject = patient.asReference() | ||
setQuestionnaire(questionnaire.asReference().reference) | ||
} | ||
val questionnaireResponses = | ||
listOf(olderQuestionnaireResponse, latestQuestionnaireResponse).map { | ||
SearchResult(it, null, null) | ||
} | ||
|
||
coEvery { fhirEngine.search<QuestionnaireResponse>(any<Search>()) } returns | ||
questionnaireResponses | ||
val result = | ||
viewModel.retrieveQuestionnaireResponse(questionnaire.id, patient.id, ResourceType.Patient) | ||
|
||
assertEquals(latestQuestionnaireResponse.id, result!!.id) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.