Skip to content

Commit

Permalink
Merge pull request #8 from niscy-eudiw/feature/test/DashboardInteractor
Browse files Browse the repository at this point in the history
Adds unit tests for DashBoard Interactor.
  • Loading branch information
stzouvaras authored Feb 27, 2024
2 parents af5e368 + 8f415aa commit fa6ce63
Show file tree
Hide file tree
Showing 6 changed files with 934 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ import eu.europa.ec.eudi.wallet.document.nameSpacedDataJSONObject
import eu.europa.ec.resourceslogic.R
import eu.europa.ec.resourceslogic.provider.ResourceProvider
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

fun extractValueFromDocumentOrEmpty(
document: Document,
key: String
): String {
val docType = document.docType.toDocumentTypeUi()
val documentJsonObject =
document.nameSpacedDataJSONObject.get(docType.codeName) as? JSONObject
return documentJsonObject?.getStringFromJsonOrEmpty(key) ?: ""
return try {
val docType = document.docType.toDocumentTypeUi()
val documentJsonObject =
document.nameSpacedDataJSONObject.get(docType.codeName) as? JSONObject
return documentJsonObject?.getStringFromJsonOrEmpty(key) ?: ""
} catch (e: JSONException) {
""
}
}

fun extractFullNameFromDocumentOrEmpty(document: Document): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2023 European Commission
*
* Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European
* Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work
* except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the Licence for the specific language
* governing permissions and limitations under the Licence.
*/

package eu.europa.ec.commonfeature.util

import androidx.annotation.VisibleForTesting
import eu.europa.ec.commonfeature.model.DocumentTypeUi
import eu.europa.ec.commonfeature.model.DocumentUi

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
object TestsConstants {
const val mockedId1 = "000001"
const val mockedId2 = "000002"
const val mockedUserFirstName = "JAN"
const val mockedUserBase64Portrait = "SE"
const val mockedDocUiNamePid = "National ID"
const val mockedDocUiNameMdl = "Driving License"
const val mockedNoUserFistNameFound = ""
const val mockedNoUserBase64PortraitFound = ""
const val mockedNoExpirationDateFound = "-"
const val mockedFormattedExpirationDate = "30 Mar 2050"

val mockedFullPidUi = DocumentUi(
documentId = mockedId1,
documentName = mockedDocUiNamePid,
documentType = DocumentTypeUi.PID,
documentExpirationDateFormatted = mockedFormattedExpirationDate,
documentImage = "",
documentDetails = emptyList(),
)

val mockedFullMdlUi = DocumentUi(
documentId = mockedId2,
documentName = mockedDocUiNameMdl,
documentType = DocumentTypeUi.MDL,
documentExpirationDateFormatted = mockedFormattedExpirationDate,
documentImage = "",
documentDetails = emptyList(),
)

val mockedMdlUiWithNoUserNameAndNoUserImage: DocumentUi = mockedFullMdlUi

val mockedMdlUiWithNoExpirationDate: DocumentUi = mockedFullMdlUi.copy(
documentExpirationDateFormatted = mockedNoExpirationDateFound
)

val mockedFullDocumentsUi: List<DocumentUi> = listOf(
mockedFullPidUi, mockedFullMdlUi
)
}
Loading

0 comments on commit fa6ce63

Please sign in to comment.