Search in sources :

Example 16 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method whenMusicFileExistsWithSameDiscordIdAndGuildAndUpdatedOnce_thenUserShouldBeFoundWithMusicFile.

@Test
public void whenMusicFileExistsWithSameDiscordIdAndGuildAndUpdatedOnce_thenUserShouldBeFoundWithMusicFile() {
    UserDto userDto = new UserDto();
    userDto.setDiscordId(1L);
    userDto.setGuildId(1L);
    MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), null, 0, null);
    userDto.setMusicDto(musicDto);
    userService.createNewUser(userDto);
    UserDto dbUser = userService.getUserById(userDto.getDiscordId(), userDto.getGuildId());
    assertEquals(dbUser.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser.hasMusicPermission());
    assertTrue(dbUser.hasMemePermission());
    assertTrue(dbUser.hasDigPermission());
    assertFalse(dbUser.isSuperUser());
    MusicDto dbMusicFileDto = userDto.getMusicDto();
    assertNotNull(dbMusicFileDto);
    assertEquals(dbMusicFileDto.getId(), musicDto.getId());
    assertEquals(dbMusicFileDto.getFileName(), musicDto.getFileName());
    dbMusicFileDto.setFileName("file name");
    dbMusicFileDto.setMusicBlob("test data".getBytes());
    userDto.setMusicDto(dbMusicFileDto);
    UserDto dbUser2 = userService.updateUser(userDto);
    assertEquals(dbUser2.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser2.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser2.hasMusicPermission());
    assertTrue(dbUser2.hasMemePermission());
    assertTrue(dbUser2.hasDigPermission());
    assertFalse(dbUser2.isSuperUser());
    dbMusicFileDto = dbUser2.getMusicDto();
    assertNotNull(dbMusicFileDto);
    assertEquals(dbMusicFileDto.getId(), musicDto.getId());
    assertEquals(dbMusicFileDto.getFileName(), musicDto.getFileName());
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method testUpdate_thenNewUserValuesShouldBeReturned.

@Test
@Transactional
public void testUpdate_thenNewUserValuesShouldBeReturned() {
    UserDto userDto1 = new UserDto();
    userDto1.setDiscordId(1L);
    userDto1.setGuildId(1L);
    MusicDto musicDto1 = new MusicDto(userDto1.getDiscordId(), userDto1.getGuildId(), null, 0, null);
    userDto1.setMusicDto(musicDto1);
    userDto1 = userService.createNewUser(userDto1);
    UserDto dbUser1 = userService.getUserById(userDto1.getDiscordId(), userDto1.getGuildId());
    assertEquals(dbUser1.getDiscordId(), userDto1.getDiscordId());
    assertEquals(dbUser1.getGuildId(), userDto1.getGuildId());
    assertTrue(dbUser1.hasMusicPermission());
    assertTrue(dbUser1.hasMemePermission());
    assertTrue(dbUser1.hasDigPermission());
    assertFalse(dbUser1.isSuperUser());
    assertNotNull(dbUser1.getMusicDto());
    UserDto userDto2 = new UserDto();
    userDto2.setDiscordId(1L);
    userDto2.setGuildId(1L);
    MusicDto musicDto2 = new MusicDto(userDto2.getDiscordId(), userDto2.getGuildId(), null, 0, null);
    userDto2.setMusicDto(musicDto2);
    userDto2.setDigPermission(false);
    userDto2 = userService.updateUser(userDto2);
    UserDto dbUser2 = userService.getUserById(userDto2.getDiscordId(), userDto2.getGuildId());
    int guildMemberSize = userService.listGuildUsers(userDto2.getGuildId()).size();
    assertEquals(dbUser2.getDiscordId(), userDto2.getDiscordId());
    assertEquals(dbUser2.getGuildId(), userDto2.getGuildId());
    assertTrue(dbUser2.hasMusicPermission());
    assertTrue(dbUser2.hasMemePermission());
    assertFalse(dbUser2.hasDigPermission());
    assertFalse(dbUser2.isSuperUser());
    assertNotNull(dbUser2.getMusicDto());
    assertEquals(1, guildMemberSize);
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method whenValidDiscordIdAndGuild_thenUserShouldBeFound.

@Test
public void whenValidDiscordIdAndGuild_thenUserShouldBeFound() {
    UserDto userDto = new UserDto();
    userDto.setDiscordId(1L);
    userDto.setGuildId(1L);
    MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), null, 0, null);
    userDto.setMusicDto(musicDto);
    userService.createNewUser(userDto);
    UserDto dbUser = userService.getUserById(userDto.getDiscordId(), userDto.getGuildId());
    assertEquals(dbUser.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser.hasMusicPermission());
    assertTrue(dbUser.hasMemePermission());
    assertTrue(dbUser.hasDigPermission());
    assertFalse(dbUser.isSuperUser());
    assertNotNull(dbUser.getMusicDto());
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method whenMusicFileExistsWithSameDiscordIdAndGuild_thenUserShouldBeFoundWithMusicFile.

@Test
public void whenMusicFileExistsWithSameDiscordIdAndGuild_thenUserShouldBeFoundWithMusicFile() {
    UserDto userDto = new UserDto();
    userDto.setDiscordId(1L);
    userDto.setGuildId(1L);
    MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), "test", 0, null);
    userDto.setMusicDto(musicDto);
    userService.createNewUser(userDto);
    UserDto dbUser = userService.getUserById(userDto.getDiscordId(), userDto.getGuildId());
    assertEquals(dbUser.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser.hasMusicPermission());
    assertTrue(dbUser.hasMemePermission());
    assertTrue(dbUser.hasDigPermission());
    assertFalse(dbUser.isSuperUser());
    MusicDto dbMusicFileDto = userDto.getMusicDto();
    assertNotNull(dbMusicFileDto);
    assertEquals(dbMusicFileDto.getId(), musicDto.getId());
    assertEquals(dbMusicFileDto.getFileName(), musicDto.getFileName());
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class UserPersistenceImpl method createNewUser.

@Override
public UserDto createNewUser(UserDto userDto) {
    createMusicFileEntry(userDto);
    UserDto databaseUser = em.find(UserDto.class, userDto);
    UserDto result = (databaseUser == null) ? persistConfigDto(userDto) : databaseUser;
    return result;
}
Also used : UserDto(toby.jpa.dto.UserDto)

Aggregations

UserDto (toby.jpa.dto.UserDto)27 CommandContext (toby.command.CommandContext)16 ICommand (toby.command.ICommand)16 List (java.util.List)15 TextChannel (net.dv8tion.jda.api.entities.TextChannel)14 Arrays (java.util.Arrays)10 MusicDto (toby.jpa.dto.MusicDto)9 Collectors (java.util.stream.Collectors)8 Message (net.dv8tion.jda.api.entities.Message)8 Member (net.dv8tion.jda.api.entities.Member)6 IUserService (toby.jpa.service.IUserService)6 IOException (java.io.IOException)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 UserDtoHelper.calculateUserDto (toby.helpers.UserDtoHelper.calculateUserDto)4 ConfigDto (toby.jpa.dto.ConfigDto)4 IConfigService (toby.jpa.service.IConfigService)4 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Random (java.util.Random)3