+
-
+
@@ -140,12 +136,14 @@
width: auto !important;
}
}
+
.mailto {
text-decoration: none;
width: 200px;
font-size: 0.8rem;
color: #555555;
}
+
.mail {
width: 100%;
text-align: center;
@@ -165,7 +163,8 @@
-
+
-
+
+
-
+
@@ -140,12 +136,14 @@
width: auto !important;
}
}
+
.mailto {
text-decoration: none;
width: 200px;
font-size: 0.8rem;
color: #555555;
}
+
.mail {
width: 100%;
text-align: center;
@@ -165,7 +163,8 @@
-
+
-
+
+
assertTrue(result.getResolvedException() instanceof ResponseStatusException))
+ result -> assertTrue(result.getResolvedException() instanceof ResponseStatusException))
// The exception message in ResponseStatusException includes the status code and error type so it has to be added to expected message
.andExpect(result -> assertEquals("418 I_AM_A_TEAPOT \"" + customMessage + "\"",
result.getResolvedException().getMessage()));
@@ -82,10 +82,10 @@ void handleResourceNotFoundCustom() throws Exception
String exceptionName = "ResourceNotFoundException";
String customMessage = "Failed to find a resource";
mvc.perform(post("/exception").contentType(MediaType.APPLICATION_JSON)
- .param("exceptionName", exceptionName).param("customMessage", customMessage))
+ .param("exceptionName", exceptionName).param("customMessage", customMessage))
.andExpect(status().isNotFound()).andExpect(result -> assertTrue(
- result.getResolvedException() instanceof ResourceNotFoundException)).andExpect(
- result -> assertEquals(customMessage, result.getResolvedException().getMessage()));
+ result.getResolvedException() instanceof ResourceNotFoundException)).andExpect(
+ result -> assertEquals(customMessage, result.getResolvedException().getMessage()));
}
}
diff --git a/apps/api/src/test/java/dk/treecreate/api/healthcheck/HealthcheckTests.java b/apps/api/src/test/java/dk/treecreate/api/healthcheck/HealthcheckTests.java
index 2a5841531..68d7dc881 100644
--- a/apps/api/src/test/java/dk/treecreate/api/healthcheck/HealthcheckTests.java
+++ b/apps/api/src/test/java/dk/treecreate/api/healthcheck/HealthcheckTests.java
@@ -25,21 +25,17 @@
class HealthcheckTests
{
+ @MockBean
+ CustomPropertiesConfig customProperties;
@Autowired
private MockMvc mvc;
-
@MockBean
private UserDetailsServiceImpl userDetailsService;
-
@MockBean
private AuthEntryPointJwt authEntryPointJwt;
-
@MockBean
private JwtUtils jwtUtils;
- @MockBean
- CustomPropertiesConfig customProperties;
-
@Test // MockMvc throws Exception, so i must catch it
void healthcheckReturnedStatusTest() throws Exception
{
@@ -53,8 +49,8 @@ void healthcheckBodyTest() throws Exception
Mockito.when(customProperties.getEnvironment()).thenReturn(Environment.STAGING);
mvc.perform(get("/healthcheck")
- // Ensure it is a Json
- .contentType(MediaType.APPLICATION_JSON))
+ // Ensure it is a Json
+ .contentType(MediaType.APPLICATION_JSON))
// Check the contents of the body.
.andExpect(jsonPath("status", is("OK")))
.andExpect(jsonPath("message", is("Server is live")))
diff --git a/apps/api/src/test/java/dk/treecreate/api/mail/MailControllerTest.java b/apps/api/src/test/java/dk/treecreate/api/mail/MailControllerTest.java
index 55a265c5a..6d3444875 100644
--- a/apps/api/src/test/java/dk/treecreate/api/mail/MailControllerTest.java
+++ b/apps/api/src/test/java/dk/treecreate/api/mail/MailControllerTest.java
@@ -127,7 +127,7 @@ void signupMessageBadRequest() throws Exception
Mockito.when(mailService.isValidEmail(email)).thenReturn(false);
mvc.perform(post("/mail/signup").content(TestUtilsService.asJsonString(params))
- .contentType(MediaType.APPLICATION_JSON))
+ .contentType(MediaType.APPLICATION_JSON))
// the message comes from a ResponseStatusException so has to be handled differently from normal content
.andExpect(result -> assertEquals("Provided email is not a valid email",
result.getResponse().getErrorMessage()));
@@ -147,7 +147,7 @@ void signupMessageException() throws Exception
.sendSignupEmail(anyString(), any(UUID.class), any(Locale.class));
mvc.perform(post("/mail/signup").content(TestUtilsService.asJsonString(params))
- .contentType(MediaType.APPLICATION_JSON))
+ .contentType(MediaType.APPLICATION_JSON))
// the message comes from a ResponseStatusException so has to be handled differently from normal content
.andExpect(result -> assertEquals("Failed to send an email",
result.getResponse().getErrorMessage()));
diff --git a/apps/api/src/test/java/dk/treecreate/api/order/OrderServiceTest.java b/apps/api/src/test/java/dk/treecreate/api/order/OrderServiceTest.java
index 2df2b08d5..f42519332 100644
--- a/apps/api/src/test/java/dk/treecreate/api/order/OrderServiceTest.java
+++ b/apps/api/src/test/java/dk/treecreate/api/order/OrderServiceTest.java
@@ -5,25 +5,39 @@
import dk.treecreate.api.designs.DesignType;
import dk.treecreate.api.discount.Discount;
import dk.treecreate.api.discount.DiscountType;
+import dk.treecreate.api.exceptionhandling.ResourceNotFoundException;
import dk.treecreate.api.transactionitem.TransactionItem;
+import dk.treecreate.api.utils.OrderStatus;
import dk.treecreate.api.utils.model.quickpay.ShippingMethod;
import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.web.server.ResponseStatusException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
+@SpringBootTest
class OrderServiceTest
{
- OrderService orderService = new OrderService();
+ @Autowired
+ OrderService orderService;
+
+ @MockBean
+ OrderRepository orderRepository;
private static Stream verifyPriceArguments()
{
@@ -85,7 +99,8 @@ private static Stream verifyPriceArguments()
DiscountType.PERCENT, 69,
DesignDimension.LARGE, 69, DesignType.FAMILY_TREE, ShippingMethod.PICK_UP_POINT,
null),
- // Discount - percent. Shipping - own delivery. Off number resulting in a complex floating point
+ // Discount - percent. Shipping - own delivery. Off number resulting in a
+ // complex floating point
Arguments.of(69, new BigDecimal(4737195), new BigDecimal("1469310.45"), 69,
DiscountType.PERCENT, 69,
DesignDimension.LARGE, 69, DesignType.FAMILY_TREE, ShippingMethod.OWN_DELIVERY,
@@ -154,6 +169,29 @@ private static Stream verifyPriceArguments()
"dimension data is not valid"));
}
+ private static Stream calculateTotalArguments()
+ {
+ return Stream.of(
+ Arguments.of(new BigDecimal(495), 100, DiscountType.AMOUNT, false,
+ new BigDecimal("395.00"), null),
+ Arguments.of(new BigDecimal(495), 100, DiscountType.PERCENT, false,
+ new BigDecimal("0.00"), null),
+ Arguments.of(new BigDecimal(495), 50, DiscountType.PERCENT, false,
+ new BigDecimal("247.50"), null),
+ Arguments.of(new BigDecimal(495), 0, null, false, new BigDecimal("495.00"), null),
+ Arguments.of(new BigDecimal(495), 0, null, true, new BigDecimal("371.25"), null));
+ }
+
+ private static Stream pricePerItemArguments()
+ {
+ return Stream.of(
+ Arguments.of(DesignType.FAMILY_TREE, DesignDimension.SMALL, new BigDecimal(495), null),
+ Arguments.of(DesignType.FAMILY_TREE, DesignDimension.MEDIUM, new BigDecimal(695), null),
+ Arguments.of(DesignType.FAMILY_TREE, DesignDimension.LARGE, new BigDecimal(995), null),
+ Arguments.of(DesignType.FAMILY_TREE, DesignDimension.ONE_SIZE, null,
+ "dimension data is not valid"));
+ }
+
@ParameterizedTest
@MethodSource("verifyPriceArguments")
@DisplayName("verifyPrice() correctly validates pricing information")
@@ -206,20 +244,6 @@ void verifyPrice(int plantedTrees, BigDecimal total, BigDecimal subTotal, int di
}
}
- private static Stream calculateTotalArguments()
- {
- return Stream.of(
- Arguments.of(new BigDecimal(495), 100, DiscountType.AMOUNT, false,
- new BigDecimal("395.00"), null),
- Arguments.of(new BigDecimal(495), 100, DiscountType.PERCENT, false,
- new BigDecimal("0.00"), null),
- Arguments.of(new BigDecimal(495), 50, DiscountType.PERCENT, false,
- new BigDecimal("247.50"), null),
- Arguments.of(new BigDecimal(495), 0, null, false, new BigDecimal("495.00"), null),
- Arguments.of(new BigDecimal(495), 0, null, true, new BigDecimal("371.25"), null)
- );
- }
-
@ParameterizedTest
@MethodSource("calculateTotalArguments")
@DisplayName("calculateTotal() correctly applies discounts to the subtotal")
@@ -254,24 +278,14 @@ void calculateTotal(BigDecimal subTotal, int discountAmount, DiscountType discou
}
}
- private static Stream pricePerItemArguments()
- {
- return Stream.of(
- Arguments.of(DesignType.FAMILY_TREE, DesignDimension.SMALL, new BigDecimal(495), null),
- Arguments.of(DesignType.FAMILY_TREE, DesignDimension.MEDIUM, new BigDecimal(695), null),
- Arguments.of(DesignType.FAMILY_TREE, DesignDimension.LARGE, new BigDecimal(995), null),
- Arguments.of(DesignType.FAMILY_TREE, DesignDimension.ONE_SIZE, null,
- "dimension data is not valid")
- );
- }
-
@ParameterizedTest
@MethodSource("pricePerItemArguments")
@DisplayName("pricePerItem() correctly returns price based on design type and dimensions")
void pricePerItem(DesignType designType, DesignDimension designDimension,
BigDecimal expectedPrice, String exceptionMessageSnippet)
{
- // there is no point testing the default options sine they are impossible to each as of now (there are not enum values not covered by the switches)
+ // there is no point testing the default options sine they are impossible to
+ // each as of now (there are not enum values not covered by the switches)
if (expectedPrice != null)
{
assertEquals(orderService.pricePerItem(designType, designDimension), expectedPrice);
@@ -283,4 +297,42 @@ void pricePerItem(DesignType designType, DesignDimension designDimension,
assertThat(exception.getMessage()).contains(exceptionMessageSnippet);
}
}
+
+ @Test
+ @DisplayName("updateOrderStatus() correctly updates the status of the order")
+ void updateOrderStatus()
+ {
+ // prepare the order
+ UUID orderId = UUID.fromString("c0a80121-7adb-10c0-817a-dbc2f0ec1234");
+ OrderStatus status = OrderStatus.ASSEMBLING;
+ OrderStatus newStatus = OrderStatus.NEW;
+
+ Order order = new Order();
+ Order newOrder = new Order();
+
+ order.setOrderId(orderId);
+ order.setStatus(status);
+
+ newOrder.setOrderId(orderId);
+ newOrder.setStatus(status);
+
+
+ Mockito.when(orderRepository.findByOrderId(orderId)).thenReturn(Optional.of(order));
+ Mockito.when(orderRepository.save(order)).thenReturn(newOrder);
+
+ assertEquals(newOrder, orderService.updateOrderStatus(orderId, newStatus));
+ }
+
+ @Test
+ @DisplayName("updateOrderStatus() throws ResourceNotFoundException if no order is found")
+ void updateOrderStatusNotFound()
+ {
+ UUID orderId = UUID.fromString("c0a80121-7adb-10c0-817a-dbc2f0ec1234");
+ OrderStatus status = OrderStatus.ASSEMBLING;
+
+ Mockito.when(orderRepository.findByOrderId(orderId)).thenReturn(Optional.empty());
+
+ assertThrows(ResourceNotFoundException.class,
+ () -> orderService.updateOrderStatus(orderId, status));
+ }
}
diff --git a/apps/api/src/test/java/dk/treecreate/api/users/UserControllerTests.java b/apps/api/src/test/java/dk/treecreate/api/users/UserControllerTests.java
index 67f5b5e29..6064f7fda 100644
--- a/apps/api/src/test/java/dk/treecreate/api/users/UserControllerTests.java
+++ b/apps/api/src/test/java/dk/treecreate/api/users/UserControllerTests.java
@@ -219,8 +219,8 @@ void updateCurrentUserReturnsUpdatedUser() throws Exception
Mockito.when(userRepository.save(user)).thenReturn(user);
mvc.perform(put("/users")
- .contentType(MediaType.APPLICATION_JSON)
- .content(TestUtilsService.asJsonString(updateUserRequest)))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(TestUtilsService.asJsonString(updateUserRequest)))
.andExpect(status().isOk())
.andExpect(content().json(TestUtilsService.asJsonString(user)));
}
@@ -246,8 +246,8 @@ void updateUserReturnsUpdatedUser() throws Exception
Mockito.when(userRepository.save(user)).thenReturn(user);
mvc.perform(put("/users/" + userId)
- .contentType(MediaType.APPLICATION_JSON)
- .content(TestUtilsService.asJsonString(updateUserRequest)))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(TestUtilsService.asJsonString(updateUserRequest)))
.andExpect(status().isOk())
.andExpect(content().json(TestUtilsService.asJsonString(user)));
}
@@ -265,8 +265,8 @@ void updateUserWithInvalidEmailReturnsBadRequest() throws Exception
updateUserRequest.setEmail("invalid format");
mvc.perform(put("/users")
- .contentType(MediaType.APPLICATION_JSON)
- .content(TestUtilsService.asJsonString(updateUserRequest)))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(TestUtilsService.asJsonString(updateUserRequest)))
.andExpect(status().isBadRequest());
}
@@ -291,8 +291,8 @@ void updateUserWithDuplicateEmailReturnsBadRequest() throws Exception
.thenReturn(true);
mvc.perform(put("/users/" + userId)
- .contentType(MediaType.APPLICATION_JSON)
- .content(TestUtilsService.asJsonString(updateUserRequest)))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(TestUtilsService.asJsonString(updateUserRequest)))
.andExpect(status().isBadRequest());
}
@@ -309,8 +309,8 @@ void updateUserWithTooLongEntryReturnsBadRequest()
updateUserRequest.setPhoneNumber("12345678901234567890"); // the limit is 15
mvc.perform(put("/users/" + userId)
- .contentType(MediaType.APPLICATION_JSON)
- .content(TestUtilsService.asJsonString(updateUserRequest)))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(TestUtilsService.asJsonString(updateUserRequest)))
.andExpect(status().isBadRequest());
}
}
diff --git a/apps/api/src/test/java/dk/treecreate/api/utils/LinkServiceTest.java b/apps/api/src/test/java/dk/treecreate/api/utils/LinkServiceTest.java
index 49bdbe80d..c82fe747b 100644
--- a/apps/api/src/test/java/dk/treecreate/api/utils/LinkServiceTest.java
+++ b/apps/api/src/test/java/dk/treecreate/api/utils/LinkServiceTest.java
@@ -53,18 +53,6 @@ private static Stream generatePaymentRedirectUrlArguments()
"https://treecreate.dk/dk/payment/cancelled"));
}
- @ParameterizedTest
- @MethodSource("generatePaymentRedirectUrlArguments")
- @DisplayName("generatePaymentRedirectUrl() returns a correctly structured redirect url")
- void generatePaymentRedirectUrl(Environment environment, Locale locale,
- boolean successLink, String expectedUrl)
- {
- Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
-
- assertEquals(linkService.generatePaymentRedirectUrl(locale, successLink),
- expectedUrl);
- }
-
private static Stream generateCallbackUrlArguments()
{
return Stream.of(
@@ -76,16 +64,6 @@ private static Stream generateCallbackUrlArguments()
"https://api.treecreate.dk/paymentCallback"));
}
- @ParameterizedTest
- @MethodSource("generateCallbackUrlArguments")
- @DisplayName("generateCallbackUrl() returns a correctly structured callback url")
- void generateCallbackUrl(Environment environment, String expectedUrl)
- {
- Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
-
- assertEquals(linkService.generateCallbackUrl(), expectedUrl);
- }
-
private static Stream generateVerificationLinkArguments()
{
return Stream.of(
@@ -103,18 +81,6 @@ private static Stream generateVerificationLinkArguments()
"https://treecreate.dk/dk/verification/00000000-0000-0000-0000-000000000000"));
}
- @ParameterizedTest
- @MethodSource("generateVerificationLinkArguments")
- @DisplayName("generateVerificationLink() returns a correctly structured verification link")
- void generateVerificationLink(UUID token, Locale locale, Environment environment,
- String expectedUrl)
- {
- Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
-
- assertEquals(linkService.generateVerificationLink(token, locale),
- expectedUrl);
- }
-
private static Stream generateResetPasswordLinkArguments()
{
return Stream.of(
@@ -132,18 +98,6 @@ private static Stream generateResetPasswordLinkArguments()
"https://treecreate.dk/dk/resetPassword/00000000-0000-0000-0000-000000000000"));
}
- @ParameterizedTest
- @MethodSource("generateResetPasswordLinkArguments")
- @DisplayName("generateResetPasswordLink() returns a correctly structured reset password link")
- void generateResetPasswordLink(UUID token, Locale locale, Environment environment,
- String expectedUrl)
- {
- Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
-
- assertEquals(linkService.generateResetPasswordLink(token, locale),
- expectedUrl);
- }
-
private static Stream generateNewsletterUnsubscribeLinkArguments()
{
return Stream.of(
@@ -161,6 +115,52 @@ private static Stream generateNewsletterUnsubscribeLinkArguments()
"https://treecreate.dk/dk/newsletter/unsubscribe/00000000-0000-0000-0000-000000000000"));
}
+ @ParameterizedTest
+ @MethodSource("generatePaymentRedirectUrlArguments")
+ @DisplayName("generatePaymentRedirectUrl() returns a correctly structured redirect url")
+ void generatePaymentRedirectUrl(Environment environment, Locale locale,
+ boolean successLink, String expectedUrl)
+ {
+ Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
+
+ assertEquals(linkService.generatePaymentRedirectUrl(locale, successLink),
+ expectedUrl);
+ }
+
+ @ParameterizedTest
+ @MethodSource("generateCallbackUrlArguments")
+ @DisplayName("generateCallbackUrl() returns a correctly structured callback url")
+ void generateCallbackUrl(Environment environment, String expectedUrl)
+ {
+ Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
+
+ assertEquals(linkService.generateCallbackUrl(), expectedUrl);
+ }
+
+ @ParameterizedTest
+ @MethodSource("generateVerificationLinkArguments")
+ @DisplayName("generateVerificationLink() returns a correctly structured verification link")
+ void generateVerificationLink(UUID token, Locale locale, Environment environment,
+ String expectedUrl)
+ {
+ Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
+
+ assertEquals(linkService.generateVerificationLink(token, locale),
+ expectedUrl);
+ }
+
+ @ParameterizedTest
+ @MethodSource("generateResetPasswordLinkArguments")
+ @DisplayName("generateResetPasswordLink() returns a correctly structured reset password link")
+ void generateResetPasswordLink(UUID token, Locale locale, Environment environment,
+ String expectedUrl)
+ {
+ Mockito.when(customProperties.getEnvironment()).thenReturn(environment);
+
+ assertEquals(linkService.generateResetPasswordLink(token, locale),
+ expectedUrl);
+ }
+
@ParameterizedTest
@MethodSource("generateNewsletterUnsubscribeLinkArguments")
@DisplayName(
| | |