Skip to content

Commit

Permalink
[#13] Add JsonApi, move dependencies to plugins and minor reviews res…
Browse files Browse the repository at this point in the history
…olves
  • Loading branch information
kaungkhantsoe committed Aug 25, 2023
1 parent 4c14109 commit 84fbc5c
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 56 deletions.
6 changes: 4 additions & 2 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import org.jetbrains.kotlin.konan.properties.loadProperties

plugins {
id(Plugins.ANDROID_APPLICATION)
id(Plugins.KOVER)
kotlin(Plugins.ANDROID)
}

val keystoreProperties = rootDir.loadGradleProperties("signing.properties")
val keystoreProperties = loadProperties("$rootDir/signing.properties")

android {
namespace = "co.nimblehq.kmm.template.android"
Expand Down Expand Up @@ -100,7 +102,7 @@ dependencies {
implementation(COMPOSE)
}

with(Dependencies.Logging) {
with(Dependencies.Log) {
implementation(TIMBER)
}

Expand Down
24 changes: 12 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath(Dependencies.Gradle.BUILD_KONFIG)
classpath(Dependencies.Kotlin.KOTLIN_GRADLE_PLUGIN)
classpath(Dependencies.Kotlin.KOTLIN_SERIALIZATION)
}
}
import org.jetbrains.kotlin.konan.properties.loadProperties

plugins {
//trick: for the same plugin versions in all sub-modules
Expand All @@ -18,8 +7,19 @@ plugins {
id(Plugins.DETEKT) version Versions.DETEKT
id(Plugins.KOVER) version Versions.KOVER
id(Plugins.KSP) version Versions.KSP
id(Plugins.BUILD_KONFIG) version Versions.BUILD_KONFIG apply (false)
kotlin(Plugins.ANDROID) version Versions.KOTLIN apply (false)
kotlin(Plugins.MULTIPLATFORM) version Versions.KOTLIN apply (false)
kotlin(Plugins.KOTLIN_SERIALIZATION) version Versions.KOTLIN
}

allprojects {
val buildProperties = loadProperties("$rootDir/buildKonfig.properties")
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}

detekt {
Expand Down
4 changes: 4 additions & 0 deletions buildKonfig.properties.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Staging env
STAGING_BASE_URL=
# Production env
PRODUCTION_BASE_URL=
21 changes: 6 additions & 15 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object Versions {

const val GRADLE = "8.0.2"

const val JSON_API = "0.1.0"
const val JUNIT = "4.13.2"

const val KOIN = "3.3.2"
Expand All @@ -41,11 +42,6 @@ object Versions {
}

object Dependencies {
object Gradle {
const val BUILD_KONFIG = "com.codingfeline.buildkonfig:buildkonfig-gradle-plugin:${Versions.BUILD_KONFIG}"

const val GRADLE = "com.android.tools.build:gradle:${Versions.GRADLE}"
}

object AndroidX {
const val ACTIVITY_COMPOSE = "androidx.activity:activity-compose:${Versions.ANDROIDX_ACTIVITY_COMPOSE}"
Expand All @@ -70,11 +66,6 @@ object Dependencies {
const val COMPOSE = "io.insert-koin:koin-androidx-compose:${Versions.KOIN_ANDROIDX_COMPOSE}"
}

object Kotlin {
const val KOTLIN_GRADLE_PLUGIN = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.KOTLIN}"
const val KOTLIN_SERIALIZATION = "org.jetbrains.kotlin:kotlin-serialization:${Versions.KOTLIN}"
}

object Ktor {
const val ANDROID = "io.ktor:ktor-client-android:${Versions.KTOR}"
const val AUTH = "io.ktor:ktor-client-auth:${Versions.KTOR}"
Expand All @@ -92,6 +83,11 @@ object Dependencies {
const val SERIALIZATION = "io.ktor:ktor-client-serialization:${Versions.KTOR}"
}

object Log {
const val NAPIER = "io.github.aakira:napier:${Versions.NAPIER}"
const val TIMBER = "com.jakewharton.timber:timber:${Versions.TIMBER}"
}

object Test {
const val COMPOSE_UI_TEST_JUNIT = "androidx.compose.ui:ui-test-junit4:${Versions.COMPOSE}"
const val COMPOSE_UI_TEST_MANIFEST = "androidx.compose.ui:ui-test-manifest:${Versions.COMPOSE}"
Expand All @@ -111,9 +107,4 @@ object Dependencies {

const val TURBINE = "app.cash.turbine:turbine:${Versions.TURBINE}"
}

object Logging {
const val NAPIER = "io.github.aakira:napier:${Versions.NAPIER}"
const val TIMBER = "com.jakewharton.timber:timber:${Versions.TIMBER}"
}
}
12 changes: 0 additions & 12 deletions buildSrc/src/main/java/FileExt.kt

This file was deleted.

2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ naming:
minimumFunctionNameLength: 3
FunctionNaming:
active: true
functionPattern: '[a-zA-Z][a-zA-Z0-9]*'
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
ignoreAnnotated: [ 'Composable' ]
MatchingDeclarationName:
active: true
Expand Down
2 changes: 1 addition & 1 deletion sample/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ naming:
minimumFunctionNameLength: 3
FunctionNaming:
active: true
functionPattern: '[a-zA-Z][a-zA-Z0-9]*'
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
ignoreAnnotated: [ 'Composable' ]
MatchingDeclarationName:
active: true
Expand Down
9 changes: 6 additions & 3 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
import org.jetbrains.kotlin.konan.properties.loadProperties

plugins {
kotlin(Plugins.MULTIPLATFORM)
Expand Down Expand Up @@ -58,7 +59,7 @@ kotlin {
implementation(AUTH)
}

implementation(Dependencies.Logging.NAPIER)
implementation(Dependencies.Log.NAPIER)
}
}
val commonTest by getting {
Expand All @@ -73,13 +74,14 @@ kotlin {
}
}
}

val androidMain by getting {
dependencies {
implementation(Dependencies.Koin.ANDROID)
implementation(Dependencies.Koin.COMPOSE)
implementation(Dependencies.Ktor.ANDROID)
}
}
val androidUnitTest by getting

val iosX64Main by getting
val iosArm64Main by getting
Expand All @@ -93,6 +95,7 @@ kotlin {
implementation(Dependencies.Ktor.IOS)
}
}
val iosTest by getting
}
}

Expand Down Expand Up @@ -122,7 +125,7 @@ android {
}
}

