Skip to content

Commit

Permalink
2024-10-22 - feedback - external reviewer - server-side
Browse files Browse the repository at this point in the history
  • Loading branch information
Luch76 committed Oct 22, 2024
1 parent 6723dc6 commit 72f24b2
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FeedbackExternalRecipient {
@NotNull
@Column(name="email")
@ColumnTransformer(
read = "pgp_sym_decrypt(workEmail::bytea,'${aes.key}')",
read = "pgp_sym_decrypt(email::bytea,'${aes.key}')",
write = "pgp_sym_encrypt(?,'${aes.key}') "
)
@Schema(description = "email of the feedback external recipient")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.objectcomputing.checkins.notifications.email.MailJetFactory;
import com.objectcomputing.checkins.services.MailJetFactoryReplacement;
import com.objectcomputing.checkins.services.TestContainersSuite;
import com.objectcomputing.checkins.services.feedback_external_recipient.FeedbackExternalRecipient;
import com.objectcomputing.checkins.services.feedback_template.FeedbackTemplate;
import com.objectcomputing.checkins.services.fixture.FeedbackRequestFixture;
import com.objectcomputing.checkins.services.fixture.FeedbackTemplateFixture;
import com.objectcomputing.checkins.services.fixture.MemberProfileFixture;
import com.objectcomputing.checkins.services.fixture.FeedbackExternalRecipientFixture;
import com.objectcomputing.checkins.services.fixture.ReviewPeriodFixture;
import com.objectcomputing.checkins.services.fixture.RoleFixture;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
Expand Down Expand Up @@ -45,7 +47,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

@Property(name = "replace.mailjet.factory", value = StringUtils.TRUE)
class FeedbackRequestControllerTest extends TestContainersSuite implements MemberProfileFixture, FeedbackTemplateFixture, FeedbackRequestFixture, RoleFixture, ReviewPeriodFixture {
class FeedbackRequestControllerTest extends TestContainersSuite implements MemberProfileFixture, FeedbackTemplateFixture, FeedbackRequestFixture, RoleFixture, ReviewPeriodFixture, FeedbackExternalRecipientFixture {

@Inject
@Client("/services/feedback/requests")
Expand Down Expand Up @@ -80,6 +82,7 @@ private FeedbackRequestCreateDTO createDTO(FeedbackRequest feedbackRequest) {
dto.setDueDate(feedbackRequest.getDueDate());
dto.setStatus(feedbackRequest.getStatus());
dto.setSubmitDate(feedbackRequest.getSubmitDate());
dto.setExternalRecipientId(feedbackRequest.getExternalRecipientId());
return dto;
}

Expand Down Expand Up @@ -120,15 +123,15 @@ private void assertResponseEqualsEntity(FeedbackRequest feedbackRequest, Feedbac
}

@Test
void testCreateFeedbackRequestByAdmin() {
void testCreateFeedbackRequestByAdminToRecipient() {
//create two member profiles: one for normal employee, one for admin
final MemberProfile memberProfile = createADefaultMemberProfile();
final MemberProfile admin = getMemberProfileRepository().save(mkMemberProfile("admin"));
final MemberProfile recipient = createADefaultRecipient();
assignAdminRole(admin);

//create feedback request
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, memberProfile, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, memberProfile, recipient);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

//send feedback request
Expand All @@ -147,11 +150,11 @@ void testCreateFeedbackRequestByAdminToExternalRecipient() {
//create two member profiles: one for normal employee, one for admin
final MemberProfile memberProfile = createADefaultMemberProfile();
final MemberProfile admin = getMemberProfileRepository().save(mkMemberProfile("admin"));
final MemberProfile recipient = createADefaultRecipient();
final FeedbackExternalRecipient feedbackExternalRecipient = createADefaultFeedbackExternalRecipient();
assignAdminRole(admin);

//create feedback request
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, memberProfile, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithExternalRecipient(admin, memberProfile, feedbackExternalRecipient);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

//send feedback request
Expand All @@ -174,7 +177,7 @@ void testCreateFeedbackRequestByAssignedPDL() {
final MemberProfile recipient = createADefaultRecipient();

//create feedback request
final FeedbackRequest feedbackRequest = createFeedbackRequest(pdlMemberProfile, employeeMemberProfile, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(pdlMemberProfile, employeeMemberProfile, recipient);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

//send feedback request
Expand All @@ -198,7 +201,7 @@ void testCreateFeedbackRequestSendsEmailNow() {
final MemberProfile recipient = createADefaultRecipient();

//create feedback request
final FeedbackRequest feedbackRequest = createFeedbackRequest(pdlMemberProfile, employeeMemberProfile, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(pdlMemberProfile, employeeMemberProfile, recipient);
feedbackRequest.setSendDate(LocalDate.now());
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand Down Expand Up @@ -230,7 +233,7 @@ void testCreateFeedbackRequestSendsEmailFuture() {
final MemberProfile recipient = createADefaultRecipient();

//create feedback request
final FeedbackRequest feedbackRequest = createFeedbackRequest(pdlMemberProfile, employeeMemberProfile, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(pdlMemberProfile, employeeMemberProfile, recipient);
feedbackRequest.setSendDate(LocalDate.now().plusDays(1));
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand All @@ -253,7 +256,7 @@ void testCreateFeedbackRequestByUnassignedPdl() {
MemberProfile recipient = createAnUnrelatedUser();

//create feedback request
final FeedbackRequest feedbackRequest = createFeedbackRequest(memberProfileForPDL, memberProfile, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(memberProfileForPDL, memberProfile, recipient);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

//send feedback request
Expand All @@ -273,7 +276,7 @@ void testCreateFeedbackRequestByMember() {
MemberProfile recipient = createAnUnrelatedUser();

//create feedback request
final FeedbackRequest feedbackRequest = createFeedbackRequest(requesteeProfile, memberProfile, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(requesteeProfile, memberProfile, recipient);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

//send feedback request
Expand All @@ -293,7 +296,7 @@ void testCreateFeedbackRequestWithInvalidCreatorId() {
assignAdminRole(admin);

// Create feedback request with invalid creator ID
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, requestee, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, requestee, recipient);
feedbackRequest.setCreatorId(UUID.randomUUID());
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand All @@ -315,7 +318,7 @@ void testCreateFeedbackRequestWithInvalidRecipientId() {
assignAdminRole(admin);

// Create feedback request with invalid recipient ID
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, requestee, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, requestee, recipient);
feedbackRequest.setRecipientId(UUID.randomUUID());
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand All @@ -337,7 +340,7 @@ void testCreateFeedbackRequestWithInvalidRequesteeId() {
assignAdminRole(admin);

// Create feedback request with invalid requestee ID
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, requestee, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, requestee, recipient);
feedbackRequest.setRequesteeId(UUID.randomUUID());
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand All @@ -359,7 +362,7 @@ void testCreateFeedbackRequestWithNoRequestee() {
assignAdminRole(admin);

// Create feedback request with no requestee
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, requestee, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, requestee, recipient);
feedbackRequest.setRequesteeId(null);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand All @@ -383,7 +386,7 @@ void testCreateFeedbackRequestWithNoRecipients() {
assignAdminRole(admin);

// Create feedback request with no recipient(s)
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, requestee, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, requestee, recipient);
feedbackRequest.setRecipientId(null);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand All @@ -407,7 +410,7 @@ void testCreateFeedbackRequestWithNoSelectedTemplate() {
assignAdminRole(admin);

// Create feedback request with no template
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, requestee, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, requestee, recipient);
feedbackRequest.setTemplateId(null);
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);

Expand All @@ -431,7 +434,7 @@ void testCreateFeedbackRequestWithSendDateAfterDueDate() {
assignAdminRole(admin);

// Create feedback request with invalid requestee ID
final FeedbackRequest feedbackRequest = createFeedbackRequest(admin, requestee, recipient);
final FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(admin, requestee, recipient);
feedbackRequest.setSendDate(LocalDate.of(1111, 11, 2));
feedbackRequest.setDueDate(LocalDate.of(1111, 11, 1));
final FeedbackRequestCreateDTO dto = createDTO(feedbackRequest);
Expand Down Expand Up @@ -1006,7 +1009,7 @@ void testUpdateSubmitDateNotAuthorized() {
MemberProfile recipient = createADefaultRecipient();

// Save feedback request that has not been submitted yet
final FeedbackRequest feedbackReq = createFeedbackRequest(pdl, requestee, recipient);
final FeedbackRequest feedbackReq = createFeedbackRequestWithRecipient(pdl, requestee, recipient);
feedbackReq.setSubmitDate(null);
getFeedbackRequestRepository().save(feedbackReq);

Expand All @@ -1030,7 +1033,7 @@ void testUpdateSubmitDateWhenPdlEnablesEdits() {
MemberProfile recipient = createADefaultRecipient();

// Save feedback request that has already been submitted
final FeedbackRequest feedbackReq = createFeedbackRequest(pdl, requestee, recipient);
final FeedbackRequest feedbackReq = createFeedbackRequestWithRecipient(pdl, requestee, recipient);
feedbackReq.setSubmitDate(LocalDate.now());
getFeedbackRequestRepository().save(feedbackReq);

Expand All @@ -1055,7 +1058,7 @@ void testFeedbackRequestEnableEditsSendsEmail() {
MemberProfile recipient = createADefaultRecipient();

// Save feedback request that has already been submitted
final FeedbackRequest feedbackReq = createFeedbackRequest(pdl, requestee, recipient);
final FeedbackRequest feedbackReq = createFeedbackRequestWithRecipient(pdl, requestee, recipient);
feedbackReq.setSubmitDate(LocalDate.now());
feedbackReq.setStatus("submitted");
getFeedbackRequestRepository().save(feedbackReq);
Expand Down Expand Up @@ -1272,7 +1275,7 @@ void testRecipientGetBeforeSendDateNotAuthorized() {
MemberProfile pdlMemberProfile = createADefaultMemberProfile();
MemberProfile requestee = createADefaultMemberProfileForPdl(pdlMemberProfile);
MemberProfile recipient = createADefaultRecipient();
FeedbackRequest feedbackRequest = createFeedbackRequest(pdlMemberProfile, requestee, recipient);
FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(pdlMemberProfile, requestee, recipient);
feedbackRequest.setSendDate(LocalDate.now().plusDays(1));
getFeedbackRequestRepository().save(feedbackRequest);

Expand All @@ -1296,7 +1299,7 @@ void testRecipientGetBeforeSendDateAsAdminAuthorized() {
assignAdminRole(adminUser);

// Save feedback request with send date in the future
FeedbackRequest feedbackRequest = createFeedbackRequest(pdlMemberProfile, requestee, recipient);
FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(pdlMemberProfile, requestee, recipient);
feedbackRequest.setSendDate(LocalDate.now().plusDays(1));
getFeedbackRequestRepository().save(feedbackRequest);

Expand All @@ -1318,7 +1321,7 @@ void testRecipientGetBeforeSendDateAsPdlAuthorized() {
MemberProfile recipient = createADefaultRecipient();

// Save feedback request with send date in the future
FeedbackRequest feedbackRequest = createFeedbackRequest(pdlMemberProfile, requestee, recipient);
FeedbackRequest feedbackRequest = createFeedbackRequestWithRecipient(pdlMemberProfile, requestee, recipient);
feedbackRequest.setSendDate(LocalDate.now().plusDays(1));
getFeedbackRequestRepository().save(feedbackRequest);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.objectcomputing.checkins.services.fixture;

import com.objectcomputing.checkins.services.feedback_external_recipient.FeedbackExternalRecipient;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;

import java.time.LocalDate;
import java.util.Map;

public interface FeedbackExternalRecipientFixture extends RepositoryFixture {

default FeedbackExternalRecipient createADefaultFeedbackExternalRecipient() {
String email = "[email protected]";
String firstName = "External-01";
String lastName = "Recipient";
String companyName = "Company Name";

return getFeedbackExternalRecipientRepository().save(new FeedbackExternalRecipient(
email, firstName, lastName, companyName
));
}

}
Loading

0 comments on commit 72f24b2

Please sign in to comment.