Skip to content

Commit

Permalink
Merge branch 'master' into branch-migrate-tests-week3
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanxi1 authored Feb 18, 2025
2 parents 645e6ac + 3e47152 commit b09a53e
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions src/test/java/teammates/sqlui/webapi/DeleteNotificationActionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package teammates.sqlui.webapi;

import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;

import java.time.Instant;
import java.util.UUID;

import org.testng.annotations.Test;

import teammates.common.datatransfer.NotificationStyle;
import teammates.common.datatransfer.NotificationTargetUser;
import teammates.common.util.Const;
import teammates.storage.sqlentity.Notification;
import teammates.ui.output.MessageOutput;
import teammates.ui.webapi.DeleteNotificationAction;

/**
* SUT: {@link DeleteNotificationAction}.
*/
public class DeleteNotificationActionTest extends BaseActionTest<DeleteNotificationAction> {
private static final String GOOGLE_ID = "user-googleId";

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

@Override
String getRequestMethod() {
return DELETE;
}

@Test
void testSpecificAccessControl_admin_canAccess() {
loginAsAdmin();
verifyCanAccess();
}

@Test
void testSpecificAccessControl_instructor_cannotAccess() {
loginAsInstructor(GOOGLE_ID);
verifyCannotAccess();
}

@Test
void testSpecificAccessControl_student_cannotAccess() {
loginAsStudent(GOOGLE_ID);
verifyCannotAccess();
}

@Test
void testSpecificAccessControl_loggedOut_cannotAccess() {
logoutUser();
verifyCannotAccess();
}

@Test
void testExecute_notificationExists_success() {
Notification testNotification = new Notification(
Instant.now(),
Instant.ofEpochMilli(Instant.now().toEpochMilli() + 10000),
NotificationStyle.INFO,
NotificationTargetUser.GENERAL,
"title",
"message");

when(mockLogic.getNotification(testNotification.getId())).thenReturn(testNotification);

String[] params = {
Const.ParamsNames.NOTIFICATION_ID, testNotification.getId().toString(),
};

DeleteNotificationAction action = getAction(params);
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput();

assertEquals("Notification has been deleted.", actionOutput.getMessage());
reset(mockLogic);
}

@Test
void testExecute_notificationDoesNotExist_failSilently() {
UUID invalidUuid = UUID.randomUUID();
when(mockLogic.getNotification(invalidUuid)).thenReturn(null);

String[] params = {
Const.ParamsNames.NOTIFICATION_ID, invalidUuid.toString(),
};

DeleteNotificationAction action = getAction(params);
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput();

assertEquals("Notification has been deleted.", actionOutput.getMessage());
reset(mockLogic);
}

@Test
void testExecute_missingNotificationUuid_throwsInvalidHttpParameterException() {
String[] params = {
Const.ParamsNames.NOTIFICATION_ID, null,
};

verifyHttpParameterFailure(params);
}

@Test
void testExecute_missingParameters_throwsInvalidHttpParameterException() {
String[] params = {};

verifyHttpParameterFailure(params);
}
}

0 comments on commit b09a53e

Please sign in to comment.