val buildKonfigProperties = rootDir.loadGradleProperties("buildKonfig.properties")
val buildKonfigProperties = loadProperties("$rootDir/buildKonfig.properties")
buildkonfig {
packageName = "co.nimblehq.kmm.template"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.nimblehq.kmm.template.data.remote.datasources

import co.nimblehq.kmm.template.data.remote.model.response.UserResponse
import co.nimblehq.kmm.template.data.remote.model.responses.UserResponse
import co.nimblehq.kmm.template.data.remote.ApiClient

interface UserRemoteDataSource {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nimblehq.kmm.template.data.remote.model.response
package co.nimblehq.kmm.template.data.remote.model.responses

import co.nimblehq.kmm.template.domain.model.UserModel
import kotlinx.serialization.SerialName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package co.nimblehq.kmm.template.data.repository
package co.nimblehq.kmm.template.data.repositories

import co.nimblehq.kmm.template.data.extensions.flowTransform
import co.nimblehq.kmm.template.data.remote.datasources.UserRemoteDataSource
import co.nimblehq.kmm.template.data.remote.model.response.toModel
import co.nimblehq.kmm.template.data.remote.model.responses.toModel
import co.nimblehq.kmm.template.domain.model.UserModel
import co.nimblehq.kmm.template.domain.repositories.Repository
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package co.nimblehq.kmm.template.di.module

import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import co.nimblehq.kmm.template.data.repository.RepositoryImpl
import co.nimblehq.kmm.template.data.repositories.RepositoryImpl
import co.nimblehq.kmm.template.domain.repositories.Repository
import org.koin.dsl.bind

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package co.nimblehq.kmm.template.domain.exceptions

data class ApiException(
val code: String?,
override val message: String?,
override val cause: Throwable? = null
) : RuntimeException(message, cause)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nimblehq.kmm.template.data.repository
package co.nimblehq.kmm.template.data.repositories

import app.cash.turbine.test
import co.nimblehq.kmm.template.data.remote.datasources.UserRemoteDataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class GetUsersUseCaseTest {
private lateinit var useCase: GetUsersUseCase

@BeforeTest
fun setup() {
fun setUp() {
useCase = GetUsersUseCaseImpl(mockRepository)
}

@Test
fun `When calling getUsersUseCase successfully - it returns users`() = runTest {
fun `When calling getUsers successfully - it returns users`() = runTest {
given(mockRepository)
.function(mockRepository::getUsers)
.whenInvoked()
Expand All @@ -39,7 +39,7 @@ class GetUsersUseCaseTest {
}

@Test
fun `when calling getUsersUseCase fails - it throws the corresponding error`() = runTest {
fun `when calling getUsers fails - it throws the corresponding error`() = runTest {
val throwable = Throwable()
given(mockRepository)
.function(mockRepository::getUsers)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package co.nimblehq.kmm.template.extensions

import app.cash.turbine.test
import co.nimblehq.kmm.template.data.extensions.flowTransform
import co.nimblehq.kmm.template.domain.model.UserModel
import io.kotest.matchers.shouldBe
import io.ktor.utils.io.errors.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

@ExperimentalCoroutinesApi
class ResponseMappingTest {

@Test
fun `When mapping API request flow failed with Exception - it returns Exception error`() = runTest {
flowTransform<UserModel> {
throw Exception()
}.test {
awaitError() shouldBe Exception()
}
}

@Test
fun `When mapping API request flow failed with a generic error - it returns that error`() = runTest {
val error = IOException("no internet")
flowTransform<UserModel> {
throw error
}.test {
awaitError() shouldBe error
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.nimblehq.kmm.template.util

import co.nimblehq.kmm.template.data.remote.model.response.UserResponse
import co.nimblehq.kmm.template.data.remote.model.responses.UserResponse
import co.nimblehq.kmm.template.domain.model.UserModel

object Fake {
Expand Down

0 comments on commit 84fbc5c

Please sign in to comment.