Skip to content

Commit

Permalink
feat: add new activites and remove unused ones (#72)
Browse files Browse the repository at this point in the history
* feat: add new activites and remove unused ones

* ci: autogenerated JaCoCo coverage badge

---------

Co-authored-by: Ci Bot <cibot@users.noreply.github.com>
  • Loading branch information
2 people authored and DerekRoberts committed May 14, 2024
1 parent 31e5156 commit 2426334
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/badges/jacoco.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
/** This enumeration contains the SPAR activities. */
@Schema(description = "This enumeration contains the SPAR activities.", type = "string")
public enum ActivityEnum {
SEEDLOT_REGISTRATION,
PARENT_TREE_ORCHARD,
SEEDLING_REQUEST;
CREATE_A_CLASS_SEEDLOT,
EXISTING_SEEDLOTS,
SEEDLOT_DASHBOARD,
SEEDLOT_REGISTRATION;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private FavouriteActivityEntity createEntity(ActivityEnum activityEnum) {
@DisplayName("createFavoriteActivitySuccessTest")
@WithMockUser(roles = "user_write")
void createFavoriteActivitySuccessTest() throws Exception {
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.SEEDLING_REQUEST);
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
when(favouriteActivityService.createUserActivity(any())).thenReturn(activityEntity);

mockMvc
Expand All @@ -88,9 +88,9 @@ void createFavoriteActivitySuccessTest() throws Exception {
.with(csrf().asHeader())
.header(CONTENT_HEADER, JSON)
.accept(MediaType.APPLICATION_JSON)
.content(stringifyCreate(ActivityEnum.SEEDLING_REQUEST)))
.content(stringifyCreate(ActivityEnum.CREATE_A_CLASS_SEEDLOT)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.activity").value(ActivityEnum.SEEDLING_REQUEST.toString()))
.andExpect(jsonPath("$.activity").value(ActivityEnum.CREATE_A_CLASS_SEEDLOT.toString()))
.andExpect(jsonPath("$.highlighted").value("false"))
.andExpect(jsonPath("$.enabled").value("true"))
.andReturn();
Expand Down Expand Up @@ -118,8 +118,8 @@ void createFavoriteActivityNotFoundTest() throws Exception {
@DisplayName("createFavoriteActivityDuplicatedTest")
@WithMockUser(roles = "user_write")
void createFavoriteActivityDuplicatedTest() throws Exception {
String contentString = stringifyCreate(ActivityEnum.SEEDLING_REQUEST);
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.SEEDLING_REQUEST);
String contentString = stringifyCreate(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
when(favouriteActivityService.createUserActivity(any())).thenReturn(activityEntity);

mockMvc
Expand All @@ -130,7 +130,7 @@ void createFavoriteActivityDuplicatedTest() throws Exception {
.accept(MediaType.APPLICATION_JSON)
.content(contentString))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.activity").value(ActivityEnum.SEEDLING_REQUEST.toString()))
.andExpect(jsonPath("$.activity").value(ActivityEnum.CREATE_A_CLASS_SEEDLOT.toString()))
.andExpect(jsonPath("$.highlighted").value("false"))
.andExpect(jsonPath("$.enabled").value("true"))
.andReturn();
Expand All @@ -154,7 +154,7 @@ void createFavoriteActivityDuplicatedTest() throws Exception {
@WithMockUser(roles = "user_write")
void getAllUsersActivityTest() throws Exception {

FavouriteActivityEntity activityEntityOne = createEntity(ActivityEnum.SEEDLING_REQUEST);
FavouriteActivityEntity activityEntityOne = createEntity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
FavouriteActivityEntity activityEntityTwo = createEntity(ActivityEnum.SEEDLOT_REGISTRATION);
activityEntityTwo.setHighlighted(Boolean.TRUE);
List<FavouriteActivityEntity> favoriteActivityEntities =
Expand All @@ -168,7 +168,7 @@ void getAllUsersActivityTest() throws Exception {
.header(CONTENT_HEADER, JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].activity").value(ActivityEnum.SEEDLING_REQUEST.toString()))
.andExpect(jsonPath("$[0].activity").value(ActivityEnum.CREATE_A_CLASS_SEEDLOT.toString()))
.andExpect(jsonPath("$[0].highlighted").value("false"))
.andExpect(jsonPath("$[0].enabled").value("true"))
.andExpect(jsonPath("$[1].activity").value(ActivityEnum.SEEDLOT_REGISTRATION.toString()))
Expand All @@ -181,7 +181,7 @@ void getAllUsersActivityTest() throws Exception {
@DisplayName("updateUserFavoriteActivity")
@WithMockUser(roles = "user_write")
void updateUserFavoriteActivity() throws Exception {
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.PARENT_TREE_ORCHARD);
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.EXISTING_SEEDLOTS);
activityEntity.setId(10000L);
when(favouriteActivityService.createUserActivity(any())).thenReturn(activityEntity);

Expand All @@ -191,9 +191,9 @@ void updateUserFavoriteActivity() throws Exception {
.with(csrf().asHeader())
.header(CONTENT_HEADER, JSON)
.accept(MediaType.APPLICATION_JSON)
.content(stringifyCreate(ActivityEnum.PARENT_TREE_ORCHARD)))
.content(stringifyCreate(ActivityEnum.EXISTING_SEEDLOTS)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.activity").value(ActivityEnum.PARENT_TREE_ORCHARD.toString()))
.andExpect(jsonPath("$.activity").value(ActivityEnum.EXISTING_SEEDLOTS.toString()))
.andExpect(jsonPath("$.highlighted").value("false"))
.andExpect(jsonPath("$.enabled").value("true"))
.andReturn();
Expand All @@ -210,7 +210,7 @@ void updateUserFavoriteActivity() throws Exception {
.accept(MediaType.APPLICATION_JSON)
.content(stringifyUpdate(true, true)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.activity").value(ActivityEnum.PARENT_TREE_ORCHARD.toString()))
.andExpect(jsonPath("$.activity").value(ActivityEnum.EXISTING_SEEDLOTS.toString()))
.andExpect(jsonPath("$.highlighted").value("true"))
.andExpect(jsonPath("$.enabled").value("true"))
.andReturn();
Expand All @@ -220,7 +220,7 @@ void updateUserFavoriteActivity() throws Exception {
@DisplayName("deleteUserFavoriteActivity")
@WithMockUser(roles = "user_write")
void deleteUserFavoriteActivity() throws Exception {
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.PARENT_TREE_ORCHARD);
FavouriteActivityEntity activityEntity = createEntity(ActivityEnum.EXISTING_SEEDLOTS);
activityEntity.setId(10000L);

when(favouriteActivityService.createUserActivity(any())).thenReturn(activityEntity);
Expand All @@ -231,9 +231,9 @@ void deleteUserFavoriteActivity() throws Exception {
.with(csrf().asHeader())
.header(CONTENT_HEADER, JSON)
.accept(MediaType.APPLICATION_JSON)
.content(stringifyCreate(ActivityEnum.PARENT_TREE_ORCHARD)))
.content(stringifyCreate(ActivityEnum.EXISTING_SEEDLOTS)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.activity").value(ActivityEnum.PARENT_TREE_ORCHARD.toString()))
.andExpect(jsonPath("$.activity").value(ActivityEnum.EXISTING_SEEDLOTS.toString()))
.andExpect(jsonPath("$.highlighted").value("false"))
.andExpect(jsonPath("$.enabled").value("true"))
.andReturn();
Expand All @@ -251,5 +251,4 @@ void deleteUserFavoriteActivity() throws Exception {
.andExpect(status().isOk())
.andReturn();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ void createWithDefaultValuesTest() {
void createWithAllValuesTest() {
FavouriteActivityEntity activity = new FavouriteActivityEntity();
activity.setUserId(USER_ID);
activity.setActivity(ActivityEnum.SEEDLING_REQUEST);
activity.setActivity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
activity.setHighlighted(true);
activity.setEnabled(false);
FavouriteActivityEntity created = favouriteActivityRepository.save(activity);

Assertions.assertEquals(ActivityEnum.SEEDLING_REQUEST, created.getActivity());
Assertions.assertEquals(ActivityEnum.CREATE_A_CLASS_SEEDLOT, created.getActivity());
Assertions.assertEquals(USER_ID, created.getUserId());
Assertions.assertTrue(created.getHighlighted());
Assertions.assertFalse(created.getEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.Assert;

@ExtendWith(SpringExtension.class)
class FavouriteActivityServiceTest {
Expand All @@ -47,17 +46,17 @@ void createUserActivityTest() {
when(loggedUserService.getLoggedUserId()).thenReturn(USER_ID);

FavouriteActivityEntity entity = new FavouriteActivityEntity();
entity.setActivity(ActivityEnum.SEEDLING_REQUEST);
entity.setActivity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
entity.setHighlighted(false);
entity.setEnabled(true);
when(favouriteActivityRepository.save(any())).thenReturn(entity);

FavouriteActivityCreateDto createDto =
new FavouriteActivityCreateDto(ActivityEnum.SEEDLING_REQUEST);
new FavouriteActivityCreateDto(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
FavouriteActivityEntity entitySaved = favouriteActivityService.createUserActivity(createDto);

Assertions.assertNotNull(entitySaved);
Assertions.assertEquals(ActivityEnum.SEEDLING_REQUEST, entitySaved.getActivity());
Assertions.assertEquals(ActivityEnum.CREATE_A_CLASS_SEEDLOT, entitySaved.getActivity());
Assertions.assertFalse(entitySaved.getHighlighted());
Assertions.assertTrue(entitySaved.getEnabled());
}
Expand All @@ -68,7 +67,7 @@ void createUserActivityExceptionTest() {
when(loggedUserService.getLoggedUserId()).thenReturn(USER_ID);

FavouriteActivityEntity entity = new FavouriteActivityEntity();
entity.setActivity(ActivityEnum.SEEDLING_REQUEST);
entity.setActivity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
entity.setHighlighted(false);
entity.setEnabled(true);
when(favouriteActivityRepository.save(any())).thenReturn(entity);
Expand All @@ -86,7 +85,7 @@ void createUserActivityExceptionTest() {
when(favouriteActivityRepository.findAllByUserId(any())).thenReturn(userFavList);

FavouriteActivityCreateDto createAnotherDto =
new FavouriteActivityCreateDto(ActivityEnum.SEEDLING_REQUEST);
new FavouriteActivityCreateDto(ActivityEnum.CREATE_A_CLASS_SEEDLOT);

Exception activityExists =
Assertions.assertThrows(
Expand Down Expand Up @@ -122,7 +121,7 @@ void updateUserActivityTest() {
when(loggedUserService.getLoggedUserId()).thenReturn(USER_ID);

FavouriteActivityEntity entity = new FavouriteActivityEntity();
entity.setActivity(ActivityEnum.SEEDLING_REQUEST);
entity.setActivity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
entity.setHighlighted(false);
entity.setEnabled(true);
when(favouriteActivityRepository.findById(any())).thenReturn(Optional.of(entity));
Expand All @@ -141,7 +140,7 @@ void updateUserActivityExceptionTest() {
when(loggedUserService.getLoggedUserId()).thenReturn(USER_ID);

FavouriteActivityEntity entity = new FavouriteActivityEntity();
entity.setActivity(ActivityEnum.SEEDLING_REQUEST);
entity.setActivity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
entity.setHighlighted(false);
entity.setEnabled(true);
when(favouriteActivityRepository.findById(any())).thenReturn(Optional.empty());
Expand All @@ -164,7 +163,7 @@ void deleteUserActivityTest() {
when(loggedUserService.getLoggedUserId()).thenReturn(USER_ID);

FavouriteActivityEntity entity = new FavouriteActivityEntity();
entity.setActivity(ActivityEnum.SEEDLING_REQUEST);
entity.setActivity(ActivityEnum.CREATE_A_CLASS_SEEDLOT);
entity.setHighlighted(false);
entity.setEnabled(true);
when(favouriteActivityRepository.findById(any())).thenReturn(Optional.of(entity));
Expand All @@ -191,8 +190,7 @@ void deleteUserActivityExceptionTest() {

Exception e =
Assertions.assertThrows(
ActivityNotFoundException.class,
() -> favouriteActivityService.deleteUserActivity(1L));
ActivityNotFoundException.class, () -> favouriteActivityService.deleteUserActivity(1L));

Assertions.assertEquals("404 NOT_FOUND \"Activity don't exist!\"", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ INSERT INTO favourite_activity (user_id, activity, highlighted, enabled)
VALUES ('123456789123456789@idir', 'SEEDLOT_REGISTRATION', 0, 1);

INSERT INTO favourite_activity (user_id, activity, highlighted, enabled)
VALUES ('123456789123456789@idir', 'PARENT_TREE_ORCHARD', 0, 1);
VALUES ('123456789123456789@idir', 'EXISTING_SEEDLOTS', 0, 1);

0 comments on commit 2426334

Please sign in to comment.