Skip to content

Commit

Permalink
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
Browse files Browse the repository at this point in the history
  • Loading branch information
xenosf committed Feb 4, 2024
2 parents 4ef3cec + c8723d5 commit ed81535
Show file tree
Hide file tree
Showing 29 changed files with 1,321 additions and 104 deletions.
86 changes: 86 additions & 0 deletions src/it/java/teammates/it/sqllogic/core/DataBundleLogicIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
import teammates.common.datatransfer.questions.FeedbackResponseDetails;
import teammates.common.datatransfer.questions.FeedbackTextQuestionDetails;
import teammates.common.datatransfer.questions.FeedbackTextResponseDetails;
import teammates.common.exception.EntityAlreadyExistsException;
import teammates.common.exception.InvalidParametersException;
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess;
import teammates.sqllogic.core.DataBundleLogic;
import teammates.storage.sqlentity.Account;
import teammates.storage.sqlentity.AccountRequest;
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.DeadlineExtension;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.FeedbackResponseComment;
Expand Down Expand Up @@ -233,4 +236,87 @@ public void testPersistDataBundle_typicalValues_persistedToDbCorrectly() throws
// TODO: incomplete
}

@Test
public void testRemoveDataBundle_typicalValues_removedCorrectly()
throws InvalidParametersException, EntityAlreadyExistsException {
SqlDataBundle dataBundle = loadSqlDataBundle("/DataBundleLogicIT.json");
dataBundleLogic.persistDataBundle(dataBundle);

______TS("verify notifications persisted correctly");
Notification notification1 = dataBundle.notifications.get("notification1");

verifyPresentInDatabase(notification1);

______TS("verify course persisted correctly");
Course typicalCourse = dataBundle.courses.get("typicalCourse");

verifyPresentInDatabase(typicalCourse);

______TS("verify feedback session persisted correctly");
FeedbackSession session1InTypicalCourse = dataBundle.feedbackSessions.get("session1InTypicalCourse");

verifyPresentInDatabase(session1InTypicalCourse);

______TS("verify accounts persisted correctly");
Account instructor1Account = dataBundle.accounts.get("instructor1");
Account student1Account = dataBundle.accounts.get("student1");

verifyPresentInDatabase(instructor1Account);
verifyPresentInDatabase(student1Account);

______TS("verify account request persisted correctly");
AccountRequest accountRequest = dataBundle.accountRequests.get("instructor1");

verifyPresentInDatabase(accountRequest);

dataBundleLogic.removeDataBundle(dataBundle);

______TS("verify notification removed correctly");

assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(notification1));

______TS("verify course removed correctly");

assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(typicalCourse));

______TS("verify feedback session removed correctly");

assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(session1InTypicalCourse));

______TS("verify feedback questions, responses, response comments and deadline extensions "
+ "related to session1InTypicalCourse are removed correctly");

List<FeedbackQuestion> fqs = session1InTypicalCourse.getFeedbackQuestions();
List<DeadlineExtension> des = session1InTypicalCourse.getDeadlineExtensions();
List<FeedbackResponse> frs = new ArrayList<>();
List<FeedbackResponseComment> frcs = new ArrayList<>();

for (DeadlineExtension de : des) {
assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(de));
}

for (FeedbackQuestion fq : fqs) {
frs.addAll(fq.getFeedbackResponses());
assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(fq));
}

for (FeedbackResponse fr : frs) {
frcs.addAll(fr.getFeedbackResponseComments());
assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(fr));
}

for (FeedbackResponseComment frc : frcs) {
assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(frc));
}

______TS("verify accounts removed correctly");

assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(instructor1Account));
assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(student1Account));

______TS("verify account request removed correctly");

assertThrows(NullPointerException.class, () -> verifyPresentInDatabase(accountRequest));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ public void testGetFeedbackSessionsForInstructors() {
}
}

@Test
public void testGetOngoingSessions_typicalCase_shouldGetOnlyOngoingSessionsWithinRange() {
FeedbackSession c1Fs2 = typicalDataBundle.feedbackSessions.get("ongoingSession2InCourse1");
FeedbackSession c1Fs3 = typicalDataBundle.feedbackSessions.get("ongoingSession3InCourse1");
FeedbackSession c3Fs2 = typicalDataBundle.feedbackSessions.get("ongoingSession2InCourse3");
Set<FeedbackSession> expectedUniqueOngoingSessions = new HashSet<>();
expectedUniqueOngoingSessions.add(c1Fs2);
expectedUniqueOngoingSessions.add(c1Fs3);
expectedUniqueOngoingSessions.add(c3Fs2);
Instant rangeStart = Instant.parse("2012-01-25T22:00:00Z");
Instant rangeEnd = Instant.parse("2012-01-27T22:00:00Z");
List<FeedbackSession> actualOngoingSessions = fsLogic.getOngoingSessions(rangeStart, rangeEnd);
Set<FeedbackSession> actualUniqueOngoingSessions = new HashSet<>();
actualUniqueOngoingSessions.addAll(actualOngoingSessions);
assertEquals(expectedUniqueOngoingSessions, actualUniqueOngoingSessions);
}

