Search in sources :

Example 11 with DiscordSnowflake

use of com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake in project Backend by FredBoat.

the class GuildDataControllerTest method testPatch.

@WithMockUser(roles = "ADMIN")
@Test
public void testPatch() throws Exception {
    Map<String, Object> patchGuildData = new HashMap<>();
    long now = System.currentTimeMillis();
    patchGuildData.put("helloSent", now);
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    MockHttpServletRequestBuilder request = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildData)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    this.mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.helloSent", both(isA(String.class)).and(is(Long.toString(now))))).andDo(document("guild/data/patch"));
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Example 12 with DiscordSnowflake

use of com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake in project Backend by FredBoat.

the class GuildPlayerControllerTest method testGet.

@WithMockUser(roles = "ADMIN")
@Test
public void testGet() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.voiceChannelId", isA(String.class))).andExpect(jsonPath("$.activeTextChannelId", isA(String.class))).andExpect(jsonPath("$.isPaused", isA(Boolean.class))).andExpect(jsonPath("$.volume", isA(Integer.class))).andExpect(jsonPath("$.repeatMode", isA(String.class))).andExpect(jsonPath("$.isShuffled", isA(Boolean.class))).andDo(document("guild/player/get"));
}
Also used : DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Example 13 with DiscordSnowflake

use of com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake in project Backend by FredBoat.

the class GuildPlayerControllerTest method testPatch.

@WithMockUser(roles = "ADMIN")
@Test
public void testPatch() throws Exception {
    Map<String, Object> patchGuildPlayer = new HashMap<>();
    patchGuildPlayer.put("voiceChannelId", 42L);
    patchGuildPlayer.put("activeTextChannelId", Long.MAX_VALUE);
    patchGuildPlayer.put("isPaused", false);
    patchGuildPlayer.put("volume", 3);
    patchGuildPlayer.put("repeatMode", RepeatMode.ALL);
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    MockHttpServletRequestBuilder request = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildPlayer)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    this.mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.voiceChannelId", both(isA(String.class)).and(is("42")))).andExpect(jsonPath("$.activeTextChannelId", both(isA(String.class)).and(is(Long.toString(Long.MAX_VALUE))))).andExpect(jsonPath("$.isPaused", both(isA(Boolean.class)).and(is(false)))).andExpect(jsonPath("$.volume", both(isA(Integer.class)).and(is(3)))).andExpect(jsonPath("$.repeatMode", both(isA(String.class)).and(is(equalToIgnoringCase(RepeatMode.ALL.name()))))).andExpect(jsonPath("$.isShuffled", both(isA(Boolean.class)).and(is(false)))).andDo(document("guild/player/patch"));
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Example 14 with DiscordSnowflake

use of com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake in project Backend by FredBoat.

the class GuildPlayerControllerTest method testDelete.

@WithMockUser(roles = "ADMIN")
@Test
public void testDelete() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.volume", is(GuildPlayer.DEFAULT_VOLUME)));
    Map<String, Object> patchGuildData = new HashMap<>();
    patchGuildData.put("volume", 69);
    MockHttpServletRequestBuilder patch = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildData)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    this.mockMvc.perform(patch).andExpect(jsonPath("$.volume", is(69)));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.volume", is(69)));
    this.mockMvc.perform(delete(urlTemplate, guildId)).andExpect(status().isOk()).andDo(document("guild/player/delete"));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.volume", is(GuildPlayer.DEFAULT_VOLUME)));
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Example 15 with DiscordSnowflake

use of com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake in project Backend by FredBoat.

the class PrefixControllerTest method testGet.

// get
@WithMockUser(roles = "ADMIN")
@Test
public void testGet() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    DiscordSnowflake botId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId, botId)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.botId", both(isA(String.class)).and(is(botId.getSnowflakeId())))).andExpect(jsonPath("$.prefixes", hasItems(Prefix.DEFAULT_PREFIXES.toArray(new String[0])))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size())));
}
Also used : DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

DiscordSnowflake (com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake)17 BaseTest (com.fredboat.backend.quarterdeck.BaseTest)16 Test (org.junit.jupiter.api.Test)16 WithMockUser (org.springframework.security.test.context.support.WithMockUser)16 HashMap (java.util.HashMap)6 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 GuildPlayer (com.fredboat.backend.quarterdeck.db.entities.main.GuildPlayer)1 Prefix (com.fredboat.backend.quarterdeck.db.entities.main.Prefix)1 GuildPlayerRepo (com.fredboat.backend.quarterdeck.db.repositories.api.GuildPlayerRepo)1 PatchParseUtil (com.fredboat.backend.quarterdeck.parsing.PatchParseUtil)1 RepeatModeParseException (com.fredboat.backend.quarterdeck.parsing.RepeatModeParseException)1 RepeatMode (fredboat.definitions.RepeatMode)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Component (org.springframework.stereotype.Component)1 DatabaseWrapper (space.npstr.sqlsauce.DatabaseWrapper)1