-
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
[#11572] Notification: GET API test and access control #11648
[#11572] Notification: GET API test and access control #11648
Conversation
cd49a85
to
43fa06b
Compare
5a33221
to
2d962e6
Compare
2d962e6
to
8e13258
Compare
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.
Good test coverage!
src/test/java/teammates/ui/webapi/GetNotificationActionTest.java
Outdated
Show resolved
Hide resolved
______TS("Request to fetch notification"); | ||
int expectedNumberOfNotifications = 4; | ||
InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1"); |
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.
The expected number of active notifications here is dependent on the current time, we are in 2022 but two years later the end time for some of these notifications e.g. notification-4
would have passed, then this test will fail 😄 .
"notification-4": {
"notificationId": "notification-4",
"startTime": "2011-04-04T00:00:00Z",
"endTime": "2024-04-04T00:00:00Z",
"createdAt": "2011-01-01T00:00:00Z",
"updatedAt": "2011-01-01T00:00:00Z",
"type": "MAINTENANCE",
"targetUser": "GENERAL",
"title": "The note of maintenance",
"message": "The content of maintenance",
"shown": false
},
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.
Would it be okay if I change the endtime to for example 2099?
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.
Would it be okay if I change the endtime to for example 2099?
This has been updated in the newly pushed code. Thank you!
src/test/java/teammates/ui/webapi/GetNotificationActionTest.java
Outdated
Show resolved
Hide resolved
src/test/java/teammates/ui/webapi/GetNotificationActionTest.java
Outdated
Show resolved
Hide resolved
private static final Instant STARTTIME_ONE = Instant.now().plusSeconds(3600); | ||
private static final Instant ENDTIME_ONE = Instant.now().plusSeconds(7200); | ||
private static final Instant STARTTIME_TWO = Instant.now().plusSeconds(1000); | ||
private static final Instant ENDTIME_TWO = Instant.now().plusSeconds(10000); | ||
|
||
@Test | ||
public void testValueOf_withAllFieldPopulatedNotificationAttributes_shouldGenerateAttributesCorrectly() { | ||
Notification notification = new Notification("valid-notification-id", | ||
STARTTIME_ONE, ENDTIME_ONE, | ||
NotificationType.DEPRECATION, NotificationTargetUser.INSTRUCTOR, | ||
"valid notification title", "valid notification message", false, | ||
Instant.now(), Instant.now()); |
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.
If these data are going to be used frequently across different tests, you may want to use a helper method like generateTypicalNotificationAttributesObject
to generate a NotificationAttributes
object for you and reuse them across tests.
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.
The builder might have slight variations in certain fields and in numbers of fields. If we abstract a method out for that, my concern is it will become just a wrapper around the builder, which might not be necessary.
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.
Yes, for cases where we need to test with different values we can build the NotificationAttributes
separately, but for typical NotificationAttributes
we can use a helper method method like generateTypicalNotificationAttributesObject
to improve readability.
I have highlighted a few examples below, there are many others places where we can simply call generateTypicalNotificationAttributesObject
to generate a default NotificationAttributes
for us.
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.
Thank you for the suggestion! I have changed accordingly in the new commit.
src/test/java/teammates/common/datatransfer/attributes/NotificationAttributesTest.java
Outdated
Show resolved
Hide resolved
src/test/java/teammates/common/datatransfer/attributes/NotificationAttributesTest.java
Outdated
Show resolved
Hide resolved
src/test/java/teammates/common/datatransfer/attributes/NotificationAttributesTest.java
Outdated
Show resolved
Hide resolved
src/test/java/teammates/common/datatransfer/attributes/NotificationAttributesTest.java
Outdated
Show resolved
Hide resolved
@jianhandev In the new commit, I add methods in |
String notificationType = "invalid type"; | ||
assertEquals("\"invalid type\" is not an accepted notification type to TEAMMATES. ", | ||
FieldValidator.getInvalidityInfoForNotificationType(notificationType)); |
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.
String notificationType = "invalid type"; | |
assertEquals("\"invalid type\" is not an accepted notification type to TEAMMATES. ", | |
FieldValidator.getInvalidityInfoForNotificationType(notificationType)); | |
String notificationType = "invalid type"; | |
assertEquals(notificationType + " is not an accepted notification type to TEAMMATES. ", | |
FieldValidator.getInvalidityInfoForNotificationType(notificationType)); |
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.
The error messages have double quotes around the variable. So we might still need to keep the \"
there.
String user = "invalid user"; | ||
assertEquals("\"invalid user\" is not an accepted notification target user to TEAMMATES. ", | ||
FieldValidator.getInvalidityInfoForNotificationTargetUser(user)); |
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.
String user = "invalid user"; | |
assertEquals("\"invalid user\" is not an accepted notification target user to TEAMMATES. ", | |
FieldValidator.getInvalidityInfoForNotificationTargetUser(user)); | |
String invalidUser = "invalid user"; | |
assertEquals(invalidUser + " is not an accepted notification target user to TEAMMATES. ", | |
FieldValidator.getInvalidityInfoForNotificationTargetUser(invalidUser)); |
* Add test for NotificationAttributes * Add notifications to typicalDataBundles and init GET api test * Add tests for GET api * Add access control and its tests for GET api * Update data in dataBundle and add more abstractions * Refactor NotificationAttributesTest and add tests for FieldValidator
* Add test for NotificationAttributes * Add notifications to typicalDataBundles and init GET api test * Add tests for GET api * Add access control and its tests for GET api * Update data in dataBundle and add more abstractions * Refactor NotificationAttributesTest and add tests for FieldValidator
* Add test for NotificationAttributes * Add notifications to typicalDataBundles and init GET api test * Add tests for GET api * Add access control and its tests for GET api * Update data in dataBundle and add more abstractions * Refactor NotificationAttributesTest and add tests for FieldValidator
* Add test for NotificationAttributes * Add notifications to typicalDataBundles and init GET api test * Add tests for GET api * Add access control and its tests for GET api * Update data in dataBundle and add more abstractions * Refactor NotificationAttributesTest and add tests for FieldValidator
* Add test for NotificationAttributes * Add notifications to typicalDataBundles and init GET api test * Add tests for GET api * Add access control and its tests for GET api * Update data in dataBundle and add more abstractions * Refactor NotificationAttributesTest and add tests for FieldValidator
* Add test for NotificationAttributes * Add notifications to typicalDataBundles and init GET api test * Add tests for GET api * Add access control and its tests for GET api * Update data in dataBundle and add more abstractions * Refactor NotificationAttributesTest and add tests for FieldValidator
Part of #11572
Outline of Solution
NotificationAttributes
Has not include:
isfetchingall
related feature / tests.