-
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.
* Filter Questionnaires by publisher g6pd (#571) * SharedPreferencesHelper.read default value null * Make SharedPreferencesHelper.read default value nullable in line with Android API SharedPrefereneces.getString. (#571) * Add UserResponse to engine * Expose keycloak GET /userInfo response as data class to simplify property access. (#571) * Store User Questionnaire Publisher as Preference * Store User Questionnaire Publisher in SharedPreferences (#571) * Filter synchronized Questionnaires by cached publisher. (#571) * Make SharedPreferencesHelper.write value nullable * Make SharedPreferencesHelper.write value nullable in line with Android API SharedPrefereneces.Editor.putString. (#607) * Add UserResponse.questionnairePublisher * Replace UserResponse.realmAccess.roles with UserResponse.questionnairePublisher. * Enable key/value rather than array access therefore enabling a more generic solution. (#607) * Store User Questionnaire Publisher as Preference * Store User Questionnaire Publisher in SharedPreferences (#607) * Log Quest Questionnaire filtering Change (#571) (#607) * Setup engine module test application class Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com> * Add more tests for LoginViewModel Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com> * Run eir:spotlessApply Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com> * add refresh token * Fix failing LoginViewModel tests Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com> Co-authored-by: Elly Kitoto <junkmailstoelly@gmail.com> Co-authored-by: Peter Lubell-Doughtie <peter@ona.io>
- Loading branch information
1 parent
8c5dfd3
commit 70c8a14
Showing
16 changed files
with
664 additions
and
119 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
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
25 changes: 25 additions & 0 deletions
25
...rc/main/java/org/smartregister/fhircore/engine/data/remote/model/response/UserResponse.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,25 @@ | ||
/* | ||
* Copyright 2021 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.engine.data.remote.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserResponse( | ||
@SerialName("questionnaire_publisher") val questionnairePublisher: String? = null | ||
) |
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
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
150 changes: 150 additions & 0 deletions
150
android/engine/src/test/java/org/smartregister/fhircore/engine/impl/FhirApplication.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,150 @@ | ||
/* | ||
* Copyright 2021 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.engine.impl | ||
|
||
import android.app.Application | ||
import androidx.test.core.app.ApplicationProvider | ||
import ca.uhn.fhir.rest.gclient.TokenClientParam | ||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException | ||
import com.google.android.fhir.FhirEngine | ||
import com.google.android.fhir.SyncDownloadContext | ||
import com.google.android.fhir.db.impl.dao.LocalChangeToken | ||
import com.google.android.fhir.db.impl.dao.SquashedLocalChange | ||
import com.google.android.fhir.search.Search | ||
import com.google.android.fhir.sync.Sync | ||
import com.google.android.fhir.sync.SyncJob | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.spyk | ||
import java.time.OffsetDateTime | ||
import org.hl7.fhir.r4.context.SimpleWorkerContext | ||
import org.hl7.fhir.r4.model.Identifier | ||
import org.hl7.fhir.r4.model.Resource | ||
import org.hl7.fhir.r4.model.ResourceType | ||
import org.robolectric.annotation.Config | ||
import org.smartregister.fhircore.engine.auth.AuthCredentials | ||
import org.smartregister.fhircore.engine.auth.AuthenticationService | ||
import org.smartregister.fhircore.engine.configuration.app.ApplicationConfiguration | ||
import org.smartregister.fhircore.engine.configuration.app.ConfigurableApplication | ||
import org.smartregister.fhircore.engine.configuration.app.applicationConfigurationOf | ||
import org.smartregister.fhircore.engine.shadow.ShadowNpmPackageProvider | ||
import org.smartregister.fhircore.engine.shadow.activity.ShadowLoginActivity | ||
import org.smartregister.fhircore.engine.util.SecureSharedPreference | ||
|
||
@Config(shadows = [ShadowNpmPackageProvider::class]) | ||
class FhirApplication : Application(), ConfigurableApplication { | ||
|
||
override val syncJob: SyncJob | ||
get() = spyk(Sync.basicSyncJob(ApplicationProvider.getApplicationContext())) | ||
|
||
override var applicationConfiguration: ApplicationConfiguration = applicationConfigurationOf() | ||
|
||
override val authenticationService: AuthenticationService | ||
get() = spyk(FhirAuthenticationService()) | ||
|
||
override val fhirEngine: FhirEngine | ||
get() = spyk(FhirEngineImpl()) | ||
|
||
override val secureSharedPreference: SecureSharedPreference by lazy { | ||
val secureSharedPreferenceSpy = | ||
spyk(SecureSharedPreference(ApplicationProvider.getApplicationContext())) | ||
every { secureSharedPreferenceSpy.retrieveCredentials() } returns | ||
AuthCredentials( | ||
username = "demo", | ||
password = "Amani123", | ||
refreshToken = "", | ||
sessionToken = "same-gibberish-string-as-token" | ||
) | ||
secureSharedPreferenceSpy | ||
} | ||
|
||
override val resourceSyncParams: Map<ResourceType, Map<String, String>> | ||
get() = mapOf() | ||
|
||
override val workerContextProvider: SimpleWorkerContext | ||
get() = mockk(relaxed = true) { SimpleWorkerContext() } | ||
|
||
override fun configureApplication(applicationConfiguration: ApplicationConfiguration) { | ||
this.applicationConfiguration = applicationConfiguration | ||
} | ||
|
||
override fun schedulePeriodicSync() { | ||
// Do nothing | ||
} | ||
|
||
inner class FhirEngineImpl : FhirEngine { | ||
|
||
val mockedResourcesStore = mutableListOf<Resource>() | ||
|
||
override suspend fun count(search: Search): Long = 1 | ||
|
||
override suspend fun getLastSyncTimeStamp(): OffsetDateTime? = OffsetDateTime.now() | ||
|
||
override suspend fun <R : Resource> load(clazz: Class<R>, id: String): R { | ||
val existingResource = | ||
mockedResourcesStore.find { it.hasId() && it.id == id } | ||
?: throw ResourceNotFoundException(id) | ||
return existingResource as R | ||
} | ||
|
||
override suspend fun <R : Resource> remove(clazz: Class<R>, id: String) { | ||
mockedResourcesStore.removeIf { it.id == id } | ||
} | ||
|
||
override suspend fun <R : Resource> save(vararg resource: R) { | ||
mockedResourcesStore.addAll(resource) | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override suspend fun <R : Resource> search(search: Search): List<R> = | ||
mockedResourcesStore.filter { search.filter(TokenClientParam(it.id), Identifier()) } as | ||
List<R> | ||
|
||
override suspend fun syncDownload(download: suspend (SyncDownloadContext) -> List<Resource>) { | ||
// Do nothing | ||
} | ||
|
||
override suspend fun syncUpload( | ||
upload: suspend (List<SquashedLocalChange>) -> List<LocalChangeToken> | ||
) { | ||
// Do nothing | ||
} | ||
|
||
override suspend fun <R : Resource> update(resource: R) { | ||
// Replace old resource | ||
mockedResourcesStore.removeIf { it.hasId() && it.id == resource.id } | ||
mockedResourcesStore.add(resource) | ||
} | ||
} | ||
|
||
inner class FhirAuthenticationService : | ||
AuthenticationService(ApplicationProvider.getApplicationContext()) { | ||
override fun skipLogin(): Boolean = false | ||
|
||
override fun getLoginActivityClass(): Class<*> = ShadowLoginActivity::class.java | ||
|
||
override fun getAccountType(): String = "test.account.type" | ||
|
||
override fun clientSecret(): String = "test.client.secret" | ||
|
||
override fun clientId(): String = "test.client.id" | ||
|
||
override fun providerScope(): String = "openid" | ||
|
||
override fun getApplicationConfigurations(): ApplicationConfiguration = applicationConfiguration | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
android/engine/src/test/java/org/smartregister/fhircore/engine/rule/CoroutineTestRule.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,52 @@ | ||
/* | ||
* Copyright 2021 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.engine.rule | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.TestCoroutineDispatcher | ||
import kotlinx.coroutines.test.TestCoroutineScope | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
import org.smartregister.fhircore.engine.util.DispatcherProvider | ||
|
||
@ExperimentalCoroutinesApi | ||
class CoroutineTestRule(val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) : | ||
TestRule, TestCoroutineScope by TestCoroutineScope(testDispatcher) { | ||
|
||
val testDispatcherProvider = | ||
object : DispatcherProvider { | ||
override fun default() = testDispatcher | ||
override fun io() = testDispatcher | ||
override fun main() = testDispatcher | ||
override fun unconfined() = testDispatcher | ||
} | ||
|
||
override fun apply(base: Statement?, description: Description?) = | ||
object : Statement() { | ||
@Throws(Throwable::class) | ||
override fun evaluate() { | ||
Dispatchers.setMain(testDispatcher) | ||
base?.evaluate() | ||
Dispatchers.resetMain() | ||
testDispatcher.cleanupTestCoroutines() | ||
} | ||
} | ||
} |
Oops, something went wrong.