Skip to content

Commit

Permalink
Added additional test validity checks. Updated related models logic (#19
Browse files Browse the repository at this point in the history
)
  • Loading branch information
oleksandrsarapulovgl authored Jun 2, 2021
1 parent 73f2837 commit b9ba5b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
7 changes: 3 additions & 4 deletions decoder/src/main/java/dgca/verifier/app/decoder/model/Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ data class Test(

) : Serializable {

fun isTestValid(): Boolean {
return testResult == TestResult.NOT_DETECTED.value &&
parseToUtcTimestamp(dateTimeOfCollection).isBefore(OffsetDateTime.now())
}
fun isResultNegative(): Boolean = testResult == TestResult.NOT_DETECTED.value

fun isDateInThePast(): Boolean = parseToUtcTimestamp(dateTimeOfCollection).isBefore(OffsetDateTime.now())

fun getTestResultType(): TestResult {
return when (testResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,27 @@ data class VerificationResult(
) {

fun isValid(): Boolean {
val isTestValid = testVerification?.isDetected ?: true
val isTestValid = testVerification?.isTestValid() ?: true
return base45Decoded && zlibDecoded && coseVerified && cborDecoded && isSchemaValid && isTestValid &&
isIssuedTimeCorrect && isNotExpired
}

/**
* Checks if all the checks but signature validation passed.
* Ultimately value {@code true} returned by the method
* would mean that signature validation has been checked. And it failed.
* Checks if test hasn't been taken yet.
*/
fun isSignatureInvalid(): Boolean {
val isTestValid = testVerification?.isDetected ?: true
return (base45Decoded && zlibDecoded && cborDecoded && isSchemaValid && isTestValid) && !coseVerified
fun isTestDateInTheFuture(): Boolean = if (testVerification == null) {
false
} else {
!testVerification!!.isTestDateInThePast
}

/**
* Checks if verification is for the test, and related test result is {@code positive).
*/
fun isTestWithPositiveResult(): Boolean = if (testVerification == null) {
false
} else {
!testVerification!!.isTestResultNegative
}

override fun toString(): String {
Expand All @@ -61,6 +69,6 @@ data class VerificationResult(
}
}

data class TestVerificationResult(
val isDetected: Boolean
)
data class TestVerificationResult(val isTestResultNegative: Boolean, val isTestDateInThePast: Boolean) {
fun isTestValid(): Boolean = isTestResultNegative && isTestDateInThePast
}

0 comments on commit b9ba5b3

Please sign in to comment.