-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 tests for GetReadNotificationsActionTest #13220
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package teammates.sqlui.webapi; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.attributes.InstructorAttributes; | ||
import teammates.common.datatransfer.attributes.NotificationAttributes; | ||
import teammates.common.util.Const; | ||
import teammates.storage.sqlentity.Notification; | ||
import teammates.ui.output.ReadNotificationsData; | ||
import teammates.ui.webapi.GetReadNotificationsAction; | ||
import teammates.ui.webapi.JsonResult; | ||
|
||
/** | ||
* SUT: {@link GetReadNotificationsAction}. | ||
*/ | ||
public class GetReadNotificationsActionTest extends BaseActionTest<GetReadNotificationsAction> { | ||
|
||
@Override | ||
String getActionUri() { | ||
return Const.ResourceURIs.NOTIFICATION_READ; | ||
} | ||
|
||
@Override | ||
String getRequestMethod() { | ||
return GET; | ||
} | ||
|
||
@Test | ||
protected void testExecute_getReadNotificationsAsInstructor_shouldSucceed() { | ||
InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
loginAsInstructor(instructor.getGoogleId()); | ||
|
||
List<NotificationAttributes> notificationAttributesList = List.of( | ||
typicalBundle.notifications.get("notification1"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should typicalBundle be used here as well? This seems related to the previous comment. |
||
typicalBundle.notifications.get("notification3")); | ||
List<Notification> testNotifications = new ArrayList<>(); | ||
for (NotificationAttributes notificationAttributes : notificationAttributesList) { | ||
testNotifications.add(new Notification( | ||
notificationAttributes.getStartTime(), | ||
notificationAttributes.getEndTime(), | ||
notificationAttributes.getStyle(), | ||
notificationAttributes.getTargetUser(), | ||
notificationAttributes.getTitle(), | ||
notificationAttributes.getMessage())); | ||
} | ||
List<UUID> testNotificationIds = testNotifications.stream().map(Notification::getId).collect(Collectors.toList()); | ||
when(mockLogic.getReadNotificationsId(instructor.getGoogleId())).thenReturn(testNotificationIds); | ||
|
||
GetReadNotificationsAction action = getAction(); | ||
JsonResult jsonResult = getJsonResult(action); | ||
|
||
ReadNotificationsData output = (ReadNotificationsData) jsonResult.getOutput(); | ||
|
||
List<String> readNotificationsData = output.getReadNotifications(); | ||
|
||
readNotificationsData.forEach(notificationId -> | ||
assertTrue(testNotificationIds.contains(UUID.fromString(notificationId)))); | ||
assertEquals(2, readNotificationsData.size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside from a few minor nits mentioned, the code is well-structured and effectively accomplishes its purpose! |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
typicalBundle.instructors.get("instructor1OfCourse1")
is related to the Google Datastore pre-migration. Would it be better to create the InstructorStub manually instead?