@@ -55,14 +55,18 @@ import com.wire.kalium.persistence.dao.UserDAO
55
55
import com.wire.kalium.persistence.dao.conversation.ConversationDAO
56
56
import com.wire.kalium.persistence.dao.member.MemberEntity
57
57
import com.wire.kalium.util.time.UNIX_FIRST_DATE
58
+ import io.mockative.Matchers
58
59
import io.mockative.Mock
59
60
import io.mockative.any
60
61
import io.mockative.coEvery
61
62
import io.mockative.coVerify
62
63
import io.mockative.eq
63
64
import io.mockative.fake.valueOf
64
65
import io.mockative.matchers.AnyMatcher
66
+ import io.mockative.matchers.EqualsMatcher
67
+ import io.mockative.matchers.Matcher
65
68
import io.mockative.matchers.PredicateMatcher
69
+ import io.mockative.matches
66
70
import io.mockative.mock
67
71
import io.mockative.once
68
72
import io.mockative.twice
@@ -126,7 +130,9 @@ class ConnectionRepositoryTest {
126
130
arrangement
127
131
.withSuccessfulFetchSelfUserConnectionsResponse(arrangement.stubUserProfileDTO)
128
132
.withSuccessfulGetConversationById(arrangement.stubConversationID1)
129
- .withSuccessfulCreateConnectionResponse(userId)
133
+ .withSuccessfulCreateConnectionResponse(
134
+ userId = EqualsMatcher (userId)
135
+ )
130
136
.withSelfUserTeamId(Either .Right (TestUser .SELF .teamId))
131
137
.withFetchSentConversationSucceed()
132
138
@@ -170,11 +176,15 @@ class ConnectionRepositoryTest {
170
176
fun givenAConnectionRequest_WhenSendingAConnectionAndPersistingReturnsAnError_thenTheConnectionShouldNotBePersisted () = runTest {
171
177
// given
172
178
val userId = NetworkUserId (" user_id" , " domain_id" )
179
+ val expectedConnection = Arrangement .stubConnectionOne.copy(status = ConnectionStateDTO .SENT )
173
180
val (arrangement, connectionRepository) = Arrangement ().arrange()
174
181
arrangement
175
182
.withSuccessfulFetchSelfUserConnectionsResponse(arrangement.stubUserProfileDTO)
176
183
.withSuccessfulGetUserById(arrangement.stubUserEntity.id)
177
- .withSuccessfulCreateConnectionResponse(userId)
184
+ .withSuccessfulCreateConnectionResponse(
185
+ result = expectedConnection,
186
+ userId = EqualsMatcher (userId)
187
+ )
178
188
.withSuccessfulGetConversationById(arrangement.stubConversationID1)
179
189
.withErrorOnPersistingConnectionResponse(userId)
180
190
.withSelfUserTeamId(Either .Right (TestUser .SELF .teamId))
@@ -205,7 +215,7 @@ class ConnectionRepositoryTest {
205
215
206
216
// when
207
217
val result = connectionRepository.updateConnectionStatus(UserId (userId.value, userId.domain), ConnectionState .ACCEPTED )
208
- result.shouldSucceed { arrangement .stubConnectionOne }
218
+ result.shouldSucceed { Arrangement .stubConnectionOne }
209
219
210
220
// then
211
221
coVerify {
@@ -328,7 +338,7 @@ class ConnectionRepositoryTest {
328
338
329
339
// when
330
340
val result = connectionRepository.ignoreConnectionRequest(UserId (userId.value, userId.domain))
331
- result.shouldSucceed { arrangement .stubConnectionOne }
341
+ result.shouldSucceed { Arrangement .stubConnectionOne }
332
342
333
343
// then
334
344
coVerify {
@@ -368,7 +378,7 @@ class ConnectionRepositoryTest {
368
378
369
379
// when
370
380
val result = connectionRepository.ignoreConnectionRequest(UserId (userId.value, userId.domain))
371
- result.shouldSucceed { arrangement .stubConnectionOne }
381
+ result.shouldSucceed { Arrangement .stubConnectionOne }
372
382
373
383
// then
374
384
coVerify {
@@ -388,7 +398,7 @@ class ConnectionRepositoryTest {
388
398
389
399
// when
390
400
val result = connectionRepository.ignoreConnectionRequest(UserId (userId.value, userId.domain))
391
- result.shouldFail { arrangement .stubConnectionOne }
401
+ result.shouldFail { Arrangement .stubConnectionOne }
392
402
393
403
// then
394
404
coVerify {
@@ -428,15 +438,7 @@ class ConnectionRepositoryTest {
428
438
conversationRepository = conversationRepository
429
439
)
430
440
431
- val stubConnectionOne = ConnectionDTO (
432
- conversationId = " conversationId1" ,
433
- from = " fromId" ,
434
- lastUpdate = Instant .UNIX_FIRST_DATE ,
435
- qualifiedConversationId = ConversationId (" conversationId1" , " domain" ),
436
- qualifiedToId = NetworkUserId (" connectionId1" , " domain" ),
437
- status = ConnectionStateDTO .ACCEPTED ,
438
- toId = " connectionId1"
439
- )
441
+
440
442
val stubConnectionTwo = ConnectionDTO (
441
443
conversationId = " conversationId2" ,
442
444
from = " fromId" ,
@@ -503,10 +505,13 @@ class ConnectionRepositoryTest {
503
505
return this
504
506
}
505
507
506
- suspend fun withSuccessfulCreateConnectionResponse (userId : NetworkUserId ): Arrangement {
508
+ suspend fun withSuccessfulCreateConnectionResponse (
509
+ result : ConnectionDTO = stubConnectionOne,
510
+ userId : Matcher <NetworkUserId >
511
+ ): Arrangement {
507
512
coEvery {
508
- connectionApi.createConnection(eq( userId) )
509
- }.returns(NetworkResponse .Success (stubConnectionOne , mapOf (), 200 ))
513
+ connectionApi.createConnection(matches { userId.matches(it) } )
514
+ }.returns(NetworkResponse .Success (result , mapOf (), 200 ))
510
515
511
516
return this
512
517
}
@@ -623,5 +628,17 @@ class ConnectionRepositoryTest {
623
628
}
624
629
625
630
fun arrange () = this to connectionRepository
631
+
632
+ companion object {
633
+ val stubConnectionOne = ConnectionDTO (
634
+ conversationId = " conversationId1" ,
635
+ from = " fromId" ,
636
+ lastUpdate = Instant .UNIX_FIRST_DATE ,
637
+ qualifiedConversationId = ConversationId (" conversationId1" , " domain" ),
638
+ qualifiedToId = NetworkUserId (" connectionId1" , " domain" ),
639
+ status = ConnectionStateDTO .ACCEPTED ,
640
+ toId = " connectionId1"
641
+ )
642
+ }
626
643
}
627
644
}
0 commit comments