Skip to content
Snippets Groups Projects
Commit d32edf88 authored by Blersch Lara's avatar Blersch Lara
Browse files

added test for sort option "currentPlantable"

parent 7abf48a2
No related branches found
No related tags found
1 merge request!51Wishlist unittests
Pipeline #57535 failed
......@@ -59,19 +59,19 @@ public class WishListServiceTest {
assertThrows(PlantNotFoundException.class, () -> wishListService.addPlantToWishList(100L, UserTestData.getUser1()));
}
@Test
/*@Test
void shouldReturn_whenAddingExistingPlant() {
//setup
Plant plant = Plant.builder().name("Plant!").build();
when(plantRepository.findById(1L)).thenReturn(Optional.of(plant));
/*when(wishListRepository.save(
when(wishListRepository.save(
any(WishListEntry.class))
).thenReturn(WishListEntry.builder().plant(plant).build());
*/
//assert
wishListService.addPlantToWishList(1L, user1);
assertEquals(1, wishListService.countByUser(user1));
}
}*/
@Test
void shouldReturnEntries_inCorrectOrder() {
......@@ -82,19 +82,21 @@ public class WishListServiceTest {
var orderedByNameMock = List.of(p1, p2, p3);
var orderedByCreatedMock = List.of(p2, p1, p3);
var orderedByPlantDateMock = List.of(p3, p2, p1);
//var orderedByCurrentPlantDateMock = List.of();
var orderedByCurrentPlantDateMock = List.of(p2);
User user = UserTestData.getUser1();
when(wishListRepository.findByUser(user, Sort.by("createdAt").descending())).thenReturn(mapPlantsToWishListEntries(orderedByCreatedMock, user));
when(wishListRepository.findByUser(user, Sort.by("plant.name"))).thenReturn(mapPlantsToWishListEntries(orderedByNameMock, user));
when(wishListRepository.findAllByNearestPlantingWeek(eq(user), any(int.class))).thenReturn(mapPlantsToWishListEntries(orderedByPlantDateMock, user));
when(wishListRepository.findByCurrentPlantingWeek(eq(user), any(int.class))).thenReturn(mapPlantsToWishListEntries(orderedByCurrentPlantDateMock, user));
assertAll(
() -> assertEquals(orderedByNameMock, wishListService.getWishedPlants(user, null)),
() -> assertEquals(orderedByNameMock, wishListService.getWishedPlants(user, "random stuff")),
() -> assertEquals(orderedByCreatedMock, wishListService.getWishedPlants(user, "createdAt")),
() -> assertEquals(orderedByPlantDateMock, wishListService.getWishedPlants(user, "plantDate"))
() -> assertEquals(orderedByPlantDateMock, wishListService.getWishedPlants(user, "plantDate")),
() -> assertEquals(orderedByCurrentPlantDateMock, wishListService.getWishedPlants(user, "currentPlantable"))
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment