Search in sources :

Example 21 with Gym

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

the class GymRepositoryTest method findNonExGym.

@Test
public void findNonExGym() throws Exception {
    final Gym gym = repo.findByName("Sköldpaddorna", "norrköping");
    assertThat(gym.isExGym(), is(false));
    assertThat(gym.getName(), is("Sköldpaddorna"));
}
Also used : Gym(pokeraidbot.domain.gym.Gym) Test(org.junit.Test)

Example 22 with Gym

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

the class GymRepositoryTest method addTemporaryGymToUppsala.

@Test
public void addTemporaryGymToUppsala() {
    Gym gym;
    try {
        gym = repo.findByName("Mongo", "uppsala");
        fail("Gym should not exist yet.");
    } catch (GymNotFoundException e) {
    // Expected
    }
    final User userMock = mock(User.class);
    when(userMock.getName()).thenReturn("User");
    repo.addTemporary(userMock, new Gym("Mongo", "66666666", "50.0001", "25.00001", "Uppsala", false), "uppsala");
    gym = repo.findByName("Mongo", "uppsala");
    assertThat(gym.getName(), is("Mongo"));
    assertThat(gym.isExGym(), is(false));
}
Also used : User(net.dv8tion.jda.core.entities.User) GymNotFoundException(pokeraidbot.domain.errors.GymNotFoundException) Gym(pokeraidbot.domain.gym.Gym) Test(org.junit.Test)

Example 23 with Gym

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

the class RaidRepositoryTest method moveTimeForGroupWorks.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void moveTimeForGroupWorks() 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());
    }
    List<User> raiders = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        final User raider = mock(User.class);
        when(raider.getName()).thenReturn("User" + i);
        raiders.add(raider);
    }
    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    final LocalDateTime raidGroupTime = endOfRaid.minusMinutes(10);
    for (User raider : raiders) {
        repo.addSignUp(raider, raid, new SignUp(raider.getName(), 2, raidGroupTime.toLocalTime()));
    }
    final LocalDateTime newRaidGroupTime = raidGroupTime.plusMinutes(2);
    RaidEntity entity = raidEntityRepository.findOne(raid.getId());
    repo.moveAllSignUpsForTimeToNewTime(raid.getId(), raidGroupTime, newRaidGroupTime, user);
    entity = raidEntityRepository.findOne(raid.getId());
    raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    entity = raidEntityRepository.findOne(raid.getId());
    assertThat(raid.getSignUps().size(), is(5));
    assertThat(raid.getNumberOfPeopleSignedUp(), is(10));
    assertThat(raid.getSignUpsAt(newRaidGroupTime.toLocalTime()).size(), is(5));
    assertThat(raid.getSignUpsAt(raidGroupTime.toLocalTime()).size(), is(0));
}
Also used : LocalDateTime(java.time.LocalDateTime) SignUp(pokeraidbot.domain.raid.signup.SignUp) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) Gym(pokeraidbot.domain.gym.Gym) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Gym

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

the class RaidRepositoryTest method changeEndOfRaidWorks.

@Test
public void changeEndOfRaidWorks() 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());
    }
    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    Raid changedRaid = repo.changeEndOfRaid(raid.getId(), endOfRaid.plusMinutes(5), guild, config, user, "test");
    assertThat(raid.getEndOfRaid(), not(changedRaid.getEndOfRaid()));
    assertThat(changedRaid.getEndOfRaid(), is(raid.getEndOfRaid().plusMinutes(5)));
    assertThat(raid.getGym(), is(changedRaid.getGym()));
    assertThat(raid.getSignUps(), is(changedRaid.getSignUps()));
    assertThat(raid.getRegion(), is(changedRaid.getRegion()));
    assertThat(raid.getPokemon().getName(), is(changedRaid.getPokemon().getName()));
}
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 25 with Gym

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

the class RaidRepository method executeUnsignCommand.

public String executeUnsignCommand(Config config, User user, Locale localeForUser, String[] args, String help) {
    String people = args[0];
    String userName = user.getName();
    if (args.length < 2 || args.length > 10) {
        throw new WrongNumberOfArgumentsException(user, localeService, 2, args.length, help);
    }
    Integer numberOfPeople = Utils.assertNotTooManyOrNoNumber(user, localeService, people);
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 1; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    String gymName = gymNameBuilder.toString().trim();
    final Gym gym = gymRepository.search(user, gymName, config.getRegion());
    Raid raid = getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    final RaidEntitySignUp signUp = findEntityByRaidId(raid.getId()).getSignUp(user.getName());
    if (signUp == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, user.getName(), gym.getName()));
    }
    raid = removeFromSignUp(raid.getId(), user, 0, 0, 0, numberOfPeople, LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), signUp.getArrivalTime()));
    final String currentSignupText = localeService.getMessageFor(LocaleService.CURRENT_SIGNUPS, localeForUser);
    final Set<SignUp> signUps = raid.getSignUps();
    Set<String> signUpNames = Utils.getNamesOfThoseWithSignUps(signUps, true);
    final String allSignUpNames = StringUtils.join(signUpNames, ", ");
    final String signUpText = raid.getSignUps().size() > 1 ? currentSignupText + "\n" + allSignUpNames : "";
    return localeService.getMessageFor(LocaleService.UNSIGN, localeForUser, userName, gym.getName(), signUpText);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) SignUp(pokeraidbot.domain.raid.signup.SignUp) WrongNumberOfArgumentsException(pokeraidbot.domain.errors.WrongNumberOfArgumentsException) RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym)

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