Skip to content

Commit

Permalink
Merge pull request #45 from uport-project/support/style-lint-check
Browse files Browse the repository at this point in the history
Apply latest detekt rules and refactor test code
  • Loading branch information
mirceanis committed Mar 20, 2020
2 parents a2a0593 + 497cfde commit cd4ada4
Show file tree
Hide file tree
Showing 48 changed files with 936 additions and 232 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
# upload test coverage report!
- run: bash <(curl -s https://codecov.io/bash)

# run linter
- run: ./gradlew detekt
- store_artifacts:
path: ./build/reports

workflows:
version: 2
workflow:
Expand Down
24 changes: 12 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
buildscript {

ext {
kotlin_version = '1.3.70'
kotlin_serialization_version = '0.20.0'
kotlin_version = "1.3.70"
kotlin_serialization_version = "0.20.0"
coroutines_version = "1.3.5"

junit_version = "4.12"
mockk_version = "1.9.3"
assertk_version = "0.13"
detekt_version = "1.0.0-RC14"
assertk_version = "0.22"
detekt_version = "1.6.0"
jacoco_version = "0.8.4"

okhttp_version = "4.4.1"
Expand All @@ -22,7 +22,7 @@ buildscript {
khash_version = "1.0.0-RC5"
kbase58_version = "0.1"
spongycastle_version = "1.58.0.0"
uport_kotlin_common_version = "0.4.2"
uport_kotlin_common_version = "0.4.3"

current_release_version = "0.3.5"
}
Expand Down Expand Up @@ -56,8 +56,8 @@ detekt {
input = files(
"$projectDir"
)
//config = "${projectDir}/detekt.yml"
filters = ".*test.*,.*/resources/.*,.*/tmp/.*,.*/build/.*"
config = files("${projectDir}/detekt.yml")
baseline = file("${projectDir}/detekt_baseline.xml")
parallel = true
reports {
xml {
Expand All @@ -73,7 +73,7 @@ detekt {

allprojects {

apply plugin: 'jacoco'
apply plugin: "jacoco"

jacoco {
toolVersion = jacoco_version
Expand All @@ -82,7 +82,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url "https://jitpack.io" }
maven { url "https://kotlin.bintray.com/kotlinx" }
// mavenLocal()
}
Expand All @@ -96,9 +96,9 @@ allprojects {
}
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'org.jetbrains.kotlin' && requested.name in [
'kotlin-reflect', 'kotlin-stdlib', 'kotlin-stdlib-common',
'kotlin-stdlib-jdk7', 'kotlin-stdlib-jdk8',
if (requested.group == "org.jetbrains.kotlin" && requested.name in [
"kotlin-reflect", "kotlin-stdlib", "kotlin-stdlib-common",
"kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8",
]) {
details.useVersion kotlin_version
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.uport.credential_status
package me.uport.credentialstatus

import me.uport.sdk.universaldid.DIDDocument

Expand Down Expand Up @@ -41,4 +41,4 @@ interface StatusResolver {
* Checks the status of a given credential and returns a [CredentialStatus] or throws an error
*/
suspend fun checkStatus(credential: String, didDoc: DIDDocument): CredentialStatus
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package me.uport.credential_status
package me.uport.credentialstatus

import me.uport.sdk.universaldid.DIDDocument
import me.uport.sdk.universaldid.UniversalDID.method
import me.uport.sdk.universaldid.UniversalDID.registerResolver

/**
*
Expand Down Expand Up @@ -36,12 +34,13 @@ class UniversalStatusResolver : StatusResolver {

val statusEntry = getStatusEntry(credential)

if (statusEntry.type.isBlank() || !resolvers.containsKey(statusEntry.type)) {
throw IllegalStateException("There is no StatusResolver registered to check status using '${statusEntry.type}' method.")
} else {
return resolvers[statusEntry.type]?.checkStatus(credential, didDoc)
?: throw IllegalStateException("There StatusResolver for '$statusEntry.type' failed to resolve for an unknown reason.")
val resolver = resolvers[statusEntry.type]

check(statusEntry.type.isNotBlank() && resolver != null) {
"There is no StatusResolver registered to check status using '${statusEntry.type}' method."
}

return resolver.checkStatus(credential, didDoc)
}


Expand All @@ -54,4 +53,4 @@ class UniversalStatusResolver : StatusResolver {
}
resolvers[resolver.method] = resolver
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.uport.credential_status
package me.uport.credentialstatus

import me.uport.sdk.jwt.JWTTools

Expand All @@ -15,4 +15,4 @@ fun getStatusEntry(credential: String): StatusEntry {
status["type"] ?: "",
status["id"] ?: ""
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

package me.uport.sdk.credential_status

import assertk.all
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import kotlinx.coroutines.runBlocking
import me.uport.credential_status.CredentialStatus
import me.uport.credential_status.StatusResolver
import me.uport.credential_status.UniversalStatusResolver
import me.uport.credentialstatus.CredentialStatus
import me.uport.credentialstatus.StatusResolver
import me.uport.credentialstatus.UniversalStatusResolver
import me.uport.sdk.ethrdid.EthrDIDDocument
import me.uport.sdk.testhelpers.coAssert
import me.uport.sdk.universaldid.DIDDocument
Expand Down Expand Up @@ -58,9 +60,10 @@ class UniversalStatusResolverTests {
coAssert {
UniversalStatusResolver().checkStatus(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NzMwNDczNTEsInN0YXR1cyI6eyJ0eXBlIjoiRXRoclN0YXR1c1JlZ2lzdHJ5MjAxOSIsImlkIjoicmlua2VieToweDFFNDY1MWRjYTVFZjM4NjM2ZTJFNEQ3QTZGZjRkMjQxM2ZDNTY0NTAifSwiaXNzIjoiZGlkOmV0aHI6MHgxZmNmOGZmNzhhYzUxMTdkOWM5OWI4MzBjNzRiNjY2OGQ2YWMzMjI5In0.MHabafA0UxJuQJ0Z-7Egb57WRlgj4_zf96B0LUhRyXgVDU5RABIczTTTXWjcuKVzhJc_-FuhRI8uQYmQQNxKzgA"
, didDoc
,
didDoc
)
}.thrownError {
}.isFailure().all {
isInstanceOf(IllegalStateException::class)
}
}
Expand All @@ -74,7 +77,7 @@ class UniversalStatusResolverTests {
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
didDoc
)
}.thrownError {
}.isFailure().all {
isInstanceOf(IllegalArgumentException::class)
}
}
Expand All @@ -86,4 +89,4 @@ class UniversalStatusResolverTests {
val result = resolver.checkStatus(successfulCred, didDoc)
assertThat(result).isEqualTo(TestStatus(BigInteger.ONE))
}
}
}
Loading

0 comments on commit cd4ada4

Please sign in to comment.