2024-04-13 20:53:31 +01:00
|
|
|
package xyz.mcutils.backend.tests;
|
2024-04-08 07:20:25 +01:00
|
|
|
|
2024-04-10 14:44:05 +01:00
|
|
|
import cc.fascinated.config.TestRedisConfig;
|
2024-04-08 07:20:25 +01:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.test.web.servlet.MockMvc;
|
2024-04-13 21:02:54 +01:00
|
|
|
import xyz.mcutils.backend.model.skin.ISkinPart;
|
2024-04-08 07:20:25 +01:00
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
|
|
|
|
@AutoConfigureMockMvc
|
2024-04-10 07:43:13 +01:00
|
|
|
@SpringBootTest(classes = TestRedisConfig.class)
|
2024-04-08 07:20:25 +01:00
|
|
|
class PlayerControllerTests {
|
|
|
|
|
2024-04-10 14:44:05 +01:00
|
|
|
private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";
|
|
|
|
private final String testPlayer = "ImFascinated";
|
|
|
|
private final String testInvalidPlayer = "invalidplayeromgyeswow";
|
|
|
|
|
2024-04-08 07:20:25 +01:00
|
|
|
@Autowired
|
|
|
|
private MockMvc mockMvc;
|
|
|
|
|
|
|
|
@Test
|
2024-04-09 03:40:08 +01:00
|
|
|
public void ensurePlayerLookupUuidSuccess() throws Exception {
|
2024-04-10 14:44:05 +01:00
|
|
|
mockMvc.perform(get("/player/" + testPlayerUuid)
|
2024-04-08 07:20:25 +01:00
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
|
|
.andExpect(status().isOk())
|
2024-04-13 17:18:43 +01:00
|
|
|
.andExpect(jsonPath("$.player.username").value(testPlayer));
|
2024-04-08 07:20:25 +01:00
|
|
|
}
|
|
|
|
|
2024-04-09 03:40:08 +01:00
|
|
|
@Test
|
|
|
|
public void ensurePlayerLookupUsernameSuccess() throws Exception {
|
2024-04-10 14:44:05 +01:00
|
|
|
mockMvc.perform(get("/player/" + testPlayer)
|
2024-04-09 03:40:08 +01:00
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
|
|
.andExpect(status().isOk())
|
2024-04-13 17:18:43 +01:00
|
|
|
.andExpect(jsonPath("$.player.username").value(testPlayer));
|
2024-04-09 03:40:08 +01:00
|
|
|
}
|
|
|
|
|
2024-04-11 00:24:03 +01:00
|
|
|
@Test
|
|
|
|
public void ensurePlayerUsernameToUuidLookupSuccess() throws Exception {
|
|
|
|
mockMvc.perform(get("/player/uuid/" + testPlayer)
|
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
|
|
.andExpect(status().isOk())
|
2024-04-13 17:21:33 +01:00
|
|
|
.andExpect(jsonPath("$.username").value(testPlayer))
|
|
|
|
.andExpect(jsonPath("$.uniqueId").value(testPlayerUuid));
|
2024-04-11 00:24:03 +01:00
|
|
|
}
|
|
|
|
|
2024-04-11 00:26:38 +01:00
|
|
|
@Test
|
|
|
|
public void ensurePlayerUsernameToUuidLookupFailure() throws Exception {
|
2024-04-11 00:28:54 +01:00
|
|
|
mockMvc.perform(get("/player/uuid/" + testInvalidPlayer)
|
2024-04-11 00:26:38 +01:00
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
|
|
.andExpect(status().isNotFound());
|
|
|
|
}
|
|
|
|
|
2024-04-08 07:20:25 +01:00
|
|
|
@Test
|
2024-04-08 07:22:03 +01:00
|
|
|
public void ensurePlayerLookupFailure() throws Exception {
|
2024-04-10 14:44:05 +01:00
|
|
|
mockMvc.perform(get("/player/" + testInvalidPlayer)
|
2024-04-08 07:22:03 +01:00
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
|
|
.andExpect(status().isNotFound());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2024-04-09 03:40:08 +01:00
|
|
|
public void ensurePlayerSkinPartsLookupSuccess() throws Exception {
|
2024-04-12 18:48:13 +01:00
|
|
|
for (Enum<?>[] type : ISkinPart.TYPES) {
|
|
|
|
for (Enum<?> part : type) {
|
|
|
|
mockMvc.perform(get("/player/" + part.name().toLowerCase() + "/" + testPlayer)
|
|
|
|
.accept(MediaType.APPLICATION_JSON)
|
|
|
|
.contentType(MediaType.APPLICATION_JSON))
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
}
|
|
|
|
|
2024-04-08 07:20:25 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-08 07:22:03 +01:00
|
|
|
|
|
|
|
@Test
|
2024-04-09 03:40:08 +01:00
|
|
|
public void ensurePlayerSkinPartsLookupFailure() throws Exception {
|
2024-04-10 14:44:05 +01:00
|
|
|
mockMvc.perform(get("/player/invalidpart/" + testPlayer))
|
2024-04-10 08:13:50 +01:00
|
|
|
.andExpect(status().isBadRequest());
|
2024-04-08 07:22:03 +01:00
|
|
|
}
|
2024-04-08 07:20:25 +01:00
|
|
|
}
|