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

Provide missing QuestionnaireResponse in bundle param for FhirCarePlanGenerator#conditionallyUpdateResourceStatus #2643

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions android/engine/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
<uses-permission android:name="android.permission.CALL_PHONE" />

<application>

<activity
android:name=".HiltActivityForTest"
android:exported="false"
android:theme="@style/AppTheme" />

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package org.smartregister.fhircore.engine.sync

import androidx.test.core.app.ApplicationProvider
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.HiltTestApplication
import javax.inject.Inject
import org.junit.After
import org.junit.Assert
Expand All @@ -26,6 +28,7 @@ import org.junit.Rule
import org.junit.Test
import org.robolectric.Robolectric
import org.smartregister.fhircore.engine.HiltActivityForTest
import org.smartregister.fhircore.engine.R
import org.smartregister.fhircore.engine.app.fakes.Faker
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.app.ConfigService
Expand Down Expand Up @@ -53,6 +56,7 @@ class SyncListenerManagerTest : RobolectricTest() {
fun setUp() {
hiltAndroidRule.inject()
hiltActivityForTest = activityController.get()
ApplicationProvider.getApplicationContext<HiltTestApplication>().setTheme(R.style.AppTheme)
syncListenerManager =
SyncListenerManager(
configService = configService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ constructor(
fhirCarePlanGenerator.conditionallyUpdateResourceStatus(
questionnaireConfig = questionnaireConfig,
subject = subject,
bundle = bundle,
bundle = newBundle,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021-2023 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

import androidx.appcompat.app.AppCompatActivity
import com.google.android.fhir.sync.SyncJobStatus
import dagger.hilt.android.AndroidEntryPoint
import org.smartregister.fhircore.engine.sync.OnSyncListener
import org.smartregister.fhircore.engine.util.annotation.ExcludeFromJacocoGeneratedReport

@ExcludeFromJacocoGeneratedReport
@AndroidEntryPoint
class HiltActivityForTest : AppCompatActivity(), OnSyncListener {
override fun onSync(syncJobStatus: SyncJobStatus) {
// DO nothing. This activity implements OnSyncListener for testing purposes
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.spyk
import javax.inject.Inject
import kotlinx.coroutines.test.runTest
import org.hl7.fhir.r4.model.Enumerations
import org.hl7.fhir.r4.model.Questionnaire
Expand All @@ -51,7 +50,6 @@ import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
import org.smartregister.fhircore.engine.domain.model.QuestionnaireType
import org.smartregister.fhircore.engine.domain.model.RuleConfig
import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.extension.decodeResourceFromString
Expand All @@ -62,8 +60,6 @@ class QuestionnaireActivityTest : RobolectricTest() {

@get:Rule(order = 0) var hiltRule = HiltAndroidRule(this)

@Inject lateinit var resourceDataRulesExecutor: ResourceDataRulesExecutor

private val context: Application = ApplicationProvider.getApplicationContext()
private lateinit var questionnaireConfig: QuestionnaireConfig
private lateinit var questionnaireJson: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ class QuestionnaireViewModelTest : RobolectricTest() {
onSuccessfulSubmission(capture(idsTypesSlot), questionnaireResponse)
}

// Captured bundle slot should contain QuestionnaireResponse
Assert.assertTrue(
bundleSlot.captured.entry.any {
it.resource.resourceType == ResourceType.QuestionnaireResponse
},
)

// ID of extracted resources passed to the onSuccessfulSubmission callback
Assert.assertEquals(idsTypesSlot.captured.firstOrNull()?.idPart, patient.logicalId)

Expand Down