use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class ClanServiceTest method generatePlayerInvitationTokenFromNonLeader.
@Test
public void generatePlayerInvitationTokenFromNonLeader() throws IOException {
Player requester = new Player();
requester.setId(1);
Player newMember = new Player();
newMember.setId(2);
Player leader = new Player();
leader.setId(3);
Clan clan = ClanFactory.builder().leader(leader).build();
when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
try {
instance.generatePlayerInvitationToken(requester, newMember.getId(), clan.getId());
fail();
} catch (ApiException e) {
assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_NOT_LEADER));
}
verify(jwtService, Mockito.never()).sign(any());
}
use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class ClanServiceTest method generatePlayerInvitationToken.
@Test
public void generatePlayerInvitationToken() throws IOException {
Player requester = new Player();
requester.setId(1);
Player newMember = new Player();
newMember.setId(2);
Clan clan = ClanFactory.builder().leader(requester).build();
FafApiProperties props = new FafApiProperties();
when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
when(playerRepository.findById(newMember.getId())).thenReturn(Optional.of(newMember));
when(fafApiProperties.getClan()).thenReturn(props.getClan());
instance.generatePlayerInvitationToken(requester, newMember.getId(), clan.getId());
ArgumentCaptor<InvitationResult> captor = ArgumentCaptor.forClass(InvitationResult.class);
verify(jwtService, Mockito.times(1)).sign(captor.capture());
assertThat("expire", captor.getValue().getExpire(), greaterThan(System.currentTimeMillis()));
assertEquals(newMember.getId(), captor.getValue().getNewMember().getId());
assertEquals(newMember.getLogin(), captor.getValue().getNewMember().getLogin());
assertEquals(clan.getId(), captor.getValue().getClan().getId());
assertEquals(clan.getTag(), captor.getValue().getClan().getTag());
assertEquals(clan.getName(), captor.getValue().getClan().getName());
}
use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class ClanServiceTest method createClanSuccessful.
@Test
public void createClanSuccessful() {
String clanName = "My cool Clan";
String tag = "123";
String description = "A cool clan for testing";
Player creator = new Player();
creator.setId(1);
when(clanRepository.findOneByName(clanName)).thenReturn(Optional.empty());
when(clanRepository.findOneByTag(tag)).thenReturn(Optional.empty());
instance.create(clanName, tag, description, creator);
ArgumentCaptor<Clan> clanCaptor = ArgumentCaptor.forClass(Clan.class);
verify(clanRepository, Mockito.times(1)).save(clanCaptor.capture());
assertEquals(clanName, clanCaptor.getValue().getName());
assertEquals(tag, clanCaptor.getValue().getTag());
assertEquals(description, clanCaptor.getValue().getDescription());
assertEquals(creator, clanCaptor.getValue().getLeader());
assertEquals(creator, clanCaptor.getValue().getFounder());
assertEquals(1, clanCaptor.getValue().getMemberships().size());
assertEquals(creator, clanCaptor.getValue().getMemberships().get(0).getPlayer());
}
use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class ClanServiceTest method generatePlayerInvitationTokenInvalidPlayer.
@Test
public void generatePlayerInvitationTokenInvalidPlayer() throws IOException {
Player requester = new Player();
requester.setId(1);
Clan clan = ClanFactory.builder().leader(requester).build();
when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
try {
instance.generatePlayerInvitationToken(requester, 42, clan.getId());
fail();
} catch (ApiException e) {
assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_GENERATE_LINK_PLAYER_NOT_FOUND));
}
verify(jwtService, Mockito.never()).sign(any());
}
use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class ClanServiceTest method acceptPlayerInvitationTokenPlayerIAlreadyInAClan.
@Test
public void acceptPlayerInvitationTokenPlayerIAlreadyInAClan() throws IOException {
String stringToken = "1234";
Clan clan = ClanFactory.builder().build();
Player newMember = new Player();
newMember.setId(2);
newMember.setClanMemberships(Collections.singleton(new ClanMembership().setClan(clan).setPlayer(newMember)));
long expire = System.currentTimeMillis() + 1000 * 3;
Jwt jwtToken = Mockito.mock(Jwt.class);
when(jwtToken.getClaims()).thenReturn(String.format("{\"expire\":%s,\"newMember\":{\"id\":%s},\"clan\":{\"id\":%s}}", expire, newMember.getId(), clan.getId()));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
when(playerRepository.findById(newMember.getId())).thenReturn(Optional.of(newMember));
when(playerService.getPlayer(any())).thenReturn(newMember);
try {
instance.acceptPlayerInvitationToken(stringToken, null);
fail();
} catch (ApiException e) {
assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_ACCEPT_PLAYER_IN_A_CLAN));
}
verify(clanMembershipRepository, Mockito.never()).save(any(ClanMembership.class));
}
Aggregations