From 722f705e2696da1a2dd367e3e6dce14b5d5251e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Sucena=20Lopes?= Date: Sat, 26 Oct 2024 16:17:55 +0100 Subject: [PATCH 1/2] tests: replace hardcoded date with dynamic value --- .../up/fe/ni/website/backend/utils/ValidationTester.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt b/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt index 55c850f4..170980cd 100644 --- a/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt +++ b/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt @@ -1,5 +1,6 @@ package pt.up.fe.ni.website.backend.utils +import java.time.LocalDate import org.springframework.http.MediaType import org.springframework.test.web.servlet.ResultActions import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content @@ -112,13 +113,18 @@ class ValidationTester( } fun isPastDate() { + // get the current date and offset it by 1 day + val tomorrow = LocalDate.now() + .plusDays(1) + .toString() + val params = requiredFields.toMutableMap() - params[param] = "01-01-3000" // TODO: use a date in the future instead of hard coded + params[param] = tomorrow req(params) .expectValidationError() .andExpectAll( jsonPath("$.errors[0].message").value("must be a past date"), - jsonPath("$.errors[0].value").value("01-01-3000") + jsonPath("$.errors[0].value").value(tomorrow) ) } From 3e37e8c6a7aa186683ed46180dedbe9b43e9b751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Sucena=20Lopes?= Date: Sat, 26 Oct 2024 17:06:09 +0100 Subject: [PATCH 2/2] tests: fix date format --- .../pt/up/fe/ni/website/backend/utils/ValidationTester.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt b/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt index 170980cd..1ff0dc0e 100644 --- a/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt +++ b/src/test/kotlin/pt/up/fe/ni/website/backend/utils/ValidationTester.kt @@ -1,6 +1,7 @@ package pt.up.fe.ni.website.backend.utils import java.time.LocalDate +import java.time.format.DateTimeFormatter import org.springframework.http.MediaType import org.springframework.test.web.servlet.ResultActions import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content @@ -114,8 +115,10 @@ class ValidationTester( fun isPastDate() { // get the current date and offset it by 1 day + val timeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy") val tomorrow = LocalDate.now() .plusDays(1) + .format(timeFormatter) .toString() val params = requiredFields.toMutableMap()