Skip to content

Commit

Permalink
Merge pull request #1574 from Opetushallitus/OK-556-kk-payment-state-…
Browse files Browse the repository at this point in the history
…logic

OK-556 payment state logic for hakemusmaksu
  • Loading branch information
vaeinoe committed Jul 10, 2024
2 parents c1098d6 + 7aa241f commit db74f3c
Show file tree
Hide file tree
Showing 22 changed files with 713 additions and 232 deletions.
1 change: 1 addition & 0 deletions .clj-kondo/babashka/sci/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:hooks {:macroexpand {sci.core/copy-ns sci.core/copy-ns}}}
9 changes: 9 additions & 0 deletions .clj-kondo/babashka/sci/sci/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns sci.core)

(defmacro copy-ns
([ns-sym sci-ns]
`(copy-ns ~ns-sym ~sci-ns nil))
([ns-sym sci-ns opts]
`[(quote ~ns-sym)
~sci-ns
(quote ~opts)]))
5 changes: 5 additions & 0 deletions .clj-kondo/rewrite-clj/rewrite-clj/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:lint-as
{rewrite-clj.zip/subedit-> clojure.core/->
rewrite-clj.zip/subedit->> clojure.core/->>
rewrite-clj.zip/edit-> clojure.core/->
rewrite-clj.zip/edit->> clojure.core/->>}}
16 changes: 16 additions & 0 deletions resources/sql/application-queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1307,3 +1307,19 @@ cross join unnest(la.hakukohde) with ordinality as u(hakukohde_oid, idx)
where la.haku = :haku_oid
and u.idx = 1) as ensisijaiset
group by hakukohde_oid;

--name: yesql-get-latest-applications-for-kk-payment-processing
SELECT
la.key,
la.submitted,
la.haku,
la.hakukohde,
la.person_oid AS "person-oid",
(SELECT content
FROM answers_as_content
WHERE application_id = la.id) AS content
FROM latest_applications AS la
LEFT JOIN application_reviews AS ar ON ar.application_key = la.key
WHERE la.haku in (:haku_oids) AND
la.person_oid in (:person_oids) AND
ar.state <> 'inactivated';
16 changes: 16 additions & 0 deletions spec/ataru/fixtures/application.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
:date "2018-03-22T07:55:08Z"
:name "Teppo Testinen"}})

(def application-with-hakemusmaksu-exemption
{:form 909909,
:lang "fi"
:haku "payment-info-test-kk-haku"
:id 543210
:person-oid "1.2.3.4.5.303"
:answers [{:key "vapautus_hakemusmaksusta" :value "0" :fieldType "dropdown"}]})

(def application-without-hakemusmaksu-exemption
{:form 909909,
:lang "fi"
:haku "payment-info-test-kk-haku"
:id 543211
:person-oid "1.2.3.4.5.303"
:answers [{:key "foo" :value "1" :fieldType "dropdown"}]})

(def application-with-koodisto-form
{:form 981230123,
:lang "fi"
Expand Down
32 changes: 26 additions & 6 deletions spec/ataru/fixtures/db/unit_test_db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
[ataru.db.db :as ataru-db]
[ataru.log.audit-log :as audit-log]))

; Make linter happy again
(declare yesql-delete-fixture-application-review!)
(declare yesql-delete-fixture-application-events!)
(declare yesql-delete-fixture-application-secrets!)
(declare yesql-delete-fixture-application-answers!)
(declare yesql-delete-fixture-application-multi-answers!)
(declare yesql-delete-fixture-application-group-answers!)
(declare yesql-delete-fixture-application!)
(declare yesql-delete-fixture-form!)
(declare yesql-delete-fixture-forms-with-key!)
(declare yesql-set-form-id!)

(defqueries "sql/dev-form-queries.sql")

(defn- nuke-old-fixture-data [form-id]
Expand All @@ -32,11 +44,11 @@
form))

(defn init-db-application-fixture
[form-fixture application-fixture application-reviews-fixture]
[form-fixture application-fixture application-hakukohde-reviews-fixture application-reviews-fixture]
(when (or (nil? (:id form-fixture)) (not= (:id form-fixture) (:form application-fixture)))
(throw (Exception. (str "Incorrect fixture data, application should refer the given form"))))
(let [audit-logger (audit-log/new-dummy-audit-logger)
form-id (init-db-form-fixture form-fixture)
_ (init-db-form-fixture form-fixture)
application-id (-> (application-store/add-application
application-fixture
(:hakukohde application-fixture)
Expand All @@ -46,17 +58,25 @@
nil)
:id)
stored-application (application-store/get-application application-id)]
(doseq [{hakukohde :hakukohde review-requirement :review-requirement review-state :review-state} application-reviews-fixture]
(doseq [{hakukohde :hakukohde review-requirement :review-requirement review-state :review-state}
application-hakukohde-reviews-fixture]
(application-store/save-application-hakukohde-review
(:key stored-application) hakukohde review-requirement review-state {} audit-logger))))
(:key stored-application) hakukohde review-requirement review-state {} audit-logger))
(doseq [review application-reviews-fixture]
(application-store/save-application-review
(merge review {:application-key (:key stored-application)}) {} audit-logger))))

(defn init-db-fixture
([form-fixture]
(nuke-old-fixture-data (:id form-fixture))
(init-db-form-fixture form-fixture))
([form-fixture application-fixture application-reviews-fixture]
([form-fixture application-fixture application-hakukohde-reviews-fixture]
(nuke-old-fixture-data (:id form-fixture))
(init-db-application-fixture form-fixture application-fixture application-reviews-fixture)))
(init-db-application-fixture form-fixture application-fixture application-hakukohde-reviews-fixture nil))
([form-fixture application-fixture application-hakukohde-reviews-fixture application-reviews-fixture]
(nuke-old-fixture-data (:id form-fixture))
(init-db-application-fixture form-fixture application-fixture
application-hakukohde-reviews-fixture application-reviews-fixture)))

(defn init-oppija-session-to-db
[ticket data]
Expand Down
5 changes: 5 additions & 0 deletions spec/ataru/fixtures/form.clj
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,8 @@
(def payment-properties-test-form
(merge minimal-form
{:key "payment-properties-test-form"}))

(def payment-exemption-test-form
(merge minimal-form
{:id 909909
:key "payment-exemption-test-form"}))
49 changes: 45 additions & 4 deletions spec/ataru/forms/form_payment_info_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
[ataru.forms.form-payment-info :as payment-info]
[ataru.tarjonta-service.tarjonta-protocol :as tarjonta-service]
[clj-time.core :as t]
[speclj.core :refer [describe it should= should-be tags]]
[ataru.tarjonta-service.mock-tarjonta-service :as mts]))

Expand Down Expand Up @@ -43,17 +44,25 @@
haku {:name { :fi "Testihaku 1"}
:oid "payment-info-test-kk-haku"
:kohdejoukko-uri "haunkohdejoukko_12#1"
:hakukohteet ["payment-info-test-kk-hakukohde"] }
:hakukohteet ["payment-info-test-kk-hakukohde"]
:hakuajat [{:start (t/date-time 2025 10 14)
:end (t/date-time 2025 10 15)}]
:alkamiskausi "kausi_s#1"
:alkamisvuosi 2025}
haku-with-payment-flag (payment-info/add-admission-payment-info-for-haku
tarjonta-service haku)]
(should= true(:admission-payment-required? haku-with-payment-flag))))
(should= true (:admission-payment-required? haku-with-payment-flag))))

(it "sets payment needed as false for non higher education"
(let [tarjonta-service (mts/->MockTarjontaKoutaService)
haku {:name { :fi "Testihaku 2" }
:oid "payment-info-test-non-kk-haku"
:kohdejoukko-uri "haunkohdejoukko_11#1"
:hakukohteet ["payment-info-test-non-kk-hakukohde"] }
:hakukohteet ["payment-info-test-non-kk-hakukohde"]
:hakuajat [{:start (t/date-time 2025 10 14)
:end (t/date-time 2025 10 15)}]
:alkamiskausi "kausi_s#1"
:alkamisvuosi 2025}
haku-with-payment-flag (payment-info/add-admission-payment-info-for-haku
tarjonta-service haku)]
(should= false (:admission-payment-required? haku-with-payment-flag))))
Expand All @@ -63,7 +72,39 @@
haku {:name { :fi "Testihaku 2" }
:oid "payment-info-test-unknown-haku"
:kohdejoukko-uri "haunkohdejoukko_12#1"
:hakukohteet ["payment-info-test-unknown-hakukohde"] }
:hakukohteet ["payment-info-test-unknown-hakukohde"]
:hakuajat [{:start (t/date-time 2025 10 14)
:end (t/date-time 2025 10 15)}]
:alkamiskausi "kausi_s#1"
:alkamisvuosi 2025}
haku-with-payment-flag (payment-info/add-admission-payment-info-for-haku
tarjonta-service haku)]
(should= false (:admission-payment-required? haku-with-payment-flag))))

(it "sets payment needed as false with higher education haku starting before 2025"
(let [tarjonta-service (mts/->MockTarjontaKoutaService)
haku {:name { :fi "Testihaku 1"}
:oid "payment-info-test-kk-haku"
:kohdejoukko-uri "haunkohdejoukko_12#1"
:hakukohteet ["payment-info-test-kk-hakukohde"]
:hakuajat [{:start (t/date-time 2024 10 14)
:end (t/date-time 2025 10 15)}]
:alkamiskausi "kausi_s#1"
:alkamisvuosi 2025}
haku-with-payment-flag (payment-info/add-admission-payment-info-for-haku
tarjonta-service haku)]
(should= false (:admission-payment-required? haku-with-payment-flag))))

(it "sets payment needed as false with higher education studies starting before fall 2025"
(let [tarjonta-service (mts/->MockTarjontaKoutaService)
haku {:name { :fi "Testihaku 1"}
:oid "payment-info-test-kk-haku"
:kohdejoukko-uri "haunkohdejoukko_12#1"
:hakukohteet ["payment-info-test-kk-hakukohde"]
:hakuajat [{:start (t/date-time 2025 10 14)
:end (t/date-time 2025 10 15)}]
:alkamiskausi "kausi_k#1"
:alkamisvuosi 2025}
haku-with-payment-flag (payment-info/add-admission-payment-info-for-haku
tarjonta-service haku)]
(should= false (:admission-payment-required? haku-with-payment-flag)))))
Expand Down
26 changes: 26 additions & 0 deletions spec/ataru/kk_application_payment/fixtures.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(ns ataru.kk-application-payment.fixtures)

(def koodisto-valtioryhmat-response
[{:uri "valtioryhmat_1"
:version 1
:value "EU"
:label {}
:valid { :start "2015-09-03T00:00:00+03:00" }
:within [{:uri "maatjavaltiot2_246"
:version 1
:value "246"}
{:uri "maatjavaltiot2_250"
:version 1
:value "250"}
{:uri "maatjavaltiot2_233"
:version 1
:value "233"}
{:uri "maatjavaltiot2_056"
:version 1
:value "056"}]}
{:uri "valtioryhmat_2"
:version 1
:value "ETA"
:label {}
:valid { :start "2015-09-03T00:00:00+03:00" }
:within {}}])
Loading

0 comments on commit db74f3c

Please sign in to comment.