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 tests for GetReadNotificationsActionTest #13220

Merged
merged 6 commits into from
Feb 27, 2025
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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.util.Const;
import teammates.storage.sqlentity.Instructor;
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> {
/** Number of read notifications used for testing. */
public static final int READ_NOTIFICATION_COUNT = 2;

@Override
String getActionUri() {
return Const.ResourceURIs.NOTIFICATION_READ;
}

@Override
String getRequestMethod() {
return GET;
}

@Test
protected void testExecute_getReadNotificationsAsInstructor_shouldSucceed() {
Instructor instructor = getTypicalInstructor();
List<Notification> testNotifications = new ArrayList<>();

loginAsInstructor(instructor.getGoogleId());
for (int i = 0; i < READ_NOTIFICATION_COUNT; i++) {
testNotifications.add(getTypicalNotificationWithId());
}

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(READ_NOTIFICATION_COUNT, readNotificationsData.size());
}
}
Loading