Skip to content

Commit

Permalink
Fix päättökysely sending on HOKS replace
Browse files Browse the repository at this point in the history
  • Loading branch information
severij committed Nov 9, 2023
1 parent 3ce23c8 commit 38016a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/oph/ehoks/hoks/hoks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@
"Korvaa kokonaisen HOKSin (ml. tutkinnon osat) annetuilla arvoilla."
[hoks-id new-values]
(let [current-hoks (get-hoks-by-id hoks-id)
updated-hoks (assoc new-values :id hoks-id)
amisherate-kasittelytila
(db-hoks/get-or-create-amisherate-kasittelytila-by-hoks-id! hoks-id)
h (jdbc/with-db-transaction
[db-conn (db-ops/get-db-connection)]
(replace-main-hoks! hoks-id new-values db-conn)
(replace-hoks-parts! updated-hoks db-conn))]
(replace-hoks-parts! (assoc new-values :id hoks-id) db-conn))
updated-hoks (get-hoks-by-id hoks-id)]
(if (c/tuva-related-hoks? updated-hoks)
(db-hoks/set-amisherate-kasittelytilat-to-true!
amisherate-kasittelytila
Expand Down
4 changes: 2 additions & 2 deletions src/oph/ehoks/hoks/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@
:types {:any s/Str}
:description "HOKSin generoitu ulkoinen tunniste eHOKS-järjestelmässä"}
:oppija-oid {:methods {:any :optional
:post :required}
:post :required} ; FIXME: should be required for :put
:types {:any Oid}
:description "Oppijan tunniste Opintopolku-ympäristössä"}
:sahkoposti {:methods {:any :optional}
Expand All @@ -894,7 +894,7 @@
:description "Oppijan puhelinnumero, merkkijono."}
:opiskeluoikeus-oid
{:methods {:any :optional
:post :required}
:post :required} ; FIXME: should be required for :put
:types {:any OpiskeluoikeusOid}
:description (str "Opiskeluoikeuden oid-tunniste Koski-järjestelmässä "
"muotoa '1.2.246.562.15.00000000001'.")}
Expand Down
33 changes: 25 additions & 8 deletions test/oph/ehoks/hoks/hoks_save_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,31 @@
(is (= @sqs-call-counter 0)))))))

(deftest form-opiskelijapalaute-in-hoks-replace
(testing (str "replace: forms opiskelijapalaute when has "
"osaamisen-hankkimisen-tarve")
(let [sqs-call-counter (atom 0)]
(with-redefs [sqs/send-amis-palaute-message (mock-call sqs-call-counter)
k/get-opiskeluoikeus-info-raw mock-get-opiskeluoikeus]
(let [saved-hoks (h/save-hoks! hoks-data)]
(h/replace-hoks! (:id saved-hoks) hoks-osaaminen-saavutettu)
(is (= @sqs-call-counter 2)))))))
(let [sqs-call-counter (atom 0)]
(with-redefs [sqs/send-amis-palaute-message (mock-call sqs-call-counter)
k/get-opiskeluoikeus-info-raw mock-get-opiskeluoikeus]
(testing "When existing HOKS is replaced with a new one, "
(testing
"form opiskelijapalaute if `osaamisen-hankkimisen-tarve` is `true`"
(let [saved-hoks (h/save-hoks! hoks-data)]
(is (= @sqs-call-counter 1)) ; sent herate for aloituskysely
(h/replace-hoks! (:id saved-hoks) hoks-osaaminen-saavutettu)
(is (= @sqs-call-counter 2))) ; herate sent for paattokysely

(reset! sqs-call-counter 0)
(utils/clear-db)

; FIXME: Currently `opiskeluoikeus-oid` is not required in
; `HOKSKorvaus` schema, even though it probably should be. The
; following assertions can be removed once that is fixed.
(testing ", even when `opiskeluoikeus-oid` is missing from new HOKS"
(let [saved-hoks (h/save-hoks! hoks-data)]
(is (= @sqs-call-counter 1)) ; herate sent for aloituskysely
(h/replace-hoks! (:id saved-hoks)
(dissoc hoks-osaaminen-saavutettu
:opiskeluoikeus-oid))
(is (= @sqs-call-counter 2))))))))) ; herate sent for paattokysely


(deftest do-not-form-opiskelijapalaute-in-hoks-replace
(testing (str "replace: does not form opiskelijapalaute when "
Expand Down

0 comments on commit 38016a9

Please sign in to comment.