Search in sources :

Example 6 with DiscordSnowflake

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

the class PrefixControllerTest method testAddSingle.

// test add single prefix
@WithMockUser(roles = "ADMIN")
@Test
public void testAddSingle() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    DiscordSnowflake botId = generateUniqueSnowflakeId();
    String[] addPrefix = { "this_is_a_prefix_in_an_array" };
    this.mockMvc.perform(post(urlTemplate, guildId, botId).content(this.gson.toJson(addPrefix)).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", hasItems(addPrefix))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size() + 1)));
}
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 7 with DiscordSnowflake

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

the class PrefixControllerTest method testDeleteMultiple.

// test remove multiple prefixes
@WithMockUser(roles = "ADMIN")
@Test
public void testDeleteMultiple() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    DiscordSnowflake botId = generateUniqueSnowflakeId();
    String[] addPrefixes = { "1", "2", "3", "4" };
    this.mockMvc.perform(post(urlTemplate, guildId, botId).content(this.gson.toJson(addPrefixes)).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", hasItems(addPrefixes))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size() + addPrefixes.length)));
    this.mockMvc.perform(delete(urlTemplate, guildId, botId).content(this.gson.toJson(addPrefixes)).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 8 with DiscordSnowflake

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

the class SqlSauceGuildPlayerRepo method patch.

@Override
public GuildPlayer patch(Long id, Map<String, Object> partialUpdate) {
    Function<GuildPlayer, GuildPlayer> update = guildPlayer -> guildPlayer;
    // voice channel id
    if (partialUpdate.containsKey("voiceChannelId")) {
        DiscordSnowflake voiceChannelId = PatchParseUtil.parseDiscordSnowflake("voiceChannelId", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setVoiceChannelId(voiceChannelId.longValue()));
    }
    // active text channel id
    if (partialUpdate.containsKey("activeTextChannelId")) {
        DiscordSnowflake activeTextChannelId = PatchParseUtil.parseDiscordSnowflake("activeTextChannelId", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setActiveTextChannelId(activeTextChannelId.longValue()));
    }
    // is paused
    if (partialUpdate.containsKey("isPaused")) {
        boolean isPaused = PatchParseUtil.parseBoolean("isPaused", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setPaused(isPaused));
    }
    // volume
    if (partialUpdate.containsKey("volume")) {
        int volume = PatchParseUtil.parseInt("volume", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setVolume(volume));
    }
    // repeat mode
    if (partialUpdate.containsKey("repeatMode")) {
        String repeatModeRaw = PatchParseUtil.cast("repeatMode", partialUpdate, String.class);
        Optional<RepeatMode> parse = RepeatMode.parse(repeatModeRaw);
        if (parse.isPresent()) {
            update = update.andThen(guildPlayer -> guildPlayer.setRepeatMode(parse.get()));
        } else {
            throw new RepeatModeParseException(repeatModeRaw);
        }
    }
    // is shuffled
    if (partialUpdate.containsKey("isShuffled")) {
        boolean isShuffled = PatchParseUtil.parseBoolean("isShuffled", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setShuffled(isShuffled));
    }
    return this.dbWrapper.findApplyAndMerge(GuildPlayer.key(id), update);
}
Also used : RepeatMode(fredboat.definitions.RepeatMode) Component(org.springframework.stereotype.Component) PatchParseUtil(com.fredboat.backend.quarterdeck.parsing.PatchParseUtil) RepeatModeParseException(com.fredboat.backend.quarterdeck.parsing.RepeatModeParseException) Map(java.util.Map) GuildPlayer(com.fredboat.backend.quarterdeck.db.entities.main.GuildPlayer) Optional(java.util.Optional) GuildPlayerRepo(com.fredboat.backend.quarterdeck.db.repositories.api.GuildPlayerRepo) DatabaseWrapper(space.npstr.sqlsauce.DatabaseWrapper) Function(java.util.function.Function) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) RepeatMode(fredboat.definitions.RepeatMode) RepeatModeParseException(com.fredboat.backend.quarterdeck.parsing.RepeatModeParseException) GuildPlayer(com.fredboat.backend.quarterdeck.db.entities.main.GuildPlayer) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake)

Example 9 with DiscordSnowflake

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

the class GuildConfigControllerTest 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("$.trackAnnounce", isA(Boolean.class))).andExpect(jsonPath("$.autoResume", isA(Boolean.class))).andExpect(jsonPath("$.language", isA(String.class))).andDo(document("guild/config/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 10 with DiscordSnowflake

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

the class GuildConfigControllerTest method testPatch.

@WithMockUser(roles = "ADMIN")
@Test
public void testPatch() throws Exception {
    Map<String, Object> patchGuildConfig = new HashMap<>();
    patchGuildConfig.put("trackAnnounce", false);
    patchGuildConfig.put("autoResume", true);
    patchGuildConfig.put("language", Language.DE_DE.getCode());
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    MockHttpServletRequestBuilder request = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildConfig)).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("$.trackAnnounce", both(isA(Boolean.class)).and(is(false)))).andExpect(jsonPath("$.autoResume", both(isA(Boolean.class)).and(is(true)))).andExpect(jsonPath("$.language", both(isA(String.class)).and(is(equalToIgnoringCase(Language.DE_DE.getCode()))))).andDo(document("guild/config/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)

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