@Test
public void testGetSoftDeletedFeedbackSessionsForInstructors() {
Instructor instructor = typicalDataBundle.instructors.get("instructor1OfCourse1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testCreateReadDeleteAccountRequest() throws Exception {
______TS("Read account request using the given registration key");

AccountRequest actualAccReqRegistrationKey =
accountRequestDb.getAccountRequest(accountRequest.getRegistrationKey());
accountRequestDb.getAccountRequestByRegistrationKey(accountRequest.getRegistrationKey());
verifyEquals(accountRequest, actualAccReqRegistrationKey);

______TS("Read account request using the given start and end timing");
Expand Down
49 changes: 49 additions & 0 deletions src/it/java/teammates/it/storage/sqlapi/FeedbackSessionsDbIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.time.Duration;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.testng.annotations.Test;

Expand Down Expand Up @@ -42,6 +45,52 @@ public void testGetFeedbackSessionByFeedbackSessionNameAndCourseId()
verifyEquals(fs2, actualFs);
}

@Test
public void testGetOngoingSessions_typicalCase_shouldGetOnlyOngoingSessionsWithinRange()
throws EntityAlreadyExistsException, InvalidParametersException {
Instant instantNow = Instant.now();
Course course1 = new Course("test-id1", "test-name1", "UTC", "NUS");
coursesDb.createCourse(course1);
FeedbackSession c1Fs1 = new FeedbackSession("name1-1", course1, "[email protected]", "test-instruction",
instantNow.minus(Duration.ofDays(7L)), instantNow.minus(Duration.ofDays(1L)),
instantNow.minus(Duration.ofDays(7L)), instantNow.plus(Duration.ofDays(7L)), Duration.ofMinutes(10L),
true, true, true);
fsDb.createFeedbackSession(c1Fs1);
FeedbackSession c1Fs2 = new FeedbackSession("name1-2", course1, "[email protected]", "test-instruction",
instantNow, instantNow.plus(Duration.ofDays(7L)),
instantNow.minus(Duration.ofDays(7L)), instantNow.plus(Duration.ofDays(7L)), Duration.ofMinutes(10L),
true, true, true);
fsDb.createFeedbackSession(c1Fs2);
Course course2 = new Course("test-id2", "test-name2", "UTC", "MIT");
coursesDb.createCourse(course2);
FeedbackSession c2Fs1 = new FeedbackSession("name2-1", course2, "[email protected]", "test-instruction",
instantNow.minus(Duration.ofHours(12L)), instantNow.plus(Duration.ofHours(12L)),
instantNow.minus(Duration.ofDays(7L)), instantNow.plus(Duration.ofDays(7L)), Duration.ofMinutes(10L),
true, true, true);
fsDb.createFeedbackSession(c2Fs1);
FeedbackSession c2Fs2 = new FeedbackSession("name2-2", course2, "[email protected]", "test-instruction",
instantNow.plus(Duration.ofDays(1L)), instantNow.plus(Duration.ofDays(7L)),
instantNow.minus(Duration.ofDays(7L)), instantNow.plus(Duration.ofDays(7L)), Duration.ofMinutes(10L),
true, true, true);
fsDb.createFeedbackSession(c2Fs2);
Course course3 = new Course("test-id3", "test-name3", "UTC", "UCL");
coursesDb.createCourse(course3);
FeedbackSession c3Fs1 = new FeedbackSession("name3-1", course3, "[email protected]", "test-instruction",
instantNow.minus(Duration.ofDays(7L)), instantNow,
instantNow.minus(Duration.ofDays(7L)), instantNow.plus(Duration.ofDays(7L)), Duration.ofMinutes(10L),
true, true, true);
fsDb.createFeedbackSession(c3Fs1);
Set<FeedbackSession> expectedUniqueOngoingSessions = new HashSet<>();
expectedUniqueOngoingSessions.add(c1Fs2);
expectedUniqueOngoingSessions.add(c2Fs1);
expectedUniqueOngoingSessions.add(c3Fs1);
List<FeedbackSession> actualOngoingSessions =
fsDb.getOngoingSessions(instantNow.minus(Duration.ofDays(1L)), instantNow.plus(Duration.ofDays(1L)));
Set<FeedbackSession> actualUniqueOngoingSessions = new HashSet<>();
actualUniqueOngoingSessions.addAll(actualOngoingSessions);
assertEquals(expectedUniqueOngoingSessions, actualUniqueOngoingSessions);
}

@Test
public void testSoftDeleteFeedbackSession()
throws EntityAlreadyExistsException, InvalidParametersException, EntityDoesNotExistException {
Expand Down
14 changes: 10 additions & 4 deletions src/it/java/teammates/it/storage/sqlsearch/InstructorSearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void allTests() throws Exception {
Instructor insInUnregCourse = typicalBundle.instructors.get("instructorOfUnregisteredCourse");
Instructor insUniqueDisplayName = typicalBundle.instructors.get("instructorOfCourse2WithUniqueDisplayName");
Instructor ins1InCourse3 = typicalBundle.instructors.get("instructor1OfCourse3");
Instructor unregisteredInsInCourse1 = typicalBundle.instructors.get("unregisteredInstructorOfCourse1");

______TS("success: search for instructors in whole system; query string does not match anyone");

Expand Down Expand Up @@ -80,12 +81,12 @@ public void allTests() throws Exception {
______TS("success: search for instructors in whole system; instructors should be searchable by course id");

results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, ins1InCourse1, ins2InCourse1);
verifySearchResults(results, ins1InCourse1, ins2InCourse1, unregisteredInsInCourse1);

______TS("success: search for instructors in whole system; instructors should be searchable by course name");

results = usersDb.searchInstructorsInWholeSystem("\"Typical Course 1\"");
verifySearchResults(results, ins1InCourse1, ins2InCourse1);
verifySearchResults(results, ins1InCourse1, ins2InCourse1, unregisteredInsInCourse1);

______TS("success: search for instructors in whole system; instructors should be searchable by their name");

Expand Down Expand Up @@ -136,17 +137,22 @@ public void testSearchInstructor_deleteAfterSearch_shouldNotBeSearchable() throw

Instructor ins1InCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
Instructor ins2InCourse1 = typicalBundle.instructors.get("instructor2OfCourse1");
Instructor unregisteredInsInCourse1 = typicalBundle.instructors.get("unregisteredInstructorOfCourse1");

List<Instructor> results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, ins1InCourse1, ins2InCourse1);
verifySearchResults(results, ins1InCourse1, ins2InCourse1, unregisteredInsInCourse1);

usersDb.deleteUser(ins1InCourse1);
results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, ins2InCourse1);
verifySearchResults(results, ins2InCourse1, unregisteredInsInCourse1);

// This used to test .deleteInstructors, but we don't seem to have a similar method to delete all users in course
usersDb.deleteUser(ins2InCourse1);
results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, unregisteredInsInCourse1);

