-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new lambda for contact info cleaning
timedOperationsHandler lambda was failing because of timeouts and this was causing some problems. Created a new lambda just for contact information cleaning.
- Loading branch information
Showing
7 changed files
with
225 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns oph.heratepalvelu.tep.contactInfoCleaningHandler | ||
"Käsittelee ajastettuja työpaikkaohjaajien yhteistietojen siivouksia." | ||
(:require [clojure.tools.logging :as log] | ||
[environ.core :refer [env]] | ||
[oph.heratepalvelu.db.dynamodb :as ddb] | ||
[oph.heratepalvelu.external.ehoks :as ehoks])) | ||
|
||
(gen-class | ||
:name "oph.heratepalvelu.tep.contactInfoCleaningHandler" | ||
:methods [[^:static cleanContactInfo | ||
[com.amazonaws.services.lambda.runtime.events.ScheduledEvent | ||
com.amazonaws.services.lambda.runtime.Context] void]]) | ||
|
||
(defn -cleanContactInfo | ||
"Käynnistää työpaikkaohjaajan yhteystietojen poiston." | ||
[_ _ _] | ||
(log/info "Käynnistetään työpaikkaohjaajan yhteystietojen poisto") | ||
(let [hankkimistavat | ||
(get-in (ehoks/delete-tyopaikkaohjaajan-yhteystiedot) | ||
[:body :data :hankkimistapa-ids]) | ||
counter (atom 0)] | ||
(doseq [hankkimistapa_id hankkimistavat] | ||
(log/info "Käsitellään oht" hankkimistapa_id) | ||
(let [resp (ddb/scan {:filter-expression "#id = :id" | ||
:expr-attr-names {"#id" "hankkimistapa_id"} | ||
:expr-attr-vals {":id" [:n hankkimistapa_id]}} | ||
(:jaksotunnus-table env)) | ||
items (:items resp)] | ||
(when (seq items) | ||
(log/info "Poistetaan ohjaajan yhteystiedot (hankkimistapa_id = " | ||
hankkimistapa_id | ||
")") | ||
(ddb/update-item | ||
{:hankkimistapa_id [:n hankkimistapa_id]} | ||
{:update-expr "SET #eml = :eml_value, #puh = :puh_value" | ||
:expr-attr-names {"#eml" "ohjaaja_email" | ||
"#puh" "ohjaaja_puhelinnumero"} | ||
:expr-attr-vals {":eml_value" [:s ""] ":puh_value" [:s ""]}} | ||
(:jaksotunnus-table env)) | ||
(swap! counter inc)))) | ||
(log/info "Poistettu" @counter "ohjaajan yhteystiedot"))) |
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
103 changes: 103 additions & 0 deletions
103
test/oph/heratepalvelu/integration_tests/tep/contactInfoCleaningHandler_i_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,103 @@ | ||
(ns oph.heratepalvelu.integration-tests.tep.contactInfoCleaningHandler-i-test | ||
(:require [clojure.test :refer [deftest is testing]] | ||
[oph.heratepalvelu.db.dynamodb :as ddb] | ||
[oph.heratepalvelu.integration-tests.mock-cas-client :as mcc] | ||
[oph.heratepalvelu.integration-tests.mock-db :as mdb] | ||
[oph.heratepalvelu.integration-tests.mock-http-client :as mhc] | ||
[oph.heratepalvelu.tep.contactInfoCleaningHandler | ||
:refer [-cleanContactInfo]] | ||
[oph.heratepalvelu.test-util :as tu])) | ||
|
||
(def mock-env {:ehoks-url "https://oph-ehoks.com/" | ||
:jaksotunnus-table "jaksotunnus-table"}) | ||
|
||
(def starting-table-contents [{:hankkimistapa_id [:n 1] | ||
:ohjaaja_email [:s "ohjaaja1@yritys.fi"] | ||
:ohjaaja_puhelinnumero [:s "0401111111"]} | ||
{:hankkimistapa_id [:n 2] | ||
:ohjaaja_email [:s "ohjaaja2@yritys.fi"] | ||
:ohjaaja_puhelinnumero [:s "0401111112"]} | ||
{:hankkimistapa_id [:n 3] | ||
:ohjaaja_email [:s "ohjaaja3@yritys.fi"] | ||
:ohjaaja_puhelinnumero [:s "0401111113"]}]) | ||
|
||
(defn- setup-test [] | ||
(mcc/clear-results) | ||
(mhc/clear-results) | ||
(mhc/clear-url-bindings) | ||
(mhc/bind-url :get | ||
(str (:ehoks-url mock-env) "heratepalvelu/tyoelamajaksot") | ||
{:query-params {:start "2021-07-01" | ||
:end "2022-02-02" | ||
:limit 1500} | ||
:as :json | ||
:headers | ||
{:ticket | ||
"service-ticket/ehoks-virkailija-backend/cas-security-check"}} | ||
{:body {:data 2}}) | ||
(mhc/bind-url :delete | ||
(str (:ehoks-url mock-env) | ||
"heratepalvelu/tyopaikkaohjaajan-yhteystiedot") | ||
{:as :json | ||
:headers | ||
{:ticket | ||
"service-ticket/ehoks-virkailija-backend/cas-security-check"}} | ||
{:body {:data {:hankkimistapa-ids [1 2 3]}}}) | ||
(mdb/clear-mock-db) | ||
(mdb/create-table (:jaksotunnus-table mock-env) | ||
{:primary-key :hankkimistapa_id | ||
:sort-key :hankkimistapa_id}) | ||
(mdb/set-table-contents (:jaksotunnus-table mock-env) | ||
starting-table-contents)) | ||
|
||
(defn- teardown-test [] | ||
(mcc/clear-results) | ||
(mhc/clear-results) | ||
(mhc/clear-url-bindings) | ||
(mdb/clear-mock-db)) | ||
|
||
(def expected-http-results | ||
[{:method :delete | ||
:url "https://oph-ehoks.com/heratepalvelu/tyopaikkaohjaajan-yhteystiedot" | ||
:options | ||
{:headers {:ticket | ||
"service-ticket/ehoks-virkailija-backend/cas-security-check"} | ||
:as :json}}]) | ||
|
||
(def expected-cas-client-results [{:type :get-service-ticket | ||
:service "/ehoks-virkailija-backend" | ||
:suffix "cas-security-check"}]) | ||
|
||
(deftest test-contactInfoCleaningHandler-integration | ||
(testing "contactInfoCleaningHandler integraatiotesti" | ||
(with-redefs [clojure.tools.logging/log* tu/mock-log* | ||
environ.core/env mock-env | ||
oph.heratepalvelu.external.cas-client/get-service-ticket | ||
mcc/mock-get-service-ticket | ||
oph.heratepalvelu.external.http-client/delete mhc/mock-delete | ||
ddb/scan mdb/scan | ||
ddb/update-item mdb/update-item] | ||
(setup-test) | ||
(-cleanContactInfo {} | ||
(tu/mock-handler-event :scheduledherate) | ||
(tu/mock-handler-context)) | ||
(is (= (mcc/get-results) expected-cas-client-results)) | ||
(is (= (mhc/get-results) expected-http-results)) | ||
(is (true? (tu/logs-contain? | ||
{:level :info | ||
:message | ||
"Käynnistetään työpaikkaohjaajan yhteystietojen poisto"}))) | ||
(is (true? (tu/logs-contain? | ||
{:level :info | ||
:message "Poistettu 3 ohjaajan yhteystiedot"}))) | ||
(is (= (mdb/get-table-values (:jaksotunnus-table mock-env)) | ||
#{{:hankkimistapa_id [:n 1] | ||
:ohjaaja_email [:s ""] | ||
:ohjaaja_puhelinnumero [:s ""]} | ||
{:hankkimistapa_id [:n 2] | ||
:ohjaaja_email [:s ""] | ||
:ohjaaja_puhelinnumero [:s ""]} | ||
{:hankkimistapa_id [:n 3] | ||
:ohjaaja_email [:s ""] | ||
:ohjaaja_puhelinnumero [:s ""]}})) | ||
(teardown-test)))) |
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
47 changes: 47 additions & 0 deletions
47
test/oph/heratepalvelu/tep/contactInfoCleaningHandler_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,47 @@ | ||
(ns oph.heratepalvelu.tep.contactInfoCleaningHandler-test | ||
(:require [clojure.test :refer [deftest is testing]] | ||
[clojure.tools.logging :as log] | ||
[oph.heratepalvelu.db.dynamodb :as ddb] | ||
[oph.heratepalvelu.external.ehoks :as ehoks] | ||
[oph.heratepalvelu.tep.contactInfoCleaningHandler | ||
:refer [-cleanContactInfo]] | ||
[oph.heratepalvelu.test-util :as tu])) | ||
|
||
(def delete-endpoint-called (atom false)) | ||
(def scan-called (atom 0)) | ||
(def update-item-called (atom 0)) | ||
|
||
(defn- mock-delete-call [] | ||
(reset! delete-endpoint-called true) | ||
{:body {:data {:hankkimistapa-ids [1 2 3]}}}) | ||
|
||
(defn- mock-scan [_ __] | ||
(swap! scan-called inc) | ||
{:items [{:hankkimistapa_id [:n @scan-called] | ||
:sahkoposti [:s "testi@oph.fi"] | ||
:puhelinnumero [:s "0401111111"]}]}) | ||
|
||
(defn- mock-update-item [_ __ ___] | ||
(swap! update-item-called inc)) | ||
|
||
(deftest test-cleanContactInfo | ||
(testing "Varmista, että -cleanContactInfo siivoaa yhteystiedot" | ||
(with-redefs | ||
[log/log* tu/mock-log* | ||
ehoks/delete-tyopaikkaohjaajan-yhteystiedot mock-delete-call | ||
ddb/scan mock-scan | ||
ddb/update-item mock-update-item] | ||
(let [event (tu/mock-handler-event :scheduledherate) | ||
context (tu/mock-handler-context)] | ||
(-cleanContactInfo {} event context) | ||
(is (true? | ||
(tu/logs-contain? | ||
{:level :info | ||
:message | ||
"Käynnistetään työpaikkaohjaajan yhteystietojen poisto"}))) | ||
(is (= @scan-called 3)) | ||
(is (= @update-item-called 3)) | ||
(is (true? @delete-endpoint-called)) | ||
(is (true? (tu/logs-contain? | ||
{:level :info | ||
:message "Poistettu 3 ohjaajan yhteystiedot"}))))))) |
Oops, something went wrong.