Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ class AuthControllerTest {
val memberMock = mock(Member::class.java)
whenever(jda.getGuildById(123L)).thenReturn(guildMock)
whenever(guildMock.getMemberById("user1")).thenReturn(memberMock)
// Assume isAdmin logic - isAdmin is an extension function, mocking it might be hard.
// It likely checks permissions.
// If it's an extension function, we cannot easily mock it unless we mock the Member interface completely
// and isAdmin calls member methods.
// dev.robothanzo.werewolf.utils.isAdmin checks member.hasPermission(Administrator) or is owner.

// However, isAdmin is an extension function.
// Let's assume it returns false for mock unless we configure it.
// But for this test, we just check if it returns OK.

val response = authController.selectGuild(guildId, session)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.springframework.http.HttpStatus
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.MockitoAnnotations
Expand All @@ -27,7 +26,6 @@ import java.util.*

class SpeechControllerTest {

@InjectMocks
private lateinit var speechController: SpeechController

@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GlobalWebSocketHandlerTest {
@Test
fun testConnectionEstablished_Success() {
val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR)
whenever(session.attributes).thenReturn(mapOf("user" to user))
whenever(session.attributes).thenReturn(mutableMapOf("user" to user) as Map<String, Any>)
whenever(session.uri).thenReturn(URI("ws://localhost:8080/ws?guildId=123"))

handler.afterConnectionEstablished(session)
Expand All @@ -45,7 +45,7 @@ class GlobalWebSocketHandlerTest {

@Test
fun testConnectionEstablished_NoUser() {
whenever(session.attributes).thenReturn(emptyMap())
whenever(session.attributes).thenReturn(mutableMapOf<String, Any>())

handler.afterConnectionEstablished(session)

Expand All @@ -55,7 +55,7 @@ class GlobalWebSocketHandlerTest {
@Test
fun testConnectionEstablished_UnauthorizedRole() {
val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.PENDING)
whenever(session.attributes).thenReturn(mapOf("user" to user))
whenever(session.attributes).thenReturn(mutableMapOf("user" to user) as Map<String, Any>)

handler.afterConnectionEstablished(session)

Expand All @@ -65,7 +65,7 @@ class GlobalWebSocketHandlerTest {
@Test
fun testConnectionEstablished_GuildMismatch() {
val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR)
whenever(session.attributes).thenReturn(mapOf("user" to user))
whenever(session.attributes).thenReturn(mutableMapOf("user" to user) as Map<String, Any>)
whenever(session.uri).thenReturn(URI("ws://localhost:8080/ws?guildId=456"))

handler.afterConnectionEstablished(session)
Expand All @@ -76,7 +76,7 @@ class GlobalWebSocketHandlerTest {
@Test
fun testHandlePing() {
val payload = """{"type": "PING"}"""
doNothing().whenever(session).sendMessage(any())
whenever(session.sendMessage(any())).then { }

handler.handleMessage(session, TextMessage(payload))

Expand All @@ -89,14 +89,14 @@ class GlobalWebSocketHandlerTest {
fun testBroadcastToGuild() {
val user1 = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR)
val session1 = mock(WebSocketSession::class.java)
whenever(session1.attributes).thenReturn(mapOf("user" to user1))
whenever(session1.attributes).thenReturn(mutableMapOf("user" to user1) as Map<String, Any>)
whenever(session1.uri).thenReturn(URI("ws://localhost/ws?guildId=123"))
whenever(session1.isOpen).thenReturn(true)
whenever(session1.id).thenReturn("s1")

val user2 = AuthSession(userId = "user2", guildId = "456", role = UserRole.SPECTATOR)
val session2 = mock(WebSocketSession::class.java)
whenever(session2.attributes).thenReturn(mapOf("user" to user2))
whenever(session2.attributes).thenReturn(mutableMapOf("user" to user2) as Map<String, Any>)
whenever(session2.uri).thenReturn(URI("ws://localhost/ws?guildId=456"))
whenever(session2.isOpen).thenReturn(true)
whenever(session2.id).thenReturn("s2")
Expand Down