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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/test/java/teammates/sqlui/webapi/BaseActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;

import teammates.common.datatransfer.DataBundle;
import teammates.common.datatransfer.UserInfo;
import teammates.common.util.Config;
import teammates.common.util.Const;
Expand Down Expand Up @@ -55,6 +56,7 @@ public abstract class BaseActionTest<T extends Action> extends BaseTestCase {
static final String PUT = HttpPut.METHOD_NAME;
static final String DELETE = HttpDelete.METHOD_NAME;

DataBundle typicalBundle = getTypicalDataBundle();
Logic mockLogic = mock(Logic.class);
teammates.logic.api.Logic mockDatastoreLogic = mock(teammates.logic.api.Logic.class);
MockTaskQueuer mockTaskQueuer = new MockTaskQueuer();
Expand Down
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");
Copy link
Contributor

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?

loginAsInstructor(instructor.getGoogleId());

List<NotificationAttributes> notificationAttributesList = List.of(
typicalBundle.notifications.get("notification1"),
Copy link
Contributor

Choose a reason for hiding this comment

The 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());
Copy link
Contributor

Choose a reason for hiding this comment

The 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!

}
}
Loading