Skip to content

Commit

Permalink
fix: resolve corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaizen-7 committed Feb 11, 2022
1 parent 109570c commit da54226
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ package it.ministerodellasalute.verificaC19sdk.model
* This enum class defines all the possible status of certifications after their verification.
*
*/
enum class CertificateStatus {
NOT_VALID,
NOT_VALID_YET,
VALID,
EXPIRED,
REVOKED,
NOT_EU_DCC,
TEST_NEEDED;
enum class CertificateStatus(val value: String) {
NOT_VALID("notValid"),
NOT_VALID_YET("notValidYet"),
VALID("valid"),
EXPIRED("expired"),
REVOKED("revoked"),
NOT_EU_DCC("notEuDCC"),
TEST_NEEDED("verificationIsNeeded");
}

fun CertificateStatus.applyFullModel(fullModel: Boolean): CertificateStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RecoveryValidationStrategy : ValidationStrategy {
return when {
LocalDate.now().isBefore(startDate.plusDays(startDaysToAdd)) -> CertificateStatus.NOT_VALID_YET
LocalDate.now().isAfter(endDate) -> CertificateStatus.EXPIRED
else -> return if (scanMode == ScanMode.BOOSTER) CertificateStatus.TEST_NEEDED else CertificateStatus.VALID
else -> return if (scanMode == ScanMode.BOOSTER && !recoveryBis) CertificateStatus.TEST_NEEDED else CertificateStatus.VALID
}
} catch (e: Exception) {
return CertificateStatus.NOT_VALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class TestValidationStrategy : ValidationStrategy {
override fun checkCertificate(certificateModel: CertificateModel, ruleSet: RuleSet): CertificateStatus {
val test: TestModel = certificateModel.tests!!.first()
val scanMode = certificateModel.scanMode

if (scanMode == ScanMode.BOOSTER || scanMode == ScanMode.STRENGTHENED || scanMode == ScanMode.SCHOOL) return CertificateStatus.NOT_VALID
val isTestNotAllowed = scanMode == ScanMode.BOOSTER || scanMode == ScanMode.STRENGTHENED || scanMode == ScanMode.SCHOOL

if (test.resultType == TestResult.DETECTED) {
return CertificateStatus.NOT_VALID
Expand Down Expand Up @@ -74,6 +73,7 @@ class TestValidationStrategy : ValidationStrategy {
return when {
LocalDateTime.now().isBefore(startDate) -> CertificateStatus.NOT_VALID_YET
LocalDateTime.now().isAfter(endDate) -> CertificateStatus.EXPIRED
isTestNotAllowed -> CertificateStatus.NOT_VALID
else -> {
val birthDate = certificateModel.dateOfBirth?.toValidDateOfBirth()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class VaccineValidationStrategy : ValidationStrategy {
*
*/
override fun checkCertificate(certificateModel: CertificateModel, ruleSet: RuleSet): CertificateStatus {
val vaccination = certificateModel.vaccinations!!.last()
if (!ruleSet.hasRulesForVaccine(vaccination.medicinalProduct)) return CertificateStatus.NOT_VALID

return try {
validateWithScanMode(certificateModel, ruleSet)
} catch (e: Exception) {
Expand Down

0 comments on commit da54226

Please sign in to comment.