diff --git a/src/main/java/com/deahtstroke/rivenbot/dispatcher/DiscordInteractionDispatcher.java b/src/main/java/com/deahtstroke/rivenbot/dispatcher/DiscordInteractionDispatcher.java index 61f7b7e..0e22a00 100644 --- a/src/main/java/com/deahtstroke/rivenbot/dispatcher/DiscordInteractionDispatcher.java +++ b/src/main/java/com/deahtstroke/rivenbot/dispatcher/DiscordInteractionDispatcher.java @@ -3,7 +3,7 @@ import com.deahtstroke.rivenbot.dto.discord.Interaction; import com.deahtstroke.rivenbot.dto.discord.InteractionResponse; import com.deahtstroke.rivenbot.exception.BaseException; -import com.deahtstroke.rivenbot.factory.InteractionFactory; +import com.deahtstroke.rivenbot.handler.InteractionFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ProblemDetail; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/deahtstroke/rivenbot/enums/MessageComponentId.java b/src/main/java/com/deahtstroke/rivenbot/enums/MessageComponentId.java index cb94d55..164516d 100644 --- a/src/main/java/com/deahtstroke/rivenbot/enums/MessageComponentId.java +++ b/src/main/java/com/deahtstroke/rivenbot/enums/MessageComponentId.java @@ -7,8 +7,7 @@ public enum MessageComponentId { RAID_STATS_COMPREHENSION("raid_stats_comprehension"), - MESSAGE_COMPONENT_TEST("message_component_test"), - RIVEN_INVITE("riven_invite"); + MESSAGE_COMPONENT_TEST("message_component_test"); @Getter private final String id; diff --git a/src/main/java/com/deahtstroke/rivenbot/factory/Factory.java b/src/main/java/com/deahtstroke/rivenbot/factory/Factory.java deleted file mode 100644 index c1f14d4..0000000 --- a/src/main/java/com/deahtstroke/rivenbot/factory/Factory.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.deahtstroke.rivenbot.factory; - -import com.deahtstroke.rivenbot.dto.discord.Interaction; -import com.deahtstroke.rivenbot.dto.discord.InteractionResponse; -import reactor.core.publisher.Mono; - -public interface Factory { - - Mono serve(T data, Interaction interaction); -} diff --git a/src/main/java/com/deahtstroke/rivenbot/factory/InteractionFactory.java b/src/main/java/com/deahtstroke/rivenbot/handler/InteractionFactory.java similarity index 92% rename from src/main/java/com/deahtstroke/rivenbot/factory/InteractionFactory.java rename to src/main/java/com/deahtstroke/rivenbot/handler/InteractionFactory.java index 4b6e729..97765c3 100644 --- a/src/main/java/com/deahtstroke/rivenbot/factory/InteractionFactory.java +++ b/src/main/java/com/deahtstroke/rivenbot/handler/InteractionFactory.java @@ -1,4 +1,4 @@ -package com.deahtstroke.rivenbot.factory; +package com.deahtstroke.rivenbot.handler; import com.deahtstroke.rivenbot.dto.discord.Interaction; import com.deahtstroke.rivenbot.dto.discord.InteractionResponse; @@ -6,10 +6,6 @@ import com.deahtstroke.rivenbot.enums.MessageComponentId; import com.deahtstroke.rivenbot.enums.SlashCommand; import com.deahtstroke.rivenbot.exception.NoSuchHandlerException; -import com.deahtstroke.rivenbot.handler.AutocompleteHandler; -import com.deahtstroke.rivenbot.handler.Handler; -import com.deahtstroke.rivenbot.handler.MessageComponentHandler; -import com.deahtstroke.rivenbot.handler.SlashCommandHandler; import jakarta.annotation.PostConstruct; import java.util.EnumMap; import java.util.List; diff --git a/src/test/java/com/deahtstroke/rivenbot/handler/InteractionFactoryTest.java b/src/test/java/com/deahtstroke/rivenbot/handler/InteractionFactoryTest.java index 2ecc262..8aca42d 100644 --- a/src/test/java/com/deahtstroke/rivenbot/handler/InteractionFactoryTest.java +++ b/src/test/java/com/deahtstroke/rivenbot/handler/InteractionFactoryTest.java @@ -1,9 +1,38 @@ package com.deahtstroke.rivenbot.handler; +import com.deahtstroke.rivenbot.handler.about.AboutHandler; +import com.deahtstroke.rivenbot.handler.raidstats.RaidStatsCommandHandler; +import com.deahtstroke.rivenbot.handler.weeklydungeon.WeeklyDungeonHandler; +import com.deahtstroke.rivenbot.handler.weeklyraid.WeeklyRaidHandler; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class InteractionFactoryTest { - // TODO: rewrite test suite from scratch + + @Mock + AboutHandler aboutHandler; + + @Mock + RaidStatsCommandHandler raidStatsCommandHandler; + + @Mock + WeeklyDungeonHandler weeklyDungeonHandler; + + @Mock + WeeklyRaidHandler weeklyRaidHandler; + + @Mock + + + List slashCommandHandlers = List.of(aboutHandler, raidStatsCommandHandler, + weeklyRaidHandler, weeklyDungeonHandler); + + @InjectMocks + InteractionFactory sut; + } diff --git a/src/test/java/com/deahtstroke/rivenbot/handler/InteractionHandlerTest.java b/src/test/java/com/deahtstroke/rivenbot/handler/InteractionHandlerTest.java index 70ff7c4..a91960e 100644 --- a/src/test/java/com/deahtstroke/rivenbot/handler/InteractionHandlerTest.java +++ b/src/test/java/com/deahtstroke/rivenbot/handler/InteractionHandlerTest.java @@ -11,7 +11,6 @@ import com.deahtstroke.rivenbot.dto.discord.InteractionResponseData; import com.deahtstroke.rivenbot.dto.discord.Member; import com.deahtstroke.rivenbot.enums.InteractionResponseType; -import com.deahtstroke.rivenbot.factory.InteractionFactory; import com.deahtstroke.rivenbot.handler.weeklydungeon.WeeklyDungeonHandler; import com.deahtstroke.rivenbot.util.MessageUtils; import java.time.LocalDate; diff --git a/src/test/java/com/deahtstroke/rivenbot/handler/AboutHandlerTest.java b/src/test/java/com/deahtstroke/rivenbot/handler/about/AboutHandlerTest.java similarity index 99% rename from src/test/java/com/deahtstroke/rivenbot/handler/AboutHandlerTest.java rename to src/test/java/com/deahtstroke/rivenbot/handler/about/AboutHandlerTest.java index f93b375..f4a90a5 100644 --- a/src/test/java/com/deahtstroke/rivenbot/handler/AboutHandlerTest.java +++ b/src/test/java/com/deahtstroke/rivenbot/handler/about/AboutHandlerTest.java @@ -1,4 +1,4 @@ -package com.deahtstroke.rivenbot.handler; +package com.deahtstroke.rivenbot.handler.about; import static com.deahtstroke.rivenbot.util.MessageUtils.BOT_INVITE_LINK; import static com.deahtstroke.rivenbot.util.MessageUtils.DISCORD_SERVER; diff --git a/src/test/java/com/deahtstroke/rivenbot/handler/RaidStatHandlerTest.java b/src/test/java/com/deahtstroke/rivenbot/handler/raidstats/RaidStatsAutocompleteHandlerTest.java similarity index 60% rename from src/test/java/com/deahtstroke/rivenbot/handler/RaidStatHandlerTest.java rename to src/test/java/com/deahtstroke/rivenbot/handler/raidstats/RaidStatsAutocompleteHandlerTest.java index f6f4456..702bded 100644 --- a/src/test/java/com/deahtstroke/rivenbot/handler/RaidStatHandlerTest.java +++ b/src/test/java/com/deahtstroke/rivenbot/handler/raidstats/RaidStatsAutocompleteHandlerTest.java @@ -1,9 +1,9 @@ -package com.deahtstroke.rivenbot.handler; +package com.deahtstroke.rivenbot.handler.raidstats; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class RaidStatHandlerTest { +class RaidStatsAutocompleteHandlerTest { } diff --git a/src/test/java/com/deahtstroke/rivenbot/handler/raidstats/RaidStatsCommandHandlerTest.java b/src/test/java/com/deahtstroke/rivenbot/handler/raidstats/RaidStatsCommandHandlerTest.java new file mode 100644 index 0000000..e565267 --- /dev/null +++ b/src/test/java/com/deahtstroke/rivenbot/handler/raidstats/RaidStatsCommandHandlerTest.java @@ -0,0 +1,55 @@ +package com.deahtstroke.rivenbot.handler.raidstats; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +import com.deahtstroke.rivenbot.dto.discord.Interaction; +import com.deahtstroke.rivenbot.dto.discord.InteractionData; +import com.deahtstroke.rivenbot.dto.discord.Option; +import com.deahtstroke.rivenbot.enums.InteractionResponseType; +import com.deahtstroke.rivenbot.processor.AsyncRaidsProcessor; +import java.util.Collections; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +@ExtendWith(MockitoExtension.class) +class RaidStatsCommandHandlerTest { + + @Mock + AsyncRaidsProcessor asyncRaidsProcessor; + + @InjectMocks + RaidStatsCommandHandler sut; + + @Test + @DisplayName("Serve should work successfully") + void shouldServeRaidStatsSuccessfully() { + // given: an interaction with a Bungie user + List