-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix Fetching history data
- Loading branch information
Showing
5 changed files
with
167 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
etp-core/etp-backend/src/test/clj/solita/etp/api/laatija_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
(ns solita.etp.api.laatija-test | ||
(:require [clojure.test :as t] | ||
[jsonista.core :as j] | ||
[ring.mock.request :as mock] | ||
[solita.etp.test-data.kayttaja :as test-data.kayttaja] | ||
[solita.etp.test-data.laatija :as test-data.laatija] | ||
[solita.etp.test-system :as ts])) | ||
|
||
(t/use-fixtures :each ts/fixture) | ||
|
||
(t/deftest retrieve-change-history-test | ||
(test-data.kayttaja/insert-virtu-paakayttaja! {:etunimi "Asian" | ||
:sukunimi "Tuntija" | ||
:email "[email protected]" | ||
:puhelin "0504363675457"}) | ||
(let [user (->> (test-data.laatija/generate-adds 1) | ||
(first)) | ||
user-id (first (test-data.laatija/insert! [user]))] | ||
(t/testing "Käyttäjä's change history can be fetched from the api after the user is created" | ||
(let [response (ts/handler (-> (mock/request :get (format "/api/private/kayttajat/%s/history" user-id)) | ||
(test-data.kayttaja/with-virtu-user) | ||
(mock/header "Accept" "application/json"))) | ||
body (-> response :body (j/read-value j/keyword-keys-object-mapper))] | ||
(t/is (= (:status response) 200)) | ||
(t/is (= (count body) | ||
1)) | ||
(t/is (= (dissoc (first body) :modifytime) | ||
(merge (select-keys user [:email :etunimi :henkilotunnus :puhelin :sukunimi :passivoitu]) | ||
{:cognitoid nil | ||
:id 2 | ||
:modifiedby-name "etp, database" | ||
:organisaatio "" | ||
:rooli 0 | ||
:titteli-fi nil | ||
:titteli-sv nil | ||
:valvoja false | ||
:virtu nil}))))) | ||
(t/testing "Laatija's change history can be fetched from the api after the user is created" | ||
(let [response (ts/handler (-> (mock/request :get (format "/api/private/laatijat/%s/history" user-id)) | ||
(test-data.kayttaja/with-virtu-user) | ||
(mock/header "Accept" "application/json"))) | ||
body (-> response :body (j/read-value j/keyword-keys-object-mapper))] | ||
(t/is (= (:status response) 200)) | ||
(t/is (= (count body) | ||
1)) | ||
(t/is (= (dissoc (first body) :modifytime :toteamispaivamaara) | ||
(merge (select-keys user [:jakeluosoite :postinumero :postitoimipaikka :maa :patevyystaso :toteaja]) | ||
{:id 2 | ||
:julkinenemail false | ||
:julkinenosoite false | ||
:julkinenpostinumero false | ||
:julkinenpuhelin false | ||
:julkinenwwwosoite false | ||
:laatimiskielto false | ||
:laskutuskieli 0 | ||
:modifiedby-name "etp, database" | ||
:muuttoimintaalueet [] | ||
:partner false | ||
:toimintaalue nil | ||
:vastaanottajan-tarkenne nil | ||
:wwwosoite nil}))))) | ||
(t/testing "After changing user data" | ||
(let [update {:etunimi "Uusi" | ||
:sukunimi "Nimi" | ||
:toteamispaivamaara "2024-01-01" | ||
:julkinenemail true} | ||
update-response (ts/handler (-> (mock/request :put (format "/api/private/laatijat/%s" user-id)) | ||
(mock/json-body (merge (dissoc user :toteamispaivamaara) | ||
update | ||
{:julkinenosoite false | ||
:julkinenpostinumero false | ||
:julkinenpuhelin false | ||
:julkinenwwwosoite false | ||
:laatimiskielto false | ||
:laskutuskieli 0 | ||
:muuttoimintaalueet [] | ||
:toimintaalue nil | ||
:vastaanottajan-tarkenne nil | ||
:wwwosoite nil | ||
:api-key nil} | ||
)) | ||
(test-data.kayttaja/with-virtu-user) | ||
(mock/header "Accept" "application/json")))] | ||
(t/is (= (:status update-response) 200)) | ||
(t/testing "Changes in kayttaja data are reflected in the history" | ||
(let [response (ts/handler (-> (mock/request :get (format "/api/private/kayttajat/%s/history" user-id)) | ||
(test-data.kayttaja/with-virtu-user) | ||
(mock/header "Accept" "application/json"))) | ||
body (-> response :body (j/read-value j/keyword-keys-object-mapper))] | ||
(t/is (= (:status response) 200)) | ||
(t/is (= (count body) | ||
2)) | ||
(t/is (= (dissoc (first body) :modifytime) | ||
(merge (select-keys user [:email :etunimi :henkilotunnus :puhelin :sukunimi :passivoitu]) | ||
{:cognitoid nil | ||
:id 2 | ||
:modifiedby-name "etp, database" | ||
:organisaatio "" | ||
:rooli 0 | ||
:titteli-fi nil | ||
:titteli-sv nil | ||
:valvoja false | ||
:virtu nil}))) | ||
(t/is (= (dissoc (last body) :modifytime) | ||
(merge (select-keys user [:email :henkilotunnus :puhelin :passivoitu]) | ||
{:etunimi "Uusi" | ||
:sukunimi "Nimi" | ||
:cognitoid nil | ||
:id 2 | ||
:modifiedby-name "Tuntija, Asian" | ||
:organisaatio "" | ||
:rooli 0 | ||
:titteli-fi nil | ||
:titteli-sv nil | ||
:valvoja false | ||
:virtu nil}))))) | ||
(t/testing "Changes in laatija data are reflected in the history" | ||
(let [response (ts/handler (-> (mock/request :get (format "/api/private/laatijat/%s/history" user-id)) | ||
(test-data.kayttaja/with-virtu-user) | ||
(mock/header "Accept" "application/json"))) | ||
body (-> response :body (j/read-value j/keyword-keys-object-mapper))] | ||
(t/is (= (:status response) 200)) | ||
(t/is (= (count body) | ||
2)) | ||
(t/is (= (dissoc (first body) :modifytime :toteamispaivamaara) | ||
(merge (select-keys user [:jakeluosoite :postinumero :postitoimipaikka :maa :patevyystaso :toteaja]) | ||
{:id 2 | ||
:julkinenemail false | ||
:julkinenosoite false | ||
:julkinenpostinumero false | ||
:julkinenpuhelin false | ||
:julkinenwwwosoite false | ||
:laatimiskielto false | ||
:laskutuskieli 0 | ||
:modifiedby-name "etp, database" | ||
:muuttoimintaalueet [] | ||
:partner false | ||
:toimintaalue nil | ||
:vastaanottajan-tarkenne nil | ||
:wwwosoite nil}))) | ||
(t/is (= (dissoc (last body) :modifytime :toteamispaivamaara) | ||
(merge (select-keys user [:jakeluosoite :postinumero :postitoimipaikka :maa :patevyystaso :toteaja]) | ||
{:id 2 | ||
:julkinenemail true | ||
:julkinenosoite false | ||
:julkinenpostinumero false | ||
:julkinenpuhelin false | ||
:julkinenwwwosoite false | ||
:laatimiskielto false | ||
:laskutuskieli 0 | ||
:modifiedby-name "Tuntija, Asian" | ||
:muuttoimintaalueet [] | ||
:partner false | ||
:toimintaalue nil | ||
:vastaanottajan-tarkenne nil | ||
:wwwosoite nil}))))))))) |
7 changes: 7 additions & 0 deletions
7
etp-core/etp-db/src/main/sql/migration/v5-release-1.1/v5.47-audit-log-kayttaja-titteli.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
alter table audit.kayttaja add column titteli_fi text default null; | ||
alter table audit.kayttaja add column titteli_sv text default null; | ||
|
||
drop trigger if exists kayttaja_update_trigger on kayttaja; | ||
call audit.create_audit_procedure('kayttaja'::name); | ||
call audit.create_audit_update_trigger('kayttaja'::name, 'kayttaja'::name, | ||
audit.update_condition('kayttaja'::name)); |