Tests for collections written, but not all passing

This commit is contained in:
Simon Brooke 2023-01-01 14:19:53 +00:00
parent 33956ed516
commit 3aad725134
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
7 changed files with 166 additions and 16 deletions

View file

@ -29,8 +29,8 @@
(object-faults x type)
(list (object-reference-or-faults x type :critical :expected-collection)
(cond-make-fault-object (integer? (:totalItems x)) :should :no-total-items)
(object-reference-or-faults (:first x) nil :must :no-first-page)
(object-reference-or-faults (:last x) nil :should :no-last-page))))
(object-reference-or-faults (:first x) (str type "Page") :must :no-first-page)
(object-reference-or-faults (:last x) (str type "Page") :should :no-last-page))))
(defn simple-collection-faults
"Return a list of faults found in `x` considered as a non-paged collection
@ -38,11 +38,12 @@
[x type]
(concat-non-empty
(object-faults x type)
(cons
(list (object-reference-or-faults x type :critical :expected-collection)
(cond-make-fault-object (integer? (:totalItems x)) :should :no-total-items)
(concat
(list (cond-make-fault-object (integer? (:totalItems x)) :should :no-total-items)
(cond-make-fault-object (coll? (:items x)) :must :no-items-collection))
(map #(object-reference-or-faults % nil :must :not-object-reference) (:items x)))))
(reduce
concat
(map #(object-reference-or-faults % nil :must :not-object-reference) (:items x))))))
(defn collection-page-faults
"Return a list of faults found in `x` considered as a collection page

View file

@ -185,12 +185,15 @@
(and (coll? tv) (string? acceptable)) ((set tv) acceptable)
(and (coll? tv) (set? acceptable)) (not-empty
(intersection (set tv) acceptable))
:else
(throw (ex-info "Type value or `acceptable` argument not as expected."
{:arguments {:x x
:acceptable acceptable
:severity severity
:token token}})))
(not
(or (string? acceptable)
(set? acceptable))) (throw
(ex-info
"`acceptable` argument not as expected."
{:arguments {:x x
:acceptable acceptable
:severity severity
:token token}})))
(make-fault-object severity token)))))
(defn any-or-faults
@ -204,7 +207,7 @@
are always required."
[options severity-if-none token]
(let [faults (filter empty? options)]
(when (empty? faults)
(when (empty? faults)
;; i.e. there was at least one option that returned no faults...
(cons (make-fault-object severity-if-none token) faults))))