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

tests: replace hardcoded date with dynamic value #207

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +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
Expand Down Expand Up @@ -112,13 +114,20 @@ 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()
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)
)
}

Expand Down
Loading