Skip to content

Commit

Permalink
Merge pull request #207 from NIAEFEUP/tests/refactor-isPastDate-valid…
Browse files Browse the repository at this point in the history
…ator

tests: replace hardcoded date with dynamic value
  • Loading branch information
MRita443 authored Nov 6, 2024
2 parents 279d0e6 + 3e37e8c commit 55ddb2d
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit 55ddb2d

Please sign in to comment.