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

Add and manage announcements #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add and manage announcements #30

wants to merge 3 commits into from

Conversation

flomillot
Copy link
Contributor

No description provided.

Signed-off-by: Florent MILLOT <millotflo@gmail.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you create AnnouncementController then you can connect AnnoucementController and AnnouncementService directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, cf above

Comment on lines +311 to 328
@Test
void testGetAllMaintenanceMessages() throws Exception {
announcementRepository.save(new AnnouncementEntity("I think dangling line is a funny name for a line", Duration.ofSeconds(60)));
assertEquals(1, announcementRepository.findAll().size());

// Try to retrieve all the messages and expect everything to be ok
MvcResult mvcResult = mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/announcements")
.header("userId", ADMIN_USER))
.andExpect(status().isOk()).andReturn();
List<AnnouncementEntity> announcements = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() {
});
assertEquals(1, announcements.size());

// Try to retrieve all the messages with a user that's not an admin and expect 403 FORBIDDEN
mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/announcements")
.header("userId", NOT_ADMIN))
.andExpect(status().isForbidden());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you separete the tests for OK results and for forbidden ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just updated and completed the test, I prefer to keep them like it was (TL already told me few times to change only the necessary so that's what I do now)

Comment on lines 288 to 309
@Test
public void testCancelMaintenanceMessage() throws Exception {
AnnouncementEntity announcement = announcementRepository.save(new AnnouncementEntity("I think dangling line is a funny name for a line", Duration.ofSeconds(60)));
assertEquals(1, announcementRepository.findAll().size());

//Send a cancel maintenance message and expect everything to be ok
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/messages/cancel-maintenance")
mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + announcement.getId())
.header("userId", ADMIN_USER))
.andExpect(status().isOk());
assertCancelMaintenanceMessageSent();
assertEquals(0, announcementRepository.findAll().size());

// With a non-existing ID, expect 404
mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + UUID.randomUUID())
.header("userId", ADMIN_USER))
.andExpect(status().isNotFound());

//Send a cancel maintenance message with a user that's not an admin and expect 403 FORBIDDEN
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/messages/cancel-maintenance")
mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + UUID.randomUUID())
.header("userId", NOT_ADMIN))
.andExpect(status().isForbidden());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Comment on lines +40 to +44
if (announcement.getDuration() == null) {
notificationService.emitMaintenanceMessage(announcement.getMessage());
} else {
notificationService.emitMaintenanceMessage(announcement.getMessage(), announcement.getDuration().toSeconds());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be handled in the EmitMessage method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have done that also, but it's not a big deal and does not change that much so I kept the existing code

Signed-off-by: Florent MILLOT <millotflo@gmail.com>
Copy link

sonarqubecloud bot commented Apr 3, 2024

Signed-off-by: Abdelsalem <abdelsalem.hedhili@rte-france.com>
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants