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)));
}
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())));
}
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);
}
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"));
}
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"));
}
Aggregations