Skip to content

Commit 2d7033d

Browse files
committed
Cover RealPostSourceOfTruthReader
Signed-off-by: Matt Ramotar <[email protected]>
1 parent adde145 commit 2d7033d

File tree

18 files changed

+458
-301
lines changed

18 files changed

+458
-301
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: chmod +x gradlew
4040

4141
- name: Build and Test with Coverage
42-
run: ./gradlew clean build koverXmlReport --stacktrace
42+
run: ./gradlew build koverXmlReport --stacktrace
4343

4444
- name: Upload Coverage to Codecov
4545
uses: codecov/codecov-action@v4

xplat/lib/repositories/post/impl/src/commonMain/kotlin/org/mobilenativefoundation/trails/xplat/lib/repositories/post/impl/RealPostComponent.kt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import org.mobilenativefoundation.trails.xplat.lib.repositories.post.api.PostCom
99
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.api.PostRepository
1010
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.PostStore
1111
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.PostStoreFactory
12-
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database.PostDAO
13-
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database.RealPostDAO
12+
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database.*
1413
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.fetcher.PostFetcherServices
1514
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.fetcher.RealPostFetcherServices
1615
import org.mobilenativefoundation.trails.xplat.lib.rest.api.TrailsClientComponent
@@ -35,16 +34,32 @@ abstract class RealPostComponent(
3534
)
3635
}
3736

37+
@Provides
38+
fun providePostPredicateEvaluator(): PostPredicateEvaluator {
39+
return RealPostPredicateEvaluator()
40+
}
41+
42+
@Provides
43+
fun providePostComparer(): PostComparer {
44+
return RealPostComparer()
45+
}
3846

3947
@Provides
4048
fun providePostStore(
41-
postFetcherServices: PostFetcherServices
49+
postFetcherServices: PostFetcherServices,
50+
postDAO: PostDAO,
51+
postPredicateEvaluator: PostPredicateEvaluator,
52+
comparer: PostComparer
4253
): PostStore {
4354
return PostStoreFactory(
4455
client = trailsClientComponent.trailsClient,
4556
trailsDatabase = database,
4657
coroutineDispatcher = TrailsDispatchers.io,
47-
postFetcherServices = postFetcherServices
58+
postDAO = postDAO,
59+
postFetcherServices = postFetcherServices,
60+
predicateEvaluator = postPredicateEvaluator,
61+
comparer = comparer
62+
4863
).create()
4964
}
5065

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.extensions
2+
3+
import org.mobilenativefoundation.trails.xplat.lib.operations.query.Order
4+
5+
6+
object OrderExtensions {
7+
fun Order<*>?.toDomain(): org.mobilenativefoundation.trails.xplat.lib.models.query.Order? {
8+
return this?.let {
9+
org.mobilenativefoundation.trails.xplat.lib.models.query.Order(
10+
propertyName = it.property.name,
11+
direction = it.direction,
12+
propertyType = it.propertyType
13+
)
14+
}
15+
}
16+
}

