-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
336 additions
and
11 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...c/androidMain/kotlin/co/nimblehq/blisskmmic/domain/platform/datetime/DateTimeFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package co.nimblehq.blisskmmic.domain.platform.datetime | ||
|
||
actual class DateTimeFormatterImpl: DateTimeFormatter { | ||
|
||
actual override fun getFormattedString( | ||
secondsSinceEpoch: Long, | ||
format: DateFormat | ||
): String { | ||
// TODO: implement date for Android | ||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/domain/platform/datetime/DateFormat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package co.nimblehq.blisskmmic.domain.platform.datetime | ||
|
||
sealed class DateFormat(val value: String) { | ||
object DayOfWeekMonthDay: DateFormat("EEEE, MMMM d") | ||
} |
11 changes: 11 additions & 0 deletions
11
...rc/commonMain/kotlin/co/nimblehq/blisskmmic/domain/platform/datetime/DateTimeFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package co.nimblehq.blisskmmic.domain.platform.datetime | ||
|
||
interface DateTimeFormatter { | ||
|
||
fun getFormattedString(secondsSinceEpoch: Long, format: DateFormat): String | ||
} | ||
|
||
expect class DateTimeFormatterImpl(): DateTimeFormatter { | ||
|
||
override fun getFormattedString(secondsSinceEpoch: Long, format: DateFormat): String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../src/commonTest/kotlin/co/nimblehq/blisskmmic/data/repository/DeviceInfoRepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package co.nimblehq.blisskmmic.data.repository | ||
|
||
import app.cash.turbine.test | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.datetime.* | ||
import org.kodein.mock.Mocker | ||
import org.kodein.mock.UsesMocks | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
|
||
@UsesMocks(Clock::class) | ||
@ExperimentalCoroutinesApi | ||
class DeviceInfoRepositoryTest { | ||
|
||
private val mocker = Mocker() | ||
private val clock = MockClock(mocker) | ||
private val instant = Instant.DISTANT_PAST | ||
private val deviceInfoRepository = DeviceInfoRepositoryImpl(clock) | ||
|
||
@BeforeTest | ||
fun setUp() { | ||
mocker.reset() | ||
} | ||
|
||
@Test | ||
fun `When calling profile with success response, it returns correct object`() = runTest { | ||
mocker.every { | ||
clock.now() | ||
} returns instant | ||
deviceInfoRepository | ||
.getCurrentDate() | ||
.test { | ||
val item = awaitItem() | ||
val local = instant.toLocalDateTime(TimeZone.currentSystemDefault()) | ||
item.day shouldBe local.dayOfMonth | ||
item.month shouldBe local.monthNumber | ||
item.dayOfWeek shouldBe local.dayOfWeek.isoDayNumber | ||
awaitComplete() | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/data/repository/UserRepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package co.nimblehq.blisskmmic.data.repository | ||
|
||
import app.cash.turbine.test | ||
import co.nimblehq.blisskmmic.data.model.UserApiModel | ||
import co.nimblehq.blisskmmic.data.model.fakeUserApiModel | ||
import co.nimblehq.blisskmmic.data.network.datasource.MockNetworkDataSource | ||
import co.nimblehq.blisskmmic.data.network.datasource.NetworkDataSource | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.kodein.mock.Mocker | ||
import org.kodein.mock.UsesFakes | ||
import org.kodein.mock.UsesMocks | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
|
||
@UsesMocks(NetworkDataSource::class) | ||
@UsesFakes(UserApiModel::class) | ||
@ExperimentalCoroutinesApi | ||
class UserRepositoryTest { | ||
|
||
private val mocker = Mocker() | ||
private val networkDataSource = MockNetworkDataSource(mocker) | ||
private val user = fakeUserApiModel() | ||
private val userRepository = UserRepositoryImpl(networkDataSource) | ||
|
||
@BeforeTest | ||
fun setUp() { | ||
mocker.reset() | ||
} | ||
|
||
@Test | ||
fun `When calling getProfile with success response, it returns correct object`() = runTest { | ||
mocker.every { | ||
networkDataSource.profile(isAny()) | ||
} returns flowOf(user) | ||
userRepository | ||
.getProfile() | ||
.test { | ||
val item = awaitItem() | ||
item.name shouldBe user.name | ||
item.avatarUrl shouldBe user.avatarUrl | ||
awaitComplete() | ||
} | ||
} | ||
|
||
@Test | ||
fun `When calling getProfile with failure response, it returns correct error`() = runTest { | ||
mocker.every { | ||
networkDataSource.profile(isAny()) | ||
} returns flow { error("Fail") } | ||
userRepository | ||
.getProfile() | ||
.test { | ||
awaitError().message shouldBe "Fail" | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../src/commonTest/kotlin/co/nimblehq/blisskmmic/domain/usecase/GetCurrentDateUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package co.nimblehq.blisskmmic.domain.usecase | ||
|
||
import app.cash.turbine.test | ||
import co.nimblehq.blisskmmic.domain.model.DateComponents | ||
import co.nimblehq.blisskmmic.domain.repository.DeviceInfoRepository | ||
import co.nimblehq.blisskmmic.domain.repository.MockDeviceInfoRepository | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.kodein.mock.Mocker | ||
import org.kodein.mock.UsesMocks | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
|
||
@UsesMocks(DeviceInfoRepository::class) | ||
@ExperimentalCoroutinesApi | ||
class GetCurrentDateUseCaseTest { | ||
|
||
private val mocker = Mocker() | ||
private val deviceInfoRepository = MockDeviceInfoRepository(mocker) | ||
private val getCurrentDateUseCase = GetCurrentDateUseCaseImpl(deviceInfoRepository) | ||
private val dateComponents = DateComponents(day = 2, month = 2, dayOfWeek = 3) | ||
|
||
@BeforeTest | ||
fun setUp() { | ||
mocker.reset() | ||
} | ||
|
||
@Test | ||
fun `When calling getCurrent with a success response, it returns correct object`() = runTest { | ||
mocker.every { | ||
deviceInfoRepository.getCurrentDate() | ||
} returns flowOf(dateComponents) | ||
|
||
getCurrentDateUseCase() | ||
.test { | ||
val item = awaitItem() | ||
item.day shouldBe 2 | ||
item.dayOfWeek shouldBe "WEDNESDAY" | ||
item.month shouldBe "FEBRUARY" | ||
awaitComplete() | ||
} | ||
} | ||
|
||
@Test | ||
fun `When calling getCurrent with a failure response, it returns correct error`() = runTest { | ||
mocker.every { | ||
deviceInfoRepository.getCurrentDate() | ||
} returns flow { error("Fail") } | ||
|
||
getCurrentDateUseCase() | ||
.test { | ||
awaitError().message shouldBe "Fail" | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/domain/usecase/GetProfileUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package co.nimblehq.blisskmmic.domain.usecase | ||
|
||
import app.cash.turbine.test | ||
import co.nimblehq.blisskmmic.domain.model.PaginationMeta | ||
import co.nimblehq.blisskmmic.domain.model.Survey | ||
import co.nimblehq.blisskmmic.domain.model.User | ||
import co.nimblehq.blisskmmic.domain.model.fakeUser | ||
import co.nimblehq.blisskmmic.domain.repository.MockUserRepository | ||
import co.nimblehq.blisskmmic.domain.repository.SurveyRepository | ||
import co.nimblehq.blisskmmic.domain.repository.UserRepository | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.kodein.mock.Mocker | ||
import org.kodein.mock.UsesFakes | ||
import org.kodein.mock.UsesMocks | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@UsesMocks(UserRepository::class) | ||
@UsesFakes(User::class) | ||
class GetProfileUseCaseTest { | ||
|
||
private val mocker = Mocker() | ||
private val userRepository = MockUserRepository(mocker) | ||
private val user = fakeUser() | ||
private val getProfileUseCase = GetProfileUseCaseImpl(userRepository) | ||
|
||
@BeforeTest | ||
fun setUp() { | ||
mocker.reset() | ||
} | ||
|
||
@Test | ||
fun `When calling getProfile with a success response, it returns correct object`() = runTest { | ||
mocker.every { | ||
userRepository.getProfile() | ||
} returns flowOf(user) | ||
|
||
getProfileUseCase() | ||
.test { | ||
val item = awaitItem() | ||
item.name shouldBe user.name | ||
item.avatarUrl shouldBe user.avatarUrl | ||
awaitComplete() | ||
} | ||
} | ||
|
||
@Test | ||
fun `When calling getProfile with a failure response, it returns correct error`() = runTest { | ||
mocker.every { | ||
userRepository.getProfile() | ||
} returns flow { error("Fail") } | ||
|
||
getProfileUseCase() | ||
.test { | ||
awaitError().message shouldBe "Fail" | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/helpers/json/UserProfileJsonResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package co.nimblehq.blisskmmic.helpers.json | ||
|
||
const val USER_PROFILE_JSON_RESULT = """ | ||
{ | ||
"data": { | ||
"id": "1", | ||
"type": "user", | ||
"attributes": { | ||
"name": "Name", | ||
"email": "mail@mail.com", | ||
"avatar_url": "https://api.adorable.io/avatar/mail@mail.com" | ||
} | ||
} | ||
} | ||
""" |
29 changes: 29 additions & 0 deletions
29
shared/src/iosMain/kotlin/co/nimblehq/blisskmmic/domain/platform/datetime/DateFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package co.nimblehq.blisskmmic.domain.platform.datetime | ||
|
||
import platform.Foundation.* | ||
|
||
class DateFormatter { | ||
|
||
companion object { | ||
|
||
var dateFormatters:MutableMap<DateFormat, NSDateFormatter> = mutableMapOf() | ||
|
||
fun get(dateFormat: DateFormat): NSDateFormatter { | ||
return initializeIfNeeded(dateFormat) | ||
} | ||
|
||
private fun dateFormatter(dataFormat: DateFormat): NSDateFormatter { | ||
return NSDateFormatter() | ||
.also { | ||
it.dateFormat = dataFormat.value | ||
} | ||
} | ||
|
||
private fun initializeIfNeeded(dateFormat: DateFormat): NSDateFormatter { | ||
dateFormatters[dateFormat]?.let { return it } | ||
val dateFormatter = dateFormatter(dateFormat) | ||
dateFormatters[dateFormat] = dateFormatter | ||
return dateFormatter | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...c/iosMain/kotlin/co/nimblehq/blisskmmic/domain/platform/datetime/DateTimeFormatterImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package co.nimblehq.blisskmmic.domain.platform.datetime | ||
|
||
import platform.Foundation.NSDate | ||
|
||
actual class DateTimeFormatterImpl: DateTimeFormatter { | ||
|
||
actual override fun getFormattedString( | ||
secondsSinceEpoch: Long, | ||
format: DateFormat | ||
): String { | ||
val date = NSDate(secondsSinceEpoch.toDouble()) | ||
return DateFormatter.get(format).stringFromDate(date) | ||
} | ||
} |
Oops, something went wrong.