Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWCore] Add Resource Tagging #2499

Merged
merged 45 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3e90564
rework auth items
sevenreup Apr 26, 2023
1d2b0e0
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup May 26, 2023
3ed6fb2
init tagging
sevenreup Jun 5, 2023
ffff742
update register
sevenreup Jun 6, 2023
a4224b4
update
sevenreup Jun 6, 2023
6aaa2fd
update sync
sevenreup Jun 9, 2023
0b05614
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jun 9, 2023
39564ac
update sync key
sevenreup Jun 9, 2023
dc34c49
fix location syncs
sevenreup Jun 18, 2023
639c7af
fix activity listener
sevenreup Jun 21, 2023
92536ca
test fixes
sevenreup Jun 26, 2023
c638406
fixes
sevenreup Jun 26, 2023
cea8e95
replace app with default
sevenreup Jun 27, 2023
7e5da06
tests fixed
sevenreup Jun 27, 2023
a72ff10
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jun 27, 2023
2a34a3e
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jun 27, 2023
2a28a52
stuff
sevenreup Jun 27, 2023
9991c0b
test fixes
sevenreup Jun 27, 2023
a525453
Merge branch 'mwcore-migrate-auth-code' of github.com:opensrp/fhircor…
sevenreup Jun 27, 2023
067b2ca
Update CqlContentTest.kt
sevenreup Jun 27, 2023
79f8267
add tests
sevenreup Jun 28, 2023
3718c03
add tests
sevenreup Jun 28, 2023
d0c116a
update appsettings
sevenreup Jun 29, 2023
cbef459
update
sevenreup Jul 4, 2023
9c2b9e9
update
sevenreup Jul 5, 2023
5b8c799
update QuestViewmodel
sevenreup Jul 11, 2023
b99b092
Update QuestionnaireActivity.kt
sevenreup Jul 12, 2023
eee0185
Update LoginViewModel.kt
sevenreup Jul 12, 2023
3807eb9
Update TokenAuthenticator.kt
sevenreup Jul 13, 2023
cf69b88
update auth
sevenreup Jul 17, 2023
39695d3
Update AppSettingActivityTest.kt
sevenreup Jul 17, 2023
c1de593
updates
sevenreup Jul 18, 2023
2d0962b
update resource tags
sevenreup Jul 20, 2023
cb62edf
block to finish saving data
sevenreup Jul 26, 2023
1c099a5
update
sevenreup Jul 26, 2023
518b38a
spotless run
sevenreup Jul 26, 2023
59d95d4
Update network_security_config.xml
sevenreup Jul 28, 2023
49fc301
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
LZRS Jul 28, 2023
183cc6a
Fix failed AppNotIdleException for some Compose tests
LZRS Jul 30, 2023
3c91f1b
Disable catching of non-test related exceptions
LZRS Jul 30, 2023
875eb8f
add tests
sevenreup Jul 31, 2023
0631d83
Update SharedPreferencesHelperTest.kt
sevenreup Jul 31, 2023
1002bc7
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jul 31, 2023
7885fa2
Update AndroidExtensions.kt
sevenreup Jul 31, 2023
3449870
update tests
sevenreup Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
sevenreup committed Jun 28, 2023
commit 3718c03be44760fd4ae11dcb04ac5b01ab87462b
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package org.smartregister.fhircore.engine.configuration
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.db.ResourceNotFoundException
import com.google.android.fhir.logicalId
import com.google.android.fhir.search.Search
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
Expand Down Expand Up @@ -240,4 +242,44 @@ class ConfigurationRegistryTest : RobolectricTest() {
}
Assert.assertFalse(configurationRegistry.isWorkflowPoint(sectionComponent))
}

@Test
@ExperimentalCoroutinesApi
fun testAddOrUpdate() {
// when does not exist
val patient = Faker.buildPatient()
coEvery { fhirEngine.get(patient.resourceType, patient.logicalId) } returns patient
coEvery { fhirEngine.update(any()) } returns Unit

runTest {
val previousLastUpdate = patient.meta.lastUpdated
configurationRegistry.addOrUpdate(patient)
Assert.assertNotEquals(previousLastUpdate, patient.meta.lastUpdated)
}

// when exists
runTest {
val previousLastUpdate = patient.meta.lastUpdated
configurationRegistry.addOrUpdate(patient)
Assert.assertNotEquals(previousLastUpdate, patient.meta.lastUpdated)
}
}

@Test
@ExperimentalCoroutinesApi
fun testAddOrUpdateCatchesResourceNotFound() {
val patient = Faker.buildPatient()
coEvery { fhirEngine.get(patient.resourceType, patient.logicalId) } throws
ResourceNotFoundException("", "")
coEvery { fhirEngine.create(any()) } returns listOf()

runTest {
val previousLastUpdate = patient.meta.lastUpdated
configurationRegistry.addOrUpdate(patient)
Assert.assertNotEquals(previousLastUpdate, patient.meta.lastUpdated)
}

coVerify(inverse = true) { fhirEngine.update(any()) }
coVerify { fhirEngine.create(patient) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ package org.smartregister.fhircore.engine.data.remote.fhir.resource
import io.mockk.coEvery
import io.mockk.mockk
import io.mockk.spyk
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.OperationOutcome
import org.hl7.fhir.r4.model.Patient
import org.hl7.fhir.r4.model.ResourceType
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.smartregister.fhircore.engine.rule.CoroutineTestRule

@OptIn(ExperimentalCoroutinesApi::class)
class FhirResourceDataSourceTest {

@get:Rule(order = 1) val coroutineTestRule = CoroutineTestRule()

private val resourceService: FhirResourceService = mockk()

private lateinit var fhirResourceDataSource: FhirResourceDataSource
Expand All @@ -45,16 +42,16 @@ class FhirResourceDataSourceTest {

@Test
fun testLoadDataShouldRetrieveResource() {
coroutineTestRule.runBlockingTest {
runTest {
val bundle = Bundle()
coEvery { resourceService.getResource(any()) } returns bundle
Assert.assertEquals(bundle, fhirResourceDataSource.loadData("http://fake.url"))
Assert.assertEquals(bundle, fhirResourceDataSource.getResource("http://fake.url"))
}
}

@Test
fun testInsertShouldAddResource() {
coroutineTestRule.runBlockingTest {
runTest {
val resource = Patient()
coEvery { resourceService.insertResource(any(), any(), any()) } returns resource
Assert.assertEquals(
Expand All @@ -66,7 +63,7 @@ class FhirResourceDataSourceTest {

@Test
fun testUpdateShouldUpdateResource() {
coroutineTestRule.runBlockingTest {
runTest {
val operationOutcome = OperationOutcome()
coEvery { resourceService.updateResource(any(), any(), any()) } returns operationOutcome
Assert.assertEquals(
Expand All @@ -79,7 +76,7 @@ class FhirResourceDataSourceTest {
@Test
fun testDeleteShouldRemoveResource() {

coroutineTestRule.runBlockingTest {
runTest {
val operationOutcome = OperationOutcome()
coEvery { resourceService.deleteResource(any(), any()) } returns operationOutcome
Assert.assertEquals(
Expand All @@ -91,7 +88,7 @@ class FhirResourceDataSourceTest {

@Test
fun testSearchResourceShouldReturnBundle() {
coroutineTestRule.runBlockingTest {
runTest {
val bundle = Bundle()
coEvery { resourceService.searchResource(any(), any()) } returns bundle
Assert.assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,4 +714,15 @@ class ResourceExtensionTest : RobolectricTest() {
carePlan.addTags(meta)
Assert.assertTrue(carePlan.meta.tag.isEmpty())
}

@Test
fun logicalIdFromFhirPathExtractedIdReturnsCorrectValue() {
val logicalId = "Group/0acda8c9-3fa3-40ae-abcd-7d1fba7098b4/_history/2"
Assert.assertEquals("0acda8c9-3fa3-40ae-abcd-7d1fba7098b4", logicalId.extractLogicalIdUuid())
val otherLogicalId = "Group/0acda8c9-3fa3-40ae-abcd-7d1fba7098b4"
Assert.assertEquals(
"0acda8c9-3fa3-40ae-abcd-7d1fba7098b4",
otherLogicalId.extractLogicalIdUuid()
)
}
}