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

@ -0,0 +1,56 @@
(ns dog-and-duck.quack.picky.collections-test
(:require [clojure.test :refer [deftest is testing]]
[dog-and-duck.quack.picky.collections :refer
[collection-page-faults paged-collection-faults
simple-collection-faults]]
[dog-and-duck.quack.picky.constants :refer
[activitystreams-context-uri]]
[dog-and-duck.scratch.parser :refer [clean]]))
;;; Copyright (C) Simon Brooke, 2022
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License
;;; as published by the Free Software Foundation; either version 2
;;; of the License, or (at your option) any later version.
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
(deftest collection-identification-test
(let [paged (-> "resources/test_documents/outbox.json" slurp clean first)
page (-> "resources/test_documents/outbox_page.json"
slurp clean first)
simple (-> "resources/activitystreams-test-documents/vocabulary-ex5-jsonld.json"
slurp clean first)
not-a-collection {(keyword "@context") activitystreams-context-uri
:id "https://somewhere.out.there/object/14323:1671654380083"
:type "Test"}]
(testing "Outbox sample"
(let [actual (paged-collection-faults paged "OrderedCollection")
expected nil] (is (= actual expected)
"There should be no faults from a perfect object")))
(testing "Outbox page sample"
(let [actual (collection-page-faults page "OrderedCollectionPage")
expected nil] (is (= actual expected)
"There should be no faults from a perfect object")))
(testing "Simple sample"
(let [actual (set
(remove
nil?
(map :fault
(simple-collection-faults simple "Collection"))))
expected #{:no-id-transient :no-context :not-object-reference}]
(is (= actual expected)
"There should be no faults from vocabulary-ex5-jsonld, either, but there are.")))
(testing "Non-collection"
(let [actual (empty? (simple-collection-faults not-a-collection "Collection"))
expected false]
(is (= actual expected)
"There should be faults from anything which isn't a collection")))))

View file

@ -5,7 +5,8 @@
[dog-and-duck.quack.picky.utils :refer
[filter-severity object-faults]]
[dog-and-duck.quack.picky :refer
[persistent-object-faults]]))
[collection-faults persistent-object-faults]]
[dog-and-duck.scratch.parser :refer [clean]]))
;;; Copyright (C) Simon Brooke, 2022
@ -107,4 +108,31 @@
expected :id-not-uri
actual (-> o persistent-object-faults first :fault)]
(is (= actual expected)
"The fault from a persistent object with an id which is not a valid URI should be :id-not-uri")))))
"The fault from a persistent object with an id which is not a valid URI should be :id-not-uri")))))
(deftest collection-faults-test
(let [outbox (-> "resources/test_documents/outbox.json" slurp clean first)
outbox-page (-> "resources/test_documents/outbox_page.json"
slurp clean first)
simple (-> "resources/activitystreams-test-documents/vocabulary-ex5-jsonld.json"
slurp clean first)
not-a-collection {(keyword "@context") activitystreams-context-uri
:id "https://somewhere.out.there/object/14323:1671654380083"
:type "Test"}]
(testing "Collection type identification"
(let [actual (collection-faults outbox)
expected nil]
(is (= actual expected)
"There should be no faults in an outbox delivered by mastodon."))
(let [actual (collection-faults outbox-page)
expected nil]
(is (= actual expected)
"There should be no faults in an outbox page delivered by mastodon."))
(let [actual (set (remove nil? (map :fault (collection-faults simple))))
expected #{:no-id-transient :no-context :not-object-reference}]
(is (= actual expected)
"There should be no faults from vocabulary-ex5-jsonld, either, but there are."))
(let [actual (empty? (collection-faults not-a-collection))
expected false]
(is (= actual expected)
"There should be faults from anything which isn't a collection")))))