usersDb.deleteUser(unregisteredInsInCourse1);
results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ private BaseEntity getEntity(BaseEntity entity) {
return logic.getAccount(((Account) entity).getId());
} else if (entity instanceof Notification) {
return logic.getNotification(((Notification) entity).getId());
} else if (entity instanceof AccountRequest) {
AccountRequest accountRequest = (AccountRequest) entity;
return logic.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute());
} else {
throw new RuntimeException("Unknown entity type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ protected void testExecute() throws Exception {
Instructor instructor = typicalBundle.instructors.get("instructor1OfCourse1");
String courseId = instructor.getCourseId();
// TODO Remove limit after migration completes
int deleteLimit = 3;
int deleteLimit = 4;

______TS("Typical Success Case delete a limited number of students");
loginAsInstructor(instructor.getGoogleId());

List<Student> studentsToDelete = logic.getStudentsForCourse(courseId);

assertEquals(3, studentsToDelete.size());
assertEquals(4, studentsToDelete.size());

String[] params = new String[] {
Const.ParamsNames.COURSE_ID, courseId,
Expand All @@ -59,7 +59,7 @@ protected void testExecute() throws Exception {
getJsonResult(deleteStudentsAction);

for (Student student : studentsToDelete) {
assertNull(logic.getStudentByGoogleId(courseId, student.getGoogleId()));
assertNull(logic.getStudentByRegistrationKey(student.getRegKey()));
}

______TS("Random course given, fails silently");
Expand Down
Loading

0 comments on commit ed81535

Please sign in to comment.