diff --git a/spec/ataru/kk_application_payment/kk_application_payment_status_updater_job_spec.clj b/spec/ataru/kk_application_payment/kk_application_payment_status_updater_job_spec.clj index ed8e17e14b..17791fbfb4 100644 --- a/spec/ataru/kk_application_payment/kk_application_payment_status_updater_job_spec.clj +++ b/spec/ataru/kk_application_payment/kk_application_payment_status_updater_job_spec.clj @@ -10,7 +10,7 @@ [clojure.java.jdbc :as jdbc] [clojure.string :as str] [speclj.core :refer [it describe should-not-throw stub should-have-invoked should-not-have-invoked - tags with-stubs should= around before]] + should-be-nil tags with-stubs should= around before]] [ataru.kk-application-payment.kk-application-payment :as payment] [ataru.fixtures.application :as application-fixtures] [ataru.fixtures.form :as form-fixtures] @@ -85,6 +85,14 @@ (declare conn) (declare spec) +(defn- get-payment-obligation-review [application-key hakukohde] + (jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}] + (->> (jdbc/query + conn + ["select * FROM application_hakukohde_reviews WHERE application_key = ? AND requirement = ? AND hakukohde = ?" + application-key "payment-obligation" hakukohde]) + first))) + (defn- clear! [] (jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}] (jdbc/delete! conn :applications []) @@ -383,4 +391,74 @@ (should-have-invoked :start-job {:with [:* :* "ataru.kk-application-payment.kk-application-payment-email-job" - check-mail-fn]}))))) + check-mail-fn]})))) + + (it "should set tuition fee obligation for non fi/sv hakukohde when payment state changes to awaiting" + (let [application-id (unit-test-db/init-db-fixture + form-fixtures/payment-exemption-test-form + application-fixtures/application-without-hakemusmaksu-exemption + nil) + _ (updater-job/update-kk-payment-status-for-person-handler + {:person_oid test-person-oid :term test-term :year test-year} runner) + application-key (:key (application-store/get-application application-id)) + payment (first (payment/get-raw-payments [application-key])) + obligation (get-payment-obligation-review application-key "payment-info-test-kk-hakukohde")] + (should= (:awaiting payment/all-states) (:state payment)) + (should= {:application_key application-key, :requirement "payment-obligation", + :state "obligated", :hakukohde "payment-info-test-kk-hakukohde"} + (select-keys obligation [:application_key :requirement :state :hakukohde])))) + + (it "should set tuition fee obligation for non fi/sv hakukohde when payment state changes to ok-by-proxy" + (let [application-ids (unit-test-db/init-db-fixture + form-fixtures/payment-exemption-test-form + [application-fixtures/application-without-hakemusmaksu-exemption + application-fixtures/application-without-hakemusmaksu-exemption]) + [first-key second-key] (map #(:key (application-store/get-application %)) application-ids) + _ (payment-store/create-or-update-kk-application-payment! + {:application-key first-key + :state (:paid payment/all-states) + :reason nil + :due-date (time-format/unparse payment/default-time-format + (time/plus (time/today-at 12 0 0) + (time/days 3))) + :total-sum payment/kk-application-payment-amount + :maksut-secret test-maksut-secret + :required-at "now()" + :notification-sent-at nil + :approved-at "now()"}) + _ (updater-job/update-kk-payment-status-for-person-handler + {:person_oid test-person-oid :term test-term :year test-year} runner) + payment (first (payment/get-raw-payments [second-key])) + obligation (get-payment-obligation-review second-key "payment-info-test-kk-hakukohde")] + (should= (:ok-by-proxy payment/all-states) (:state payment)) + (should= {:application_key second-key, :requirement "payment-obligation", + :state "obligated", :hakukohde "payment-info-test-kk-hakukohde"} + (select-keys obligation [:application_key :requirement :state :hakukohde])))) + + (it "should not set tuition fee obligation for non fi/sv hakukohde when payment state changes to not-required" + (let [application-id (unit-test-db/init-db-fixture + form-fixtures/payment-exemption-test-form + application-fixtures/application-with-hakemusmaksu-exemption + nil) + _ (updater-job/update-kk-payment-status-for-person-handler + {:person_oid test-person-oid :term test-term :year test-year} runner) + application-key (:key (application-store/get-application application-id)) + payment (first (payment/get-raw-payments [application-key])) + obligation (get-payment-obligation-review application-key "payment-info-test-kk-hakukohde")] + (should= (:not-required payment/all-states) (:state payment)) + (should-be-nil obligation))) + + (it "should not set tuition fee obligation for fi/sv hakukohde" + (let [application-id (unit-test-db/init-db-fixture + form-fixtures/payment-exemption-test-form + (merge + application-fixtures/application-without-hakemusmaksu-exemption + {:hakukohde ["payment-info-test-kk-fisv-hakukohde"]}) + nil) + _ (updater-job/update-kk-payment-status-for-person-handler + {:person_oid test-person-oid :term test-term :year test-year} runner) + application-key (:key (application-store/get-application application-id)) + payment (first (payment/get-raw-payments [application-key])) + obligation (get-payment-obligation-review application-key "payment-info-test-kk-fisv-hakukohde")] + (should= (:awaiting payment/all-states) (:state payment)) + (should-be-nil obligation)))) diff --git a/src/clj/ataru/tarjonta_service/mock_tarjonta_service.clj b/src/clj/ataru/tarjonta_service/mock_tarjonta_service.clj index b6223841a7..1dbc2c6ad5 100644 --- a/src/clj/ataru/tarjonta_service/mock_tarjonta_service.clj +++ b/src/clj/ataru/tarjonta_service/mock_tarjonta_service.clj @@ -550,7 +550,14 @@ :payment-info-test-kk-hakukohde (merge base-kouta-hakukohde {:oid "payment-info-test-kk-hakukohde" - :johtaaTutkintoon true}) + :johtaaTutkintoon true + :opetuskieliKoodiUrit ["oppilaitoksenopetuskieli_4#2"]}) + :payment-info-test-kk-fisv-hakukohde (merge + base-kouta-hakukohde + {:oid "payment-info-test-kk-fisv-hakukohde" + :johtaaTutkintoon true + :opetuskieliKoodiUrit ["oppilaitoksenopetuskieli_2#2" + "oppilaitoksenopetuskieli_4#2"]}) :payment-info-test-kk-no-tutkinto-hakukohde (merge base-kouta-hakukohde {:oid "payment-info-test-kk-no-tutkinto-hakukohde"