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

EH-1362: 'Automate' valid-herate-date? #244

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
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
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