Skip to content

Commit

Permalink
Move the db tests to REPL based tests
Browse files Browse the repository at this point in the history
Yes, I agree this is neither reproducible nor automated, but the db
tests were so majorly brittle that they need some hand holding anyway.
The REPL is perfect for that: You invoke some code and check the
results in the file system and in the database.
  • Loading branch information
egli committed Jul 8, 2024
1 parent 601e8d3 commit 603d3da
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 73 deletions.
134 changes: 134 additions & 0 deletions env/dev/clj/repl_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
(ns repl-test
(:require [java-time.api :as time]))

;; invoke the following expressions in a REPL inside the
;; daisyproducer2.documents.abacus namespace

(documents/get-document 49)

(versions/insert-initial-version (documents/get-document 49))


;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test the predicates ;;
;;;;;;;;;;;;;;;;;;;;;;;;;

(product-seen-before? "EB31506")
(source-or-title-source-edition-seen-before? {:source "" :title "" :source-edition ""})
(source-or-title-source-edition-seen-before? {:source "" :title "Übersetzungstest (MK)" :source-edition ""})
(source-or-title-source-edition-seen-before? {:source "" :title "Übersetzungstest (MK)" :source-edition "2. / 2006"})
(source-or-title-source-edition-seen-before? {:source "SBS362058" :title "" :source-edition ""})
(source-or-title-source-edition-seen-before? (documents/get-document 49))
(product-seen-before? "ET4728726")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test update-document with unchanged metadata ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ensure that the document has an associated product

(products/insert-product 49 "EB31506" 1)
(update-document (assoc (documents/get-document 49) :product-number "EB31506"))

;; make sure no new version was created

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test update-document with changed metadata ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(update-document (assoc (documents/get-document 49) :author "a test author" :product-number "EB31506"))

;; make sure the metadata is changed
;; select author from documents_document where id = 49;

;; make sure there is an new entry in documents_version
;; select * from documents_version where document_id = 49;

;; make sure a new version has been created in the file system with updated metadata
;; ~/tmp/49/versions/0GK6952K3MDXK.xml

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Try to change the production-series metadata ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(update-document (assoc (documents/get-document 49) :production-series "PPP" :product-number "EB31506"))

;; make sure the metadata is changed
;; select author from documents_document where id = 49;

;; make sure there is an new entry in documents_version
;; select * from documents_version where document_id = 49;

;; make sure a new version has been created in the file system with updated metadata
;; ~/tmp/49/versions/0GK6AKK67MFVC.xml

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Try to change the source metadata ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(update-document (assoc (documents/get-document 49) :source "SBS362058" :product-number "EB31506"))

;; make sure the metadata is changed
;; select author from documents_document where id = 49;

;; make sure there is an new entry in documents_version
;; select * from documents_version where document_id = 49;

;; make sure a new version has been created in the file system with updated metadata
;; ~/tmp/49/versions/0GK6FMNA7MC4D.xml

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test update-document-and-product ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(update-document-and-product (assoc (documents/get-document 49) :product-number "ET4728726"))

;; make sure the metadata is _not_ changed
;; select author from documents_document where id = 49;

;; make sure there is _no_ new entry in documents_version
;; select * from documents_version where document_id = 49;

;; make sure _no_ new version has been created in the file system

;; make sure the product has been added
;; select * from documents_product where document_id = 49;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test insert-document-and-product ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(insert-document-and-product
{:production-series-number "6"
:source-publisher ""
:date (LocalDate/parse "2080-04-24")
:production-series "PPP"
:source-edition ""
:publisher "SBS Schweizerische Bibliothek für Blinde, Seh- und Lesebehinderte"
:product-number "PS86141"
:source "33-508974-91-0"
:title "Voilà"
:author "Edgar Palmérise",
:production-source "electronicData",
:product-type :braille,
:language "de",
:daisyproducer? true})

;; make sure a new document has been created
;; select * from documents_document where title = "Voilà";
;; ✓

;; make sure there is an entry in documents_version
;; select * from documents_version where document_id = 761;
;; ✓

;; make sure there is an initial version in the file system
;; ✓

;; make sure the metadata of the initial version in the file system is correct
;; ✓

;; make sure the product has been added
;; select * from documents_product where document_id = 761;
;; ✓

73 changes: 0 additions & 73 deletions test/clj/daisyproducer2/test/abacus_import/db_test.clj

This file was deleted.

0 comments on commit 603d3da

Please sign in to comment.