Skip to content

Commit

Permalink
proper error reporting for common error conditions in ddb/sync-item!
Browse files Browse the repository at this point in the history
  • Loading branch information
pkalliok committed Jul 19, 2024
1 parent 5dbc38d commit c15543d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/oph/ehoks/db/dynamodb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@
[table item]
(let [table-name @(tables table)
key-names (table-keys table)
item-key (zipmap key-names (map item key-names))
item-key (zipmap key-names
(map #(or (item %)
(throw (ex-info "item key missing"
{:key-name % :item item})))
key-names))
rest-item (apply dissoc item key-names)
attr-names (zipmap (map (partial str "#") (range))
(map name (keys rest-item)))
Expand All @@ -97,6 +101,9 @@
(-> {:hoks-id hoks-id :kyselytyypit [kyselytyyppi]}
(->> (get-for-heratepalvelu-by-hoks-id-and-kyselytyypit! db/spec))
(first)
(not-empty)
(or (throw (ex-info "palaute not found"
{:hoks-id hoks-id :kyselytyyppi kyselytyyppi})))
(remove-nils)
(update-keys map-keys-to-ddb)
(dissoc :internal-kyselytyyppi)
Expand Down
15 changes: 15 additions & 0 deletions test/oph/ehoks/db/dynamodb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
(use-fixtures :once test-utils/migrate-database)
(use-fixtures :each test-utils/empty-database-after-test)

(deftest amis-field-mapping
(testing "map-keys-to-ddb maps correctly"
(is (= (ddb/map-keys-to-ddb :foo) :foo))
(is (= (ddb/map-keys-to-ddb :toimija-oppija) :toimija_oppija))
(is (= (ddb/map-keys-to-ddb :sahkoposti) :sahkoposti))))

(deftest missing-sync-test
(testing "sync-item! fails when not enough information is available
for identifying the item"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"item key missing"
(ddb/sync-item! :amis {}))))
(testing "sync-amis-herate! fails when there is no information in db"
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"palaute not found"
(ddb/sync-amis-herate! 54343 "aloittaneet")))))

(def hoks-data {:opiskeluoikeus-oid "1.2.246.562.15.10000000009"
:oppija-oid "1.2.246.562.24.12312312319"
:ensikertainen-hyvaksyminen (LocalDate/now)
Expand Down

0 comments on commit c15543d

Please sign in to comment.