Skip to content

Commit

Permalink
Feature/temp comment (#34)
Browse files Browse the repository at this point in the history
* Temp commenting of versions

* Updated engine version comparision
  • Loading branch information
oleksandrsarapulovgl authored Jul 9, 2021
1 parent 83fb104 commit 03d62cc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DefaultCertLogicEngine(
private const val EXTERNAL_KEY = "external"
private const val PAYLOAD_KEY = "payload"
private const val CERTLOGIC_KEY = "CERTLOGIC"
private const val CERTLOGIC_VERSION = "1.0.0"
private val CERTLOGIC_VERSION: Triple<Int, Int, Int> = Triple(1, 0, 0)
}

init {
Expand Down Expand Up @@ -72,9 +72,12 @@ class DefaultCertLogicEngine(
val dataJsonNode = prepareData(externalParameter, payload)
val hcertVersion = hcertVersionString.toVersion()
rules.forEach { rule ->
val ruleEngineVersion = rule.engineVersion.toVersion()
val schemaVersion = rule.schemaVersion.toVersion()
val res = when {
rule.engine != CERTLOGIC_KEY || rule.engineVersion != CERTLOGIC_VERSION
rule.engine != CERTLOGIC_KEY
|| ruleEngineVersion == null || !CERTLOGIC_VERSION
.isGreaterOrEqualThan(ruleEngineVersion)
|| hcertVersion == null || schemaVersion == null || hcertVersion.first != schemaVersion.first -> Result.OPEN
hcertVersion.isGreaterOrEqualThan(schemaVersion) ->
when (jsonLogicValidator.isDataValid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.doThrow
import java.io.InputStream
import java.nio.charset.Charset
import java.time.ZonedDateTime
Expand Down Expand Up @@ -200,6 +199,45 @@ internal class DefaultCertLogicEngineTest {
)
}

@Test
fun testEngineVersionIsGreater() {
val hcertJson = mockHcertJson()
val rules = listOf(mockRuleRemote(engineVersion = "0.7.5")).toRules()
val externalParameter = mockExternalParameter()
doReturn(true).`when`(jsonLogicValidator).isDataValid(any(), any())

assertEquals(
Result.PASSED,
certLogicEngine.validate(
CertificateType.VACCINATION,
STANDARD_VERSION,
rules,
externalParameter,
hcertJson
)
.first().result
)
}

@Test
fun testEngineVersionIsLower() {
val hcertJson = mockHcertJson()
val rules = listOf(mockRuleRemote(engineVersion = "1.7.5")).toRules()
val externalParameter = mockExternalParameter()

assertEquals(
Result.OPEN,
certLogicEngine.validate(
CertificateType.VACCINATION,
STANDARD_VERSION,
rules,
externalParameter,
hcertJson
)
.first().result
)
}

@Test
fun testValidatedWithException() {
doReturn(null).`when`(jsonLogicValidator).isDataValid(any(), any())
Expand Down

0 comments on commit 03d62cc

Please sign in to comment.