use of com.objectcomputing.checkins.services.guild.Guild in project check-ins by objectcomputing.
the class GuildMemberControllerTest method testUpdateGuildMemberThrowExceptionWithInvalidId.
@Test
void testUpdateGuildMemberThrowExceptionWithInvalidId() {
Guild guild = createDefaultGuild();
MemberProfile memberProfile = createADefaultMemberProfile();
GuildMember guildMember = createDefaultGuildMember(guild, memberProfile);
guildMember.setId(UUID.randomUUID());
guildMember.setMemberId(guildMember.getMemberId());
guildMember.setGuildId(guildMember.getGuildId());
final MutableHttpRequest<GuildMember> request = HttpRequest.PUT("", guildMember).basicAuth(MEMBER_ROLE, MEMBER_ROLE);
HttpClientResponseException responseException = assertThrows(HttpClientResponseException.class, () -> client.toBlocking().exchange(request, Map.class));
JsonNode body = responseException.getResponse().getBody(JsonNode.class).orElse(null);
String error = Objects.requireNonNull(body).get("message").asText();
String href = Objects.requireNonNull(body).get("_links").get("self").get("href").asText();
assertEquals(String.format("Unable to locate guildMember to update with id %s", guildMember.getId()), error);
assertEquals(request.getPath(), href);
assertEquals(HttpStatus.BAD_REQUEST, responseException.getStatus());
}
use of com.objectcomputing.checkins.services.guild.Guild in project check-ins by objectcomputing.
the class GuildMemberControllerTest method testUpdateGuildMemberThrowsExceptionForNotAdminAndNotGuildLead.
@Test
void testUpdateGuildMemberThrowsExceptionForNotAdminAndNotGuildLead() {
Guild guild = createDefaultGuild();
MemberProfile memberProfile = createADefaultMemberProfile();
GuildMember guildMember = createDefaultGuildMember(guild, memberProfile);
final HttpRequest<GuildMember> request = HttpRequest.PUT("", guildMember).basicAuth(MEMBER_ROLE, MEMBER_ROLE);
HttpClientResponseException responseException = assertThrows(HttpClientResponseException.class, () -> client.toBlocking().exchange(request, Map.class));
JsonNode body = responseException.getResponse().getBody(JsonNode.class).orElse(null);
String error = Objects.requireNonNull(body).get("message").asText();
String href = Objects.requireNonNull(body).get("_links").get("self").get("href").asText();
assertEquals(request.getPath(), href);
assertEquals("You are not authorized to perform this operation", error);
assertEquals(HttpStatus.BAD_REQUEST, responseException.getStatus());
}
use of com.objectcomputing.checkins.services.guild.Guild in project check-ins by objectcomputing.
the class GuildMemberControllerTest method testUpdateGuildMemberThrowException.
@Test
void testUpdateGuildMemberThrowException() {
Guild guild = createDefaultGuild();
MemberProfile memberProfile = createADefaultMemberProfile();
GuildMember guildMember = createDefaultGuildMember(guild, memberProfile);
guildMember.setMemberId(UUID.randomUUID());
guildMember.setGuildId(guildMember.getGuildId());
final MutableHttpRequest<GuildMember> request = HttpRequest.PUT("", guildMember).basicAuth(MEMBER_ROLE, MEMBER_ROLE);
HttpClientResponseException responseException = assertThrows(HttpClientResponseException.class, () -> client.toBlocking().exchange(request, Map.class));
JsonNode body = responseException.getResponse().getBody(JsonNode.class).orElse(null);
String error = Objects.requireNonNull(body).get("message").asText();
String href = Objects.requireNonNull(body).get("_links").get("self").get("href").asText();
assertEquals(String.format("Member %s doesn't exist", guildMember.getMemberId()), error);
assertEquals(request.getPath(), href);
assertEquals(HttpStatus.BAD_REQUEST, responseException.getStatus());
}
use of com.objectcomputing.checkins.services.guild.Guild in project check-ins by objectcomputing.
the class GuildMemberControllerTest method testUpdateGuildMemberByGuildLead.
@Test
void testUpdateGuildMemberByGuildLead() {
Guild guild = createDefaultGuild();
// Create a guild lead and add him to the guild
MemberProfile memberProfileOfGuildLead = createADefaultMemberProfile();
createLeadGuildMember(guild, memberProfileOfGuildLead);
// Create a member and add him to guild
MemberProfile memberProfileOfUser = createAnUnrelatedUser();
GuildMember guildMember = createDefaultGuildMember(guild, memberProfileOfUser);
// Update member
GuildMemberUpdateDTO guildMemberUpdateDTO = new GuildMemberUpdateDTO(guildMember.getId(), guildMember.getGuildId(), guildMember.getMemberId(), true);
final MutableHttpRequest<GuildMemberUpdateDTO> request = HttpRequest.PUT("", guildMemberUpdateDTO).basicAuth(memberProfileOfGuildLead.getWorkEmail(), MEMBER_ROLE);
final HttpResponse<GuildMember> response = client.toBlocking().exchange(request, GuildMember.class);
GuildMember result = response.body();
assertNotNull(result);
assertEquals(guildMember.getMemberId(), result.getMemberId());
assertTrue(result.isLead());
assertEquals(HttpStatus.OK, response.getStatus());
assertEquals(String.format("%s/%s", request.getPath(), guildMember.getId()), response.getHeaders().get("location"));
}
use of com.objectcomputing.checkins.services.guild.Guild in project check-ins by objectcomputing.
the class GuildMemberControllerTest method testUpdateGuildMemberThrowExceptionWithNoGuild.
@Test
void testUpdateGuildMemberThrowExceptionWithNoGuild() {
Guild guild = createDefaultGuild();
MemberProfile memberProfile = createADefaultMemberProfile();
GuildMember guildMember = createDefaultGuildMember(guild, memberProfile);
guildMember.setMemberId(guildMember.getMemberId());
guildMember.setGuildId(UUID.randomUUID());
final MutableHttpRequest<GuildMember> request = HttpRequest.PUT("", guildMember).basicAuth(MEMBER_ROLE, MEMBER_ROLE);
HttpClientResponseException responseException = assertThrows(HttpClientResponseException.class, () -> client.toBlocking().exchange(request, Map.class));
JsonNode body = responseException.getResponse().getBody(JsonNode.class).orElse(null);
String error = Objects.requireNonNull(body).get("message").asText();
String href = Objects.requireNonNull(body).get("_links").get("self").get("href").asText();
assertEquals(String.format("Guild %s doesn't exist", guildMember.getGuildId()), error);
assertEquals(request.getPath(), href);
assertEquals(HttpStatus.BAD_REQUEST, responseException.getStatus());
}
Aggregations