Search in sources :

Example 16 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class RaidRepositoryTest method changePokemonWorks.

@Test
public void changePokemonWorks() throws Exception {
    // We're not allowed to create signups at night, so mocking time
    clockService.setMockTime(LocalTime.of(10, 0));
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);
    when(user.getName()).thenReturn(raidCreatorName);
    try {
        repo.newRaid(user, enteiRaid, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }
    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    Raid changedRaid = repo.changePokemon(raid, pokemonRepository.search("Mewtwo", user), guild, config, user, "test");
    assertThat(raid.getEndOfRaid(), is(changedRaid.getEndOfRaid()));
    assertThat(raid.getGym(), is(changedRaid.getGym()));
    assertThat(raid.getSignUps(), is(changedRaid.getSignUps()));
    assertThat(raid.getRegion(), is(changedRaid.getRegion()));
    assertThat(raid.getPokemon().getName(), is("Entei"));
    assertThat(changedRaid.getPokemon().getName(), is("Mewtwo"));
}
Also used : LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) Gym(pokeraidbot.domain.gym.Gym) Guild(net.dv8tion.jda.core.entities.Guild) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class RaidRepositoryTest method testCreateGetAndDeleteGroup.

@Test
public void testCreateGetAndDeleteGroup() throws Exception {
    // We're not allowed to create signups at night, so mocking time
    clockService.setMockTime(LocalTime.of(10, 0));
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    when(user.getName()).thenReturn(raidCreatorName);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);
    Raid enteiRaid1 = enteiRaid;
    try {
        enteiRaid1 = repo.newRaid(user, enteiRaid1, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }
    enteiRaid = enteiRaid1;
    User user2 = mock(User.class);
    String userName = "testUser2";
    when(user2.getName()).thenReturn(userName);
    LocalTime arrivalTime = nowTime.plusMinutes(30);
    RaidGroup group = new RaidGroup("testserver", "channel", "infoId", "emoteId", "userId", LocalDateTime.of(LocalDate.now(), arrivalTime));
    group = repo.newGroupForRaid(user2, group, enteiRaid, guild, config);
    List<RaidGroup> groupsForServer = repo.getGroupsForServer("testserver");
    assertThat(group != null, is(true));
    assertThat(groupsForServer.size(), is(1));
    assertThat(groupsForServer.iterator().next(), is(group));
    RaidGroup deleted = repo.deleteGroup(enteiRaid.getId(), group.getId());
    assertThat(deleted != null, is(true));
    groupsForServer = repo.getGroupsForServer("testserver");
    assertThat(groupsForServer.size(), is(0));
}
Also used : LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Guild(net.dv8tion.jda.core.entities.Guild) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class RaidRepositoryTest method testSignUp.

@Test
public void testSignUp() throws Exception {
    // We're not allowed to create signups at night, so mocking time
    clockService.setMockTime(LocalTime.of(10, 0));
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    when(user.getName()).thenReturn(raidCreatorName);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);
    try {
        repo.newRaid(user, enteiRaid, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }
    User user2 = mock(User.class);
    String userName = "testUser2";
    when(user2.getName()).thenReturn(userName);
    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
    // Set to same id for equals comparison
    enteiRaid.setId(raid.getId());
    // Set creator to same for equals comparison
    enteiRaid.setCreator(raid.getCreator());
    assertThat(raid, is(enteiRaid));
    int howManyPeople = 3;
    LocalTime arrivalTime = nowTime.plusMinutes(30);
    raid.signUp(user2, howManyPeople, arrivalTime, repo);
    assertThat(raid.getSignUps().size(), is(1));
    assertThat(raid.getNumberOfPeopleSignedUp(), is(howManyPeople));
    final Raid raidFromDb = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
    assertThat(raidFromDb, is(raid));
    assertThat(raidFromDb.getSignUps().size(), is(1));
}
Also used : LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) Gym(pokeraidbot.domain.gym.Gym) Guild(net.dv8tion.jda.core.entities.Guild) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class UtilsTest method timeInRaidspan.

@Test
public void timeInRaidspan() throws Exception {
    User user = mock(User.class);
    when(user.getName()).thenReturn("User");
    LocalDateTime localDateTime = LocalDateTime.now();
    LocalDateTime same = localDateTime;
    LocalDateTime before = localDateTime.minusMinutes(1);
    LocalDateTime after = localDateTime.plusMinutes(1);
    LocalDateTime end = localDateTime.plusMinutes(Utils.RAID_DURATION_IN_MINUTES);
    LocalDateTime sameAsEnd = end;
    LocalDateTime beforeEnd = end.minusMinutes(1);
    LocalDateTime afterEnd = end.plusMinutes(1);
    final LocaleService localeService = mock(LocaleService.class);
    when(localeService.getMessageFor(any(), any(), any())).thenReturn("Mupp");
    Raid raid = new Raid(pokemonRepository.getByName("Tyranitar"), end, new Gym("Test", "id", "10", "10", null), localeService, "Test");
    checkWhetherAssertFails(user, same, localeService, raid, false);
    checkWhetherAssertFails(user, after, localeService, raid, false);
    checkWhetherAssertFails(user, before, localeService, raid, true);
    checkWhetherAssertFails(user, sameAsEnd, localeService, raid, false);
    checkWhetherAssertFails(user, afterEnd, localeService, raid, true);
    checkWhetherAssertFails(user, beforeEnd, localeService, raid, false);
}
Also used : LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocaleService(pokeraidbot.domain.config.LocaleService) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid) Test(org.junit.Test)

Example 20 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class GymRepositoryTest method findNewGymInUppsala.

@Test
public void findNewGymInUppsala() throws Exception {
    final Gym u969 = repo.findByName("U969", "uppsala");
    assertThat(u969.getName(), is("U969"));
    assertThat(u969.isExGym(), is(false));
}
Also used : Gym(pokeraidbot.domain.gym.Gym) Test(org.junit.Test)

Aggregations

Gym (pokeraidbot.domain.gym.Gym)37 User (net.dv8tion.jda.core.entities.User)18 Raid (pokeraidbot.domain.raid.Raid)16 LocalDateTime (java.time.LocalDateTime)15 LocalTime (java.time.LocalTime)13 Test (org.junit.Test)12 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)12 Pokemon (pokeraidbot.domain.pokemon.Pokemon)11 Locale (java.util.Locale)8 Config (pokeraidbot.infrastructure.jpa.config.Config)7 SignUp (pokeraidbot.domain.raid.signup.SignUp)6 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)6 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)5 Guild (net.dv8tion.jda.core.entities.Guild)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)4 PokemonRaidInfo (pokeraidbot.domain.pokemon.PokemonRaidInfo)3 InputStream (java.io.InputStream)2 LocalDate (java.time.LocalDate)2 Set (java.util.Set)2