Search in sources :

Example 21 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UserServiceTest method changePasswordInvalidPassword.

@Test
public void changePasswordInvalidPassword() {
    expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.PASSWORD_CHANGE_FAILED_WRONG_PASSWORD));
    User user = createUser(TEST_USERID, TEST_USERNAME, "invalid password", TEST_CURRENT_EMAIL);
    instance.changePassword(TEST_CURRENT_PASSWORD, TEST_NEW_PASSWORD, user);
}
Also used : User(com.faforever.api.data.domain.User) Test(org.junit.Test)

Example 22 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UserServiceTest method setUp.

@Before
public void setUp() {
    properties = new FafApiProperties();
    properties.getJwt().setSecret(TEST_SECRET);
    properties.getLinkToSteam().setSteamRedirectUrlFormat("%s");
    instance = new UserService(emailService, playerRepository, userRepository, nameRecordRepository, properties, anopeUserRepository, fafTokenService, steamService, Optional.of(mauticService), globalRatingRepository, ladder1v1RatingRepository);
    when(fafTokenService.createToken(any(), any(), any())).thenReturn(TOKEN_VALUE);
    when(userRepository.save(any(User.class))).then(invocation -> ((User) invocation.getArgument(0)).setId(TEST_USERID));
    when(mauticService.createOrUpdateContact(any(), any(), any(), any(), any())).thenReturn(CompletableFuture.completedFuture(null));
}
Also used : User(com.faforever.api.data.domain.User) FafApiProperties(com.faforever.api.config.FafApiProperties) Before(org.junit.Before)

Example 23 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UserServiceTest method changeLoginWithUsernameInUse.

@Test
public void changeLoginWithUsernameInUse() {
    expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.USERNAME_TAKEN));
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    when(userRepository.existsByLoginIgnoreCase(TEST_USERNAME_CHANGED)).thenReturn(true);
    instance.changeLogin(TEST_USERNAME_CHANGED, user, "127.0.0.1");
}
Also used : User(com.faforever.api.data.domain.User) Test(org.junit.Test)

Example 24 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UserServiceTest method buildSteamLinkUrlAlreadLinked.

@Test
public void buildSteamLinkUrlAlreadLinked() {
    expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.STEAM_ID_UNCHANGEABLE));
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    user.setSteamId(STEAM_ID);
    instance.buildSteamLinkUrl(user, "http://example.com/callback");
}
Also used : User(com.faforever.api.data.domain.User) Test(org.junit.Test)

Example 25 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UserServiceTest method changeLogin.

@Test
public void changeLogin() {
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    when(nameRecordRepository.getDaysSinceLastNewRecord(anyInt(), anyInt())).thenReturn(Optional.empty());
    instance.changeLogin(TEST_USERNAME_CHANGED, user, "127.0.0.1");
    ArgumentCaptor<User> captorUser = ArgumentCaptor.forClass(User.class);
    verify(userRepository).save(captorUser.capture());
    assertEquals(captorUser.getValue().getLogin(), TEST_USERNAME_CHANGED);
    ArgumentCaptor<NameRecord> captorNameRecord = ArgumentCaptor.forClass(NameRecord.class);
    verify(nameRecordRepository).save(captorNameRecord.capture());
    assertEquals(captorNameRecord.getValue().getName(), TEST_USERNAME);
    verify(mauticService).createOrUpdateContact(eq(TEST_NEW_EMAIL), eq(String.valueOf(TEST_USERID)), eq(TEST_USERNAME_CHANGED), eq("127.0.0.1"), any(OffsetDateTime.class));
}
Also used : User(com.faforever.api.data.domain.User) NameRecord(com.faforever.api.data.domain.NameRecord) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.Test)

Aggregations

User (com.faforever.api.data.domain.User)28 Test (org.junit.Test)22 OffsetDateTime (java.time.OffsetDateTime)4 AbstractIntegrationTest (com.faforever.api.AbstractIntegrationTest)3 ApiException (com.faforever.api.error.ApiException)3 Error (com.faforever.api.error.Error)3 SteamLinkResult (com.faforever.api.user.UserService.SteamLinkResult)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 SneakyThrows (lombok.SneakyThrows)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)3 GlobalRating (com.faforever.api.data.domain.GlobalRating)2 Ladder1v1Rating (com.faforever.api.data.domain.Ladder1v1Rating)2 ArrayList (java.util.ArrayList)2 HttpHeaders (org.springframework.http.HttpHeaders)2 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)2 FafApiProperties (com.faforever.api.config.FafApiProperties)1 NameRecord (com.faforever.api.data.domain.NameRecord)1 Before (org.junit.Before)1