Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] Migrate SubmitFeedbackResponseAction's tests #12760

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c4228c7
Initial draft for migrated
FergusMok Jan 31, 2024
84f61e2
Add tests
FergusMok Feb 5, 2024
d59938c
Add implementation
FergusMok Feb 6, 2024
f27e407
Add implementation
FergusMok Feb 6, 2024
41a7809
Add implementation
FergusMok Feb 6, 2024
533b13a
Migrate updateFeedbackResponseCascade and deleteFeedbackResponsesAndC…
FergusMok Feb 6, 2024
6443cb9
Revert unnecessary changes, add tests
FergusMok Feb 6, 2024
062bce8
Fix linting and tests
FergusMok Feb 6, 2024
322f7a2
Merge branch 'v9-migration' into 12048-migrate-submit-feedbackrespons…
FergusMok Feb 6, 2024
df5cd5b
Merge changes with db
FergusMok Feb 7, 2024
b22efb0
Merge branch '12048-migrate-submit-feedbackresponse-db' into 12048-mi…
FergusMok Feb 7, 2024
be525ae
Merge branch '12048-migrate-submit-feedbackresponse-db' into 12048-mi…
FergusMok Feb 7, 2024
5f8025b
Migrate updateFeedbackResponseCascade and deleteFeedbackResponsesAndC…
FergusMok Feb 6, 2024
fa310bb
Revert unnecessary changes, add tests
FergusMok Feb 6, 2024
36df981
Fix linting and tests
FergusMok Feb 6, 2024
3382b5d
Merge branch '12048-migrate-submit-feedbackresponse-db' into 12048-mi…
FergusMok Feb 7, 2024
50d3f61
Save progress
FergusMok Feb 14, 2024
2ec4d6c
Migrate updateFeedbackResponseCascade and deleteFeedbackResponsesAndC…
FergusMok Feb 6, 2024
03aed0a
Merge branch 'v9-migration' into 12048-migrate-submit-feedbackrespons…
FergusMok Feb 18, 2024
f57131f
Fix linting errors
FergusMok Feb 18, 2024
9737828
Merge with db changes
FergusMok Feb 18, 2024
04aa41b
Clean up commits
FergusMok Feb 18, 2024
1be8a2a
Disable failing test
FergusMok Feb 18, 2024
e2e6a63
Replace giver with updatedAt to make test clearer
FergusMok Feb 18, 2024
6f9d854
Merge branch '12048-migrate-submit-feedbackresponse-db' into 12048-mi…
FergusMok Feb 19, 2024
9a748cc
Add IT setUp
FergusMok Feb 19, 2024
192f996
Save progress on tests
FergusMok Feb 19, 2024
8fdc414
Merge with upstream
FergusMok Feb 19, 2024
469403e
Add tests and comments
FergusMok Feb 19, 2024
8c31ec6
Merge with upstream
FergusMok Feb 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/it/java/teammates/it/ui/webapi/BaseActionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import teammates.logic.api.MockRecaptchaVerifier;
import teammates.logic.api.MockTaskQueuer;
import teammates.logic.api.MockUserProvision;
import teammates.sqllogic.api.Logic;
import teammates.sqllogic.api.LogicExtension;
import teammates.storage.sqlentity.Account;
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.Instructor;
Expand Down Expand Up @@ -63,7 +63,7 @@ public abstract class BaseActionIT<T extends Action> extends BaseTestCaseWithSql
static final String DELETE = HttpDelete.METHOD_NAME;

SqlDataBundle typicalBundle = getTypicalSqlDataBundle();
Logic logic = Logic.inst();
LogicExtension logic = new LogicExtension();
MockTaskQueuer mockTaskQueuer = new MockTaskQueuer();
MockEmailSender mockEmailSender = new MockEmailSender();
MockLogsProcessor mockLogsProcessor = new MockLogsProcessor();
Expand Down

Large diffs are not rendered by default.

61 changes: 54 additions & 7 deletions src/it/resources/data/typicalDataBundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,33 @@
"isClosedEmailSent": false,
"isPublishedEmailSent": true
},
"session2InTypicalCourse": {
"closedSessionInCourse1": {
"id": "00000000-0000-4000-8000-000000000702",
"course": {
"id": "course-1"
},
"name": "Closed Session",
"creatorEmail": "instr1@teammates.tmt",
"instructions": "Please please fill in the following questions.",
"startTime": "2013-06-01T22:00:00Z",
"endTime": "2013-06-01T22:00:00Z",
"sessionVisibleFromTime": "2013-03-20T22:00:00Z",
"resultsVisibleFromTime": "2013-04-29T22:00:00Z",
"gracePeriod": 5,
"isOpeningEmailEnabled": true,
"isClosingEmailEnabled": true,
"isPublishedEmailEnabled": true,
"isOpeningSoonEmailSent": true,
"isOpenEmailSent": true,
"isClosingSoonEmailSent": false,
"isClosedEmailSent": false,
"isPublishedEmailSent": false
},
"session2InTypicalCourse": {
"id": "00000000-0000-4000-8000-000000000703",
"course": {
"id": "course-1"
},
"name": "Second feedback session",
"creatorEmail": "instr1@teammates.tmt",
"instructions": "Please please fill in the following questions.",
Expand All @@ -721,7 +743,7 @@
"isPublishedEmailSent": false
},
"unpublishedSession1InTypicalCourse": {
"id": "00000000-0000-4000-8000-000000000703",
"id": "00000000-0000-4000-8000-000000000704",
"course": {
"id": "course-1"
},
Expand All @@ -743,7 +765,7 @@
"isPublishedEmailSent": false
},
"ongoingSession1InCourse1": {
"id": "00000000-0000-4000-8000-000000000704",
"id": "00000000-0000-4000-8000-000000000705",
"course": {
"id": "course-1"
},
Expand All @@ -765,7 +787,7 @@
"isPublishedEmailSent": true
},
"ongoingSession2InCourse1": {
"id": "00000000-0000-4000-8000-000000000705",
"id": "00000000-0000-4000-8000-000000000706",
"course": {
"id": "course-1"
},
Expand All @@ -787,7 +809,7 @@
"isPublishedEmailSent": true
},
"ongoingSession3InCourse1": {
"id": "00000000-0000-4000-8000-000000000706",
"id": "00000000-0000-4000-8000-000000000707",
"course": {
"id": "course-1"
},
Expand All @@ -809,7 +831,7 @@
"isPublishedEmailSent": true
},
"ongoingSession1InCourse3": {
"id": "00000000-0000-4000-8000-000000000707",
"id": "00000000-0000-4000-8000-000000000708",
"course": {
"id": "course-3"
},
Expand All @@ -831,7 +853,7 @@
"isPublishedEmailSent": true
},
"ongoingSession2InCourse3": {
"id": "00000000-0000-4000-8000-000000000707",
"id": "00000000-0000-4000-8000-000000000709",
"course": {
"id": "course-3"
},
Expand Down Expand Up @@ -1019,6 +1041,31 @@
"showResponsesTo": ["INSTRUCTORS"],
"showGiverNameTo": ["INSTRUCTORS"],
"showRecipientNameTo": ["INSTRUCTORS"]
},
"qn1InClosedSessionInCourse1": {
"id": "00000000-0000-4000-8001-000000000807",
"feedbackSession": {
"id": "00000000-0000-4000-8000-000000000702"
},
"questionDetails": {
"recommendedLength": 100,
"questionType": "TEXT",
"questionText": "Give feedback to yourself."
},
"description": "This is a mcq question.",
"questionNumber": 1,
"giverType": "INSTRUCTORS",
"recipientType": "SELF",
"numOfEntitiesToGiveFeedbackTo": 1,
"showResponsesTo": [
"RECEIVER"
],
"showGiverNameTo": [
"RECEIVER"
],
"showRecipientNameTo": [
"RECEIVER"
]
}
},
"feedbackResponses": {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/teammates/sqllogic/api/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.annotation.Nullable;

import teammates.common.datatransfer.DataBundle;
import teammates.common.datatransfer.FeedbackQuestionRecipient;
import teammates.common.datatransfer.NotificationStyle;
import teammates.common.datatransfer.NotificationTargetUser;
Expand All @@ -19,6 +20,7 @@
import teammates.common.exception.InvalidParametersException;
import teammates.common.exception.SearchServiceException;
import teammates.common.exception.StudentUpdateException;
import teammates.logic.core.StudentsLogic;
import teammates.sqllogic.core.AccountRequestsLogic;
import teammates.sqllogic.core.AccountsLogic;
import teammates.sqllogic.core.CoursesLogic;
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/teammates/sqllogic/api/LogicExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package teammates.sqllogic.api;

import java.util.UUID;

import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;

/**
* Holds additional methods for {@link Logic} used only in tests.
*/
public class LogicExtension extends Logic {

/**
* Gets the unique feedback question based on sessionId and questionNumber.
*/
public FeedbackQuestion getFeedbackQuestionForSessionQuestionNumber(UUID sessionId, int questionNumber) {
return feedbackQuestionsLogic.getFeedbackQuestionForSessionQuestionNumber(sessionId, questionNumber);
}

/**
* Gets a single question corresponding to question-giver-receiver.
*/
public FeedbackResponse getFeedbackResponseForQuestionGiverRecipient(
UUID feedbackQuestionId,
String giver,
String recipient) {
return feedbackResponsesLogic.getFeedbackResponseForQuestionGiverRecipient(feedbackQuestionId, giver, recipient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public FeedbackQuestion getFeedbackQuestion(UUID id) {
return fqDb.getFeedbackQuestion(id);
}

/**
* Gets the unique feedback question based on sessionId and questionNumber.
*/
public FeedbackQuestion getFeedbackQuestionForSessionQuestionNumber(UUID sessionId, int questionNumber) {
return fqDb.getFeedbackQuestionForSessionQuestionNumber(sessionId, questionNumber);
}

/**
* Gets a {@link List} of every FeedbackQuestion in the given session.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/teammates/sqllogic/core/FeedbackResponsesLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public FeedbackResponse getFeedbackResponse(UUID frId) {
return frDb.getFeedbackResponse(frId);
}

/**
* Gets a single question corresponding to question-giver-receiver.
*/
public FeedbackResponse getFeedbackResponseForQuestionGiverRecipient(
UUID feedbackQuestionId,
String giver,
String recipient) {
return frDb.getFeedbackResponseForQuestionGiverRecipient(feedbackQuestionId, giver, recipient);
}

/**
* Returns true if the responses of the question are visible to students.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/teammates/storage/sqlapi/EntitiesDb.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

package teammates.storage.sqlapi;

import com.google.common.base.Objects;

import teammates.common.util.HibernateUtil;
import teammates.common.util.Logger;
import teammates.storage.sqlentity.BaseEntity;
Expand Down Expand Up @@ -43,4 +45,11 @@ protected void delete(BaseEntity entity) {
HibernateUtil.remove(entity);
log.info("Entity deleted: " + entity.toString());
}

/**
* Checks whether two values are the same.
*/
<T> boolean hasSameValue(T oldValue, T newValue) {
return Objects.equal(oldValue, newValue);
}
}
16 changes: 16 additions & 0 deletions src/main/java/teammates/storage/sqlapi/FeedbackQuestionsDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ public List<FeedbackQuestion> getFeedbackQuestionsForSession(UUID fdId) {
return HibernateUtil.createQuery(cq).getResultList();
}

/**
* Gets the unique feedback question based on sessionId and questionNumber.
*/
public FeedbackQuestion getFeedbackQuestionForSessionQuestionNumber(UUID sessionId, int questionNumber) {
CriteriaBuilder cb = HibernateUtil.getCriteriaBuilder();
CriteriaQuery<FeedbackQuestion> cq = cb.createQuery(FeedbackQuestion.class);
Root<FeedbackQuestion> fqRoot = cq.from(FeedbackQuestion.class);
Join<FeedbackQuestion, FeedbackSession> fqJoin = fqRoot.join("feedbackSession");
cq.select(fqRoot).where(
cb.and(
cb.equal(fqJoin.get("id"), sessionId),
cb.equal(fqRoot.get("questionNumber"), questionNumber)
));
return HibernateUtil.createQuery(cq).getResultStream().findFirst().orElse(null);
}

/**
* Gets a list of feedback questions by {@code feedbackSession} and {@code giverType}.
*
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/teammates/storage/sqlapi/FeedbackResponsesDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ public FeedbackResponse getFeedbackResponse(UUID frId) {
return HibernateUtil.get(FeedbackResponse.class, frId);
}

/**
* Gets the unique feedback response by question-giver-receiver.
*/
public FeedbackResponse getFeedbackResponseForQuestionGiverRecipient(
UUID feedbackSessionId,
String giver,
String recipient) {
assert feedbackSessionId != null;

CriteriaBuilder cb = HibernateUtil.getCriteriaBuilder();
CriteriaQuery<FeedbackResponse> cq = cb.createQuery(FeedbackResponse.class);
Root<FeedbackResponse> root = cq.from(FeedbackResponse.class);
Join<FeedbackResponse, FeedbackSession> frJoin = root.join("feedbackSession");
cq.select(root)
.where(cb.and(
cb.equal(frJoin.get("id"), feedbackSessionId),
cb.equal(root.get("giver"), giver),
cb.equal(root.get("recipient"), recipient)
));

return HibernateUtil.createQuery(cq).getSingleResult();
}

/**
* Gets all responses given by a user in a course.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ public void setFeedbackSession(FeedbackSession feedbackSession) {
this.feedbackSession = feedbackSession;
}

public String getFeedbackSessionName() {
return feedbackSession.getName();
}

public List<FeedbackResponse> getFeedbackResponses() {
return feedbackResponses;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public void setFeedbackQuestion(FeedbackQuestion feedbackQuestion) {
this.feedbackQuestion = feedbackQuestion;
}

public UUID getFeedbackQuestionId() {
return feedbackQuestion.getId();
}

public List<FeedbackResponseComment> getFeedbackResponseComments() {
return feedbackResponseComments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public void setCourse(Course course) {
this.course = course;
}

public String getCourseId() {
return course.getId();
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package teammates.ui.webapi;

import org.hibernate.sql.results.LoadingLogger_.logger;

import teammates.common.datatransfer.FeedbackParticipantType;
import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes;
import teammates.common.datatransfer.attributes.FeedbackSessionAttributes;
import teammates.common.datatransfer.attributes.InstructorAttributes;
import teammates.common.datatransfer.attributes.StudentAttributes;
import teammates.common.util.Const;
import teammates.common.util.Logger;
import teammates.common.util.StringHelper;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackSession;
Expand Down Expand Up @@ -299,6 +302,8 @@ void verifyNotPreview() throws UnauthorizedAccessException {
*/
void verifySessionOpenExceptForModeration(FeedbackSessionAttributes feedbackSession) throws UnauthorizedAccessException {
String moderatedPerson = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_MODERATED_PERSON);
boolean isOpened = feedbackSession.isOpened();
boolean isInGrace = feedbackSession.isInGracePeriod();

if (StringHelper.isEmpty(moderatedPerson) && !(feedbackSession.isOpened() || feedbackSession.isInGracePeriod())) {
throw new UnauthorizedAccessException("The feedback session is not available for submission", true);
Expand All @@ -312,7 +317,8 @@ void verifySessionOpenExceptForModeration(FeedbackSessionAttributes feedbackSess
*/
void verifySessionOpenExceptForModeration(FeedbackSession feedbackSession) throws UnauthorizedAccessException {
String moderatedPerson = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_MODERATED_PERSON);

boolean isOpened = feedbackSession.isOpened();
boolean isInGrace = feedbackSession.isInGracePeriod();
if (StringHelper.isEmpty(moderatedPerson) && !(feedbackSession.isOpened() || feedbackSession.isInGracePeriod())) {
throw new UnauthorizedAccessException("The feedback session is not available for submission", true);
}
Expand Down
Loading