xplat/lib/repositories/post/impl/src/commonMain/kotlin/org/mobilenativefoundation/trails/xplat/lib/repositories/post/impl/store/PostStoreFactory.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import org.mobilenativefoundation.trails.xplat.lib.models.post.Post
1010
import org.mobilenativefoundation.trails.xplat.lib.models.post.PostOutput
1111
import org.mobilenativefoundation.trails.xplat.lib.operations.io.Operation
1212
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.bookkeeper.PostBookkeeperFactory
13-
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database.PostSourceOfTruthFactory
14-
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database.PostSourceOfTruthReader
15-
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database.PostSourceOfTruthWriter
13+
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database.*
1614
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.fetcher.PostFetcherFactory
1715
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.fetcher.PostFetcherServices
1816
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.updater.PostUpdaterFactory
@@ -29,10 +27,13 @@ class PostStoreFactory(
2927
client: PostOperations,
3028
trailsDatabase: TrailsDatabase,
3129
coroutineDispatcher: CoroutineDispatcher,
32-
postFetcherServices: PostFetcherServices
30+
postFetcherServices: PostFetcherServices,
31+
postDAO: PostDAO,
32+
predicateEvaluator: PostPredicateEvaluator,
33+
comparer: PostComparer
3334
) {
3435

35-
private val sourceOfTruthReader = PostSourceOfTruthReader(trailsDatabase, coroutineDispatcher)
36+
private val sourceOfTruthReader = RealPostSourceOfTruthReader(postDAO, predicateEvaluator, comparer, coroutineDispatcher)
3637
private val sourceOfTruthWriter = PostSourceOfTruthWriter(trailsDatabase, coroutineDispatcher)
3738
private val sourceOfTruthFactory = PostSourceOfTruthFactory(sourceOfTruthReader, sourceOfTruthWriter)
3839
private val fetcherFactory = PostFetcherFactory(postFetcherServices)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database
2+
3+
import org.mobilenativefoundation.trails.xplat.lib.models.post.Post
4+
import org.mobilenativefoundation.trails.xplat.lib.operations.query.Order
5+
6+
interface PostComparer {
7+
fun compare(a: Post.Node, b: Post.Node, order: Order<Post.Node>?): Int
8+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database
22

3+
import kotlinx.coroutines.launch
34
import org.mobilenativefoundation.trails.xplat.lib.db.PostEntity
5+
import org.mobilenativefoundation.trails.xplat.lib.db.TrailsDatabase
46
import org.mobilenativefoundation.trails.xplat.lib.models.post.Post
7+
import org.mobilenativefoundation.trails.xplat.lib.models.post.PostOutput
8+
import org.mobilenativefoundation.trails.xplat.lib.operations.io.Operation
9+
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.extensions.PostExtensions.asNode
510

611
interface PostDAO {
712
suspend fun insertOne(entity: PostEntity)
813
suspend fun insertOneComposite(composite: Post.Composite)
14+
suspend fun findOne(id: Int): PostEntity?
15+
suspend fun findAll(): List<PostEntity>
16+
fun findOneAndAssembleComposite(id: Int): Post.Composite?
917
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.database
2+
3+
import org.mobilenativefoundation.trails.xplat.lib.models.post.Post
4+
import org.mobilenativefoundation.trails.xplat.lib.operations.query.Predicate
5+
6+
interface PostPredicateEvaluator {
7+
fun evaluate(predicate: Predicate<Post.Node, *>, item: Post.Node): Boolean
8+
}

xplat/lib/repositories/post/impl/src/commonMain/kotlin/org/mobilenativefoundation/trails/xplat/lib/repositories/post/impl/store/database/PostSourceOfTruthFactory.kt

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import kotlinx.coroutines.channels.BufferOverflow
44
import kotlinx.coroutines.flow.MutableSharedFlow
55
import kotlinx.coroutines.flow.asSharedFlow
66
import org.mobilenativefoundation.store.store5.SourceOfTruth
7+
import org.mobilenativefoundation.trails.xplat.lib.models.post.Post
78
import org.mobilenativefoundation.trails.xplat.lib.operations.io.Operation
89
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.PostOperation
910
import org.mobilenativefoundation.trails.xplat.lib.models.post.PostOutput
@@ -26,7 +27,7 @@ class PostSourceOfTruthFactory(
2627
// We only invoke the SOT on reads
2728
require(operation is Operation.Query)
2829

29-
reader.handleRead(operation) {
30+
handleRead(operation) {
3031
mutableSharedFlow.emit(it)
3132
}
3233

@@ -42,54 +43,23 @@ class PostSourceOfTruthFactory(
4243
TODO()
4344
}
4445
)
45-
}
4646

47-
// SourceOfTruth.of(
48-
// reader = { operation ->
49-
//
50-
// val mutableSharedFlow = MutableSharedFlow<Post?>(
51-
// replay = 8,
52-
// extraBufferCapacity = 20,
53-
// onBufferOverflow = BufferOverflow.DROP_OLDEST
54-
// )
55-
//
56-
// // We only invoke the SOT on reads
57-
// require(operation is Operation.Query)
58-
//
59-
// when (operation) {
60-
// is PostOperation.Query.FindOne -> {
61-
// val id = operation.key.id
62-
// coroutineScope.launch {
63-
// mutableSharedFlow.emit(trailsDatabase.postQueries.assemblePostModel(id.toLong()))
64-
// }
65-
// }
66-
//
67-
// is PostOperation.Query.FindOneComposite -> {
68-
// val id = operation.key.id
69-
// coroutineScope.launch {
70-
// mutableSharedFlow.emit(trailsDatabase.postQueries.assembleCompositePost(id.toLong()))
71-
// }
72-
// }
73-
//
74-
// is PostOperation.Query.ObserveOne -> {
75-
// val id = operation.key.id
76-
// coroutineScope.launch {
77-
// trailsDatabase.postQueries.observePostModel(id.toLong()).collect {
78-
// mutableSharedFlow.emit(it)
79-
// }
80-
// }
81-
// }
82-
//
83-
// is PostOperation.Query.ObserveOneComposite -> {
84-
// val id = operation.key.id
85-
// coroutineScope.launch {
86-
// trailsDatabase.postQueries.observeCompositePost(id.toLong()).collect {
87-
// mutableSharedFlow.emit(it)
88-
// }
89-
// }
90-
// }
91-
//
92-
// is PostOperation.Query.QueryOne -> TODO()
93-
// }
94-
//
95-
// mutableSharedFlow.asSharedFlow()
47+
private fun handleRead(
48+
operation: Operation.Query<Post.Key, Post.Properties, Post.Edges, Post.Node>,
49+
emit: suspend (PostOutput?) -> Unit
50+
) {
51+
52+
when (operation) {
53+
is Operation.Query.FindAll -> TODO()
54+
is Operation.Query.FindMany -> TODO()
55+
is Operation.Query.FindOne -> reader.findOne(operation, emit)
56+
is Operation.Query.FindOneComposite -> TODO()
57+
is Operation.Query.ObserveMany -> TODO()
58+
is Operation.Query.ObserveOne -> TODO()
59+
is Operation.Query.ObserveOneComposite -> TODO()
60+
is Operation.Query.QueryMany -> TODO()
61+
is Operation.Query.QueryOne -> TODO()
62+
is Operation.Query.QueryManyComposite -> reader.queryManyComposite(operation.query, emit)
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)