Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored and Daniel Villavicencio committed Aug 6, 2024
1 parent 8c81a47 commit c6b6144
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/deahtstroke/rivenbot/factory/Factory.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.deahtstroke.rivenbot.factory;
package com.deahtstroke.rivenbot.handler;

import com.deahtstroke.rivenbot.dto.discord.Interaction;
import com.deahtstroke.rivenbot.dto.discord.InteractionResponse;
import com.deahtstroke.rivenbot.enums.InteractionType;
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SlashCommandHandler> slashCommandHandlers = List.of(aboutHandler, raidStatsCommandHandler,
weeklyRaidHandler, weeklyDungeonHandler);

@InjectMocks
InteractionFactory sut;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -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<Option> options = List.of(
new Option("username", 1, "Deaht#3180", false, Collections.emptyList()));
Interaction interaction = Interaction.builder()
.data(InteractionData.builder()
.options(options)
.build())
.token("someToken")
.build();

when(asyncRaidsProcessor.processRaidsAsync("Deaht", "3180", "someToken"))
.thenReturn(Mono.empty());

// when: serve() is invoked
StepVerifier.create(sut.serve(interaction))
.assertNext(response -> {
assertThat(response.getType())
.isEqualTo(InteractionResponseType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE.getType());
assertThat(response.getData()).isNotNull();
}).verifyComplete();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.deahtstroke.rivenbot.handler;
package com.deahtstroke.rivenbot.handler.weeklydungeon;

import static org.mockito.Mockito.when;

import com.deahtstroke.rivenbot.dto.WeeklyActivity;
import com.deahtstroke.rivenbot.dto.discord.InteractionResponse;
import com.deahtstroke.rivenbot.enums.ActivityMode;
import com.deahtstroke.rivenbot.enums.InteractionResponseType;
import com.deahtstroke.rivenbot.handler.weeklydungeon.WeeklyDungeonHandler;
import com.deahtstroke.rivenbot.service.WeeklyActivitiesService;
import com.deahtstroke.rivenbot.util.MessageUtils;
import java.time.ZonedDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.deahtstroke.rivenbot.handler;
package com.deahtstroke.rivenbot.handler.weeklyraid;

import static org.mockito.Mockito.when;

import com.deahtstroke.rivenbot.dto.WeeklyActivity;
import com.deahtstroke.rivenbot.dto.discord.InteractionResponse;
import com.deahtstroke.rivenbot.enums.ActivityMode;
import com.deahtstroke.rivenbot.enums.InteractionResponseType;
import com.deahtstroke.rivenbot.handler.weeklyraid.WeeklyRaidHandler;
import com.deahtstroke.rivenbot.service.WeeklyActivitiesService;
import com.deahtstroke.rivenbot.util.MessageUtils;
import java.time.ZonedDateTime;
Expand Down

0 comments on commit c6b6144

Please sign in to comment.