Skip to content

Commit

Permalink
Create Unit Tests for CommandUtil#hasRole and `CommandUtil.EmbedRep…
Browse files Browse the repository at this point in the history
…ly#build`
  • Loading branch information
gmitch215 authored Nov 26, 2024
1 parent e1d9d5f commit 7bb7911
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/test/java/io/codemc/bot/utils/TestCommandUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.codemc.bot.utils;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.codemc.bot.MockCodeMCBot;
import io.codemc.bot.MockJDA;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed;

public class TestCommandUtil {

private static final long AUTHOR_ROLE = MockCodeMCBot.INSTANCE.getConfigHandler().getLong("author_role");
private static final long ADMIN_ROLE = 405917902865170453L;
private static final long MAINTAINER_ROLE = 659568973079379971L;

@Test
@DisplayName("Test CommandUtil#hasRole")
public void testHasRole() {
Member m1 = MockJDA.mockMember("gmitch215");

assertFalse(CommandUtil.hasRole(m1, List.of(AUTHOR_ROLE)));

MockJDA.GUILD.addRoleToMember(m1, MockJDA.AUTHOR);

assertTrue(CommandUtil.hasRole(m1, List.of(AUTHOR_ROLE)));

Member m2 = MockJDA.mockMember("sgdc3");

assertFalse(CommandUtil.hasRole(m2, List.of(ADMIN_ROLE)));
assertFalse(CommandUtil.hasRole(m2, List.of(MAINTAINER_ROLE)));

MockJDA.GUILD.addRoleToMember(m2, MockJDA.ADMINISTRATOR);
MockJDA.GUILD.addRoleToMember(m2, MockJDA.MAINTAINER);

assertTrue(CommandUtil.hasRole(m2, List.of(ADMIN_ROLE, MAINTAINER_ROLE)));
}

@Test
@DisplayName("Test CommandUtil.EmbedReply#build")
public void testEmbedReply() {
CommandUtil.EmbedReply<?> r1 = CommandUtil.EmbedReply.empty();
MessageEmbed m1 = r1.success("Success!").build();

MockJDA.assertEmbed(m1, CommandUtil.embedSuccess("Success!"), true);

CommandUtil.EmbedReply<?> r2 = CommandUtil.EmbedReply.empty();
MessageEmbed m2 = r2.error("Error!").build();

MockJDA.assertEmbed(m2, CommandUtil.embedError("Error!"), true);
}

}

0 comments on commit 7bb7911

Please sign in to comment.