Search in sources :

Example 1 with DiscordSnowflake

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

the class GuildConfigControllerTest method testDelete.

@WithMockUser(roles = "ADMIN")
@Test
public void testDelete() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.language", is(equalToIgnoringCase(GuildConfig.DEFAULT_LANGAUGE.getCode()))));
    Map<String, Object> patchGuildConfig = new HashMap<>();
    patchGuildConfig.put("language", Language.DE_DE.getCode());
    MockHttpServletRequestBuilder patch = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildConfig)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    this.mockMvc.perform(patch).andExpect(jsonPath("$.language", is(equalToIgnoringCase(Language.DE_DE.getCode()))));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.language", is(equalToIgnoringCase(Language.DE_DE.getCode()))));
    this.mockMvc.perform(delete(urlTemplate, guildId)).andExpect(status().isOk()).andDo(document("guild/config/delete"));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.language", is(equalToIgnoringCase(GuildConfig.DEFAULT_LANGAUGE.getCode()))));
}
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 2 with DiscordSnowflake

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

the class GuildDataControllerTest 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("$.helloSent", isA(String.class))).andDo(document("guild/data/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 3 with DiscordSnowflake

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

the class GuildDataControllerTest method testDelete.

@WithMockUser(roles = "ADMIN")
@Test
public void testDelete() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.helloSent", is(Long.toString(GuildData.DEFAULT_HELLO_SENT_TIMESTAMP))));
    Map<String, Object> patchGuildData = new HashMap<>();
    long now = System.currentTimeMillis();
    patchGuildData.put("helloSent", now);
    MockHttpServletRequestBuilder patch = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildData)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    this.mockMvc.perform(patch).andExpect(jsonPath("$.helloSent", is(Long.toString(now))));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.helloSent", is(Long.toString(now))));
    this.mockMvc.perform(delete(urlTemplate, guildId)).andExpect(status().isOk()).andDo(document("guild/data/delete"));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.helloSent", is(Long.toString(GuildData.DEFAULT_HELLO_SENT_TIMESTAMP))));
}
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 4 with DiscordSnowflake

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

the class PrefixControllerTest method testDelete.

// delete
@WithMockUser(roles = "ADMIN")
@Test
public void testDelete() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    DiscordSnowflake botId = generateUniqueSnowflakeId();
    this.mockMvc.perform(delete(urlTemplate, guildId, botId).contentType(MediaType.APPLICATION_JSON_UTF8)).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)

Example 5 with DiscordSnowflake

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

the class PrefixControllerTest method testDeleteAll.

// test remove all prefixes
@WithMockUser(roles = "ADMIN")
@Test
public void testDeleteAll() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    DiscordSnowflake botId = generateUniqueSnowflakeId();
    String[] current = this.gson.fromJson(this.mockMvc.perform(get(urlTemplate, guildId, botId)).andReturn().getResponse().getContentAsString(), com.fredboat.backend.quarterdeck.rest.v1.transfer.Prefix.class).getPrefixes();
    this.mockMvc.perform(delete(urlTemplate, guildId, botId).content(this.gson.toJson(current)).contentType(MediaType.APPLICATION_JSON_UTF8)).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) Prefix(com.fredboat.backend.quarterdeck.db.entities.main.Prefix) 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