minecraft-helper/src/test/java/cc/fascinated/PlayerControllerTests.java

64 lines
2.4 KiB
Java
Raw Normal View History

2024-04-08 06:20:25 +00:00
package cc.fascinated;
import cc.fascinated.model.player.Skin;
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;
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
@SpringBootTest
class PlayerControllerTests {
@Autowired
private MockMvc mockMvc;
@Test
2024-04-09 02:40:08 +00:00
public void ensurePlayerLookupUuidSuccess() throws Exception {
2024-04-08 06:20:25 +00:00
mockMvc.perform(get("/player/eeab5f8a-18dd-4d58-af78-2b3c4543da48")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.username").value("ImFascinated"));
}
2024-04-09 02:40:08 +00:00
@Test
public void ensurePlayerLookupUsernameSuccess() throws Exception {
mockMvc.perform(get("/player/ImFascinated")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.username").value("ImFascinated"));
}
2024-04-08 06:20:25 +00:00
@Test
2024-04-08 06:22:03 +00:00
public void ensurePlayerLookupFailure() throws Exception {
mockMvc.perform(get("/player/invalidnamehahahahahayesslmaooo")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}
@Test
2024-04-09 02:40:08 +00:00
public void ensurePlayerSkinPartsLookupSuccess() throws Exception {
2024-04-08 06:20:25 +00:00
for (Skin.Parts part : Skin.Parts.values()) {
mockMvc.perform(get("/player/" + part.getName() + "/eeab5f8a-18dd-4d58-af78-2b3c4543da48")
.accept(MediaType.IMAGE_PNG)
.contentType(MediaType.IMAGE_PNG))
.andExpect(status().isOk());
}
}
2024-04-08 06:22:03 +00:00
@Test
2024-04-09 02:40:08 +00:00
public void ensurePlayerSkinPartsLookupFailure() throws Exception {
mockMvc.perform(get("/player/invalidpart/eeab5f8a-18dd-4d58-af78-2b3c4543da48"))
2024-04-08 06:22:03 +00:00
.andExpect(status().isNotFound());
}
2024-04-08 06:20:25 +00:00
}