Search in sources :

Example 1 with Guild

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());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) JsonNode(com.fasterxml.jackson.databind.JsonNode) Guild(com.objectcomputing.checkins.services.guild.Guild) Test(org.junit.jupiter.api.Test)

Example 2 with Guild

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());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) JsonNode(com.fasterxml.jackson.databind.JsonNode) Guild(com.objectcomputing.checkins.services.guild.Guild) Test(org.junit.jupiter.api.Test)

Example 3 with Guild

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());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) JsonNode(com.fasterxml.jackson.databind.JsonNode) Guild(com.objectcomputing.checkins.services.guild.Guild) Test(org.junit.jupiter.api.Test)

Example 4 with Guild

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"));
}
Also used : MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) Guild(com.objectcomputing.checkins.services.guild.Guild) Test(org.junit.jupiter.api.Test)

Example 5 with Guild

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());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) JsonNode(com.fasterxml.jackson.databind.JsonNode) Guild(com.objectcomputing.checkins.services.guild.Guild) Test(org.junit.jupiter.api.Test)

Aggregations

Guild (com.objectcomputing.checkins.services.guild.Guild)36 MemberProfile (com.objectcomputing.checkins.services.memberprofile.MemberProfile)36 Test (org.junit.jupiter.api.Test)32 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 BadArgException (com.objectcomputing.checkins.exceptions.BadArgException)3 NotFoundException (com.objectcomputing.checkins.exceptions.NotFoundException)2 PermissionException (com.objectcomputing.checkins.exceptions.PermissionException)2 UUID (java.util.UUID)2