Skip to content

Commit

Permalink
'Automate' valid-herate-date?
Browse files Browse the repository at this point in the history
  • Loading branch information
tomikat committed Jun 22, 2023
1 parent 0a689a6 commit ff8177f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/oph/heratepalvelu/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,18 @@
:tyyppi_kausi [:s (str tyyppi "/" laskentakausi)]}))))

(defn valid-herate-date?
"onko herätteen päivämäärä aikaisintaan 1.7.2022?"
"onko herätteen päivämäärä aikaisintaan kuluvan rahoituskauden alkupvm
(1.7.)?"
[heratepvm]
(try
(not (.isAfter (LocalDate/of 2022 7 1) (LocalDate/parse (or heratepvm ""))))
(let [current-year (.getYear (local-date-now))
rahoituskausi-alkuvuosi (if (< (.getMonthValue (local-date-now)) 7)
(dec current-year)
current-year)
rahoituskausi-alkupvm (LocalDate/of
^long rahoituskausi-alkuvuosi 7 1)]
(not (.isAfter rahoituskausi-alkupvm
(LocalDate/parse (or heratepvm "")))))
(catch DateTimeParseException e
(log/warn "Bad date" heratepvm)
false)))
Expand Down
21 changes: 13 additions & 8 deletions test/oph/heratepalvelu/common_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns oph.heratepalvelu.common-test
(:require [clojure.test :refer :all]
[oph.heratepalvelu.common :refer :all]
[oph.heratepalvelu.common :refer :all :as c]
[oph.heratepalvelu.test-util :refer :all]
[clj-time.core :as t]
[clojure.string :as str])
Expand Down Expand Up @@ -199,13 +199,18 @@
"arvizturo_tukorfurogep"))))

(deftest test-valid-herate-date?
(testing "True if heratepvm is >= 2022-07-01"
(is (true? (valid-herate-date? "2022-07-02")))
(is (true? (valid-herate-date? "2022-07-01")))
(is (not (true? (valid-herate-date? "2022-06-01"))))
(is (not (true? (valid-herate-date? "2022-07-01xxxx"))))
(is (not (true? (valid-herate-date? ""))))
(is (not (true? (valid-herate-date? nil))))))
(testing "True if heratepvm is >= [rahoituskausi start year]-07-01"
(with-redefs [c/local-date-now (constantly (LocalDate/of 2023 6 22))]
(is (true? (valid-herate-date? "2022-07-02")))
(is (true? (valid-herate-date? "2022-07-01")))
(is (not (true? (valid-herate-date? "2022-06-01"))))
(is (not (true? (valid-herate-date? "2022-07-01xxxx"))))
(is (not (true? (valid-herate-date? ""))))
(is (not (true? (valid-herate-date? nil))))))
(testing "Not true if heratepvm is < [rahoituskausi start year]-07-01"
(with-redefs [c/local-date-now (constantly (LocalDate/of 2023 7 22))]
(is (not (true? (valid-herate-date? "2022-07-02"))))
(is (not (true? (valid-herate-date? "2022-07-01")))))))

(deftest test-sisaltyy-toiseen-opiskeluoikeuteen
(testing "Sisältyy toiseen opiskeluoikeuteen"
Expand Down

0 comments on commit ff8177f

Please sign in to comment.