Skip to content

Commit

Permalink
chore: more arrangement classes (#1956)
Browse files Browse the repository at this point in the history
* chore: more arrangement classes

* Update logic/src/commonTest/kotlin/com/wire/kalium/logic/util/arrangement/repository/ConnectionRepositoryArrangement.kt

Co-authored-by: Vitor Hugo Schwaab <vitor@schwaab.dev>

* Update logic/src/commonTest/kotlin/com/wire/kalium/logic/util/arrangement/repository/ConversationRepositoryArrangement.kt

Co-authored-by: Vitor Hugo Schwaab <vitor@schwaab.dev>

* Update logic/src/commonTest/kotlin/com/wire/kalium/logic/util/arrangement/repository/UserRepositoryArrangement.kt

Co-authored-by: Vitor Hugo Schwaab <vitor@schwaab.dev>

* Update logic/src/commonTest/kotlin/com/wire/kalium/logic/util/arrangement/usecase/PersistMessageUseCaseArrangement.kt

Co-authored-by: Vitor Hugo Schwaab <vitor@schwaab.dev>

---------

Co-authored-by: Vitor Hugo Schwaab <vitor@schwaab.dev>
  • Loading branch information
Garzas and vitorhugods authored Aug 7, 2023
1 parent fe7a70e commit 56387a4
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ interface MemberDAOArrangement {
result: Flow<List<MemberEntity>>,
conversationId: Matcher<QualifiedIDEntity> = any()
)

fun withDeleteMembersByQualifiedID(
conversationId: Matcher<QualifiedIDEntity> = any(),
memberIdList: Matcher<List<QualifiedIDEntity>> = any()
)
}

class MemberDAOArrangementImpl : MemberDAOArrangement {
Expand Down Expand Up @@ -138,6 +143,16 @@ class MemberDAOArrangementImpl : MemberDAOArrangement {
.whenInvokedWith(conversationId)
.thenReturn(result)
}

override fun withDeleteMembersByQualifiedID(
conversationId: Matcher<QualifiedIDEntity>,
memberIdList: Matcher<List<QualifiedIDEntity>>
) {
given(memberDAO)
.suspendFunction(memberDAO::deleteMembersByQualifiedID)
.whenInvokedWith(memberIdList, conversationId)
.thenReturn(Unit)
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.util.arrangement.repository

import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.data.connection.ConnectionRepository
import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.functional.Either
import io.mockative.Mock
import io.mockative.given
import io.mockative.mock
import kotlinx.coroutines.flow.Flow

internal interface ConnectionRepositoryArrangement {
val connectionRepository: ConnectionRepository

fun withGetConnections(result: Either<StorageFailure, Flow<List<ConversationDetails>>>)
}

internal open class ConnectionRepositoryArrangementImpl : ConnectionRepositoryArrangement {
@Mock
override val connectionRepository: ConnectionRepository = mock(ConnectionRepository::class)

override fun withGetConnections(
result: Either<StorageFailure, Flow<List<ConversationDetails>>>,
) {
given(connectionRepository)
.suspendFunction(connectionRepository::getConnections)
.whenInvoked()
.thenReturn(result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.util.arrangement.repository

import com.wire.kalium.logic.data.conversation.ConversationRepository
import io.mockative.Mock
import io.mockative.mock

internal interface ConversationRepositoryArrangement {
val conversationRepository: ConversationRepository
}

internal open class ConversationRepositoryArrangementImpl : ConversationRepositoryArrangement {
@Mock
override val conversationRepository: ConversationRepository = mock(ConversationRepository::class)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.util.arrangement.repository

import com.wire.kalium.logic.data.user.UserRepository
import io.mockative.Mock
import io.mockative.mock

internal interface UserRepositoryArrangement {
val userRepository: UserRepository
}

internal open class UserRepositoryArrangementImpl : UserRepositoryArrangement {
@Mock
override val userRepository: UserRepository = mock(UserRepository::class)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.util.arrangement.usecase

import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.data.message.PersistMessageUseCase
import com.wire.kalium.logic.functional.Either
import io.mockative.Mock
import io.mockative.any
import io.mockative.given
import io.mockative.mock

internal interface PersistMessageUseCaseArrangement {
val persistMessageUseCase: PersistMessageUseCase
fun withPersistingMessage(result: Either<CoreFailure, Unit>): PersistMessageUseCaseArrangementImpl
}

internal open class PersistMessageUseCaseArrangementImpl : PersistMessageUseCaseArrangement {
@Mock
override val persistMessageUseCase: PersistMessageUseCase = mock(PersistMessageUseCase::class)

override fun withPersistingMessage(result: Either<CoreFailure, Unit>) = apply {
given(persistMessageUseCase)
.suspendFunction(persistMessageUseCase::invoke)
.whenInvokedWith(any())
.thenReturn(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ interface MemberDAO {
suspend fun insertMembers(memberList: List<MemberEntity>, groupId: String)
suspend fun deleteMemberByQualifiedID(userID: QualifiedIDEntity, conversationID: QualifiedIDEntity)
suspend fun deleteMembersByQualifiedID(userIDList: List<QualifiedIDEntity>, conversationID: QualifiedIDEntity)
suspend fun deleteMembersByQualifiedID(userIDList: List<QualifiedIDEntity>, groupId: String)
suspend fun observeConversationMembers(qualifiedID: QualifiedIDEntity): Flow<List<MemberEntity>>
suspend fun updateConversationMemberRole(conversationId: QualifiedIDEntity, userId: UserIDEntity, role: MemberEntity.Role)
suspend fun updateOrInsertOneOnOneMemberWithConnectionStatus(
Expand Down Expand Up @@ -113,14 +112,6 @@ internal class MemberDAOImpl internal constructor(
}
}

override suspend fun deleteMembersByQualifiedID(userIDList: List<QualifiedIDEntity>, groupId: String) {
withContext(coroutineContext) {
conversationsQueries.selectByGroupId(groupId).executeAsOneOrNull()?.let {
nonSuspendDeleteMembersByQualifiedID(userIDList, it.qualifiedId)
}
}
}

override suspend fun observeConversationMembers(qualifiedID: QualifiedIDEntity): Flow<List<MemberEntity>> {
return memberQueries.selectAllMembersByConversation(qualifiedID)
.asFlow()
Expand Down

0 comments on commit 56387a4

Please sign in to comment.