mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-26 16:10:11 +08:00
fix MockNormalMember modify admin (#2420)
* fix MockNormalMember modify admin (untested) * modify as required * fix changeOwner (tested) * update test * update tests
This commit is contained in:
parent
56bfc65d82
commit
aa84e6d337
@ -108,10 +108,11 @@ internal class MockGroupImpl(
|
||||
}
|
||||
|
||||
override suspend fun changeOwner(member: NormalMember) {
|
||||
if (member === owner) return
|
||||
val oldOwner = owner
|
||||
val oldPerm = member.permission
|
||||
member.mock().mockApi.permission = MemberPermission.OWNER
|
||||
oldOwner.mock().mockApi.permission = MemberPermission.MEMBER
|
||||
member.mock().mockApi.permission = MemberPermission.OWNER
|
||||
owner = member
|
||||
|
||||
if (member === botAsMember) {
|
||||
|
@ -162,7 +162,7 @@ internal class MockNormalMemberImpl(
|
||||
val newPerm = if (operation) MemberPermission.ADMINISTRATOR else MemberPermission.MEMBER
|
||||
if (newPerm != permission) {
|
||||
val oldPerm = permission
|
||||
mockApi.permission = oldPerm
|
||||
mockApi.permission = newPerm
|
||||
MemberPermissionChangeEvent(this, oldPerm, newPerm).broadcast()
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,14 @@
|
||||
package net.mamoe.mirai.mock.test.mock
|
||||
|
||||
import net.mamoe.mirai.contact.MemberPermission
|
||||
import net.mamoe.mirai.event.events.BotGroupPermissionChangeEvent
|
||||
import net.mamoe.mirai.event.events.MemberPermissionChangeEvent
|
||||
import net.mamoe.mirai.mock.test.MockBotTestBase
|
||||
import net.mamoe.mirai.mock.utils.simpleMemberInfo
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
import kotlin.test.assertSame
|
||||
|
||||
internal class MockMemberTest : MockBotTestBase() {
|
||||
@Test
|
||||
@ -21,4 +25,53 @@ internal class MockMemberTest : MockBotTestBase() {
|
||||
val m = bot.addGroup(111, "aaa").addMember(simpleMemberInfo(222, "bbb", permission = MemberPermission.MEMBER))
|
||||
assertNotEquals("", m.avatarUrl)
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun changeOwner() = runTest {
|
||||
val group = bot.addGroup(111, "aaa")
|
||||
val member = group.addMember(simpleMemberInfo(222, "bbb", permission = MemberPermission.MEMBER))
|
||||
val events = runAndReceiveEventBroadcast {
|
||||
group.changeOwner(member)
|
||||
assertSame(member, group.owner)
|
||||
assertSame(MemberPermission.OWNER, member.permission)
|
||||
}
|
||||
assertEquals(2, events.size)
|
||||
assertIsInstance<MemberPermissionChangeEvent>(events[0]) {
|
||||
assertSame(member, this.member)
|
||||
assertSame(MemberPermission.OWNER, new)
|
||||
assertSame(MemberPermission.MEMBER, origin)
|
||||
assertSame(group, this.group)
|
||||
}
|
||||
assertIsInstance<BotGroupPermissionChangeEvent>(events[1]) {
|
||||
assertSame(MemberPermission.MEMBER, new)
|
||||
assertSame(MemberPermission.OWNER, origin)
|
||||
assertSame(group, this.group)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun modifyAdmin() = runTest {
|
||||
val group = bot.addGroup(111, "aaa")
|
||||
group.changeOwner(group.botAsMember)
|
||||
val m = group.addMember(simpleMemberInfo(222, "bbb", permission = MemberPermission.MEMBER))
|
||||
val events = runAndReceiveEventBroadcast {
|
||||
m.modifyAdmin(true)
|
||||
assertEquals(MemberPermission.ADMINISTRATOR, m.permission)
|
||||
m.modifyAdmin(false)
|
||||
assertEquals(MemberPermission.MEMBER, m.permission)
|
||||
}
|
||||
assertEquals(2, events.size)
|
||||
assertIsInstance<MemberPermissionChangeEvent>(events[0]) {
|
||||
assertSame(m, member)
|
||||
assertSame(MemberPermission.MEMBER, origin)
|
||||
assertSame(MemberPermission.ADMINISTRATOR, new)
|
||||
assertSame(group, this.group)
|
||||
}
|
||||
assertIsInstance<MemberPermissionChangeEvent>(events[1]) {
|
||||
assertSame(m, member)
|
||||
assertSame(MemberPermission.ADMINISTRATOR, origin)
|
||||
assertSame(MemberPermission.MEMBER, new)
|
||||
assertSame(group, this.group)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user