|
1 | 1 | (ns lrsql.util.statement-test |
2 | 2 | (:require [clojure.test :refer [deftest testing is]] |
3 | | - [lrsql.util.statement :as su])) |
| 3 | + [lrsql.util.statement :as su] |
| 4 | + [lrsql.util :as u])) |
4 | 5 |
|
5 | 6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | 7 | ;; Fixtures |
|
46 | 47 | {"id" "http://www.example.com/tincan/activities/multipart" |
47 | 48 | "objectType" "Activity"}) |
48 | 49 |
|
| 50 | +(def sample-attachment |
| 51 | + {"usageType" "http://example.com/attachment-usage/test" |
| 52 | + "display" {"en-US" "A test attachment"} |
| 53 | + "description" {"en-US" "A test attachment (description)"} |
| 54 | + "contentType" "text/plain" |
| 55 | + "length" 27 |
| 56 | + "sha2" "495395e777cd98da653df9615d09c0fd6bb2f8d4788394cd53c56a3bfdcd848a"}) |
| 57 | + |
49 | 58 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
50 | 59 | ;; Tests |
51 | 60 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
54 | 63 | (let [lrs-authority {"mbox" "mailto:a@example.com" |
55 | 64 | "objectType" "Agent"} |
56 | 65 | foreign-authority {"mbox" "mailto:b@example.com" |
57 | | - "objectType" "Agent"}] |
| 66 | + "objectType" "Agent"} |
| 67 | + ;; Statements |
| 68 | + statement-1 {"id" sample-id |
| 69 | + "actor" sample-group |
| 70 | + "verb" sample-verb |
| 71 | + "object" sample-activity} |
| 72 | + statement-2 {"id" sample-id |
| 73 | + "actor" sample-group |
| 74 | + "verb" sample-verb |
| 75 | + "object" sample-activity |
| 76 | + "authority" foreign-authority} |
| 77 | + statement-3 {"id" sample-id |
| 78 | + "actor" sample-group |
| 79 | + "verb" (assoc sample-verb "display" {}) |
| 80 | + "object" (assoc sample-activity |
| 81 | + "definition" |
| 82 | + {"name" {} |
| 83 | + "description" {}}) |
| 84 | + "attachments" [(-> sample-attachment |
| 85 | + (assoc "display" {}) |
| 86 | + (assoc "description" {}))] |
| 87 | + "context" {} |
| 88 | + "result" {}} |
| 89 | + statement-4 {"id" sample-id |
| 90 | + "actor" sample-group |
| 91 | + "verb" sample-verb |
| 92 | + "object" (assoc sample-activity |
| 93 | + "definition" |
| 94 | + {;; Doesn't form a valid statement but |
| 95 | + ;; we need to test these lang maps |
| 96 | + "choices" [{"id" "Choice" |
| 97 | + "description" {}}] |
| 98 | + "scale" [{"id" "Scale" |
| 99 | + "description" {}}] |
| 100 | + "source" [{"id" "Source" |
| 101 | + "description" {}}] |
| 102 | + "target" [{"id" "Target" |
| 103 | + "description" {}}] |
| 104 | + "steps" [{"id" "Step" |
| 105 | + "description" {}}]})}] |
| 106 | + (testing "adds timestamp, stored, version, and authority" |
| 107 | + (let [statement* (su/prepare-statement lrs-authority statement-1)] |
| 108 | + (is (inst? (u/str->time (get statement* "timestamp")))) |
| 109 | + (is (inst? (u/str->time (get statement* "stored")))) |
| 110 | + (is (= su/xapi-version (get statement* "version"))) |
| 111 | + (is (= lrs-authority (get statement* "authority"))))) |
58 | 112 | (testing "overwrites authority" |
59 | 113 | (is (= lrs-authority |
60 | | - (-> (su/prepare-statement |
61 | | - lrs-authority |
62 | | - {"id" sample-id |
63 | | - "actor" sample-group |
64 | | - "verb" sample-verb |
65 | | - "object" sample-activity |
66 | | - "authority" foreign-authority}) |
67 | | - (get "authority"))))))) |
| 114 | + (-> (su/prepare-statement lrs-authority statement-2) |
| 115 | + (get "authority"))))) |
| 116 | + (testing "dissocs empty maps" |
| 117 | + (is (= {"id" sample-id |
| 118 | + "actor" sample-group |
| 119 | + "verb" sample-verb-dissoc |
| 120 | + "object" sample-activity-dissoc |
| 121 | + "attachments" [(dissoc sample-attachment |
| 122 | + "display" |
| 123 | + "description")]} |
| 124 | + (-> (su/prepare-statement lrs-authority statement-3) |
| 125 | + (dissoc "timestamp" "stored" "authority" "version")))) |
| 126 | + (is (= {"id" sample-id |
| 127 | + "actor" sample-group |
| 128 | + "verb" sample-verb |
| 129 | + "object" (assoc sample-activity |
| 130 | + "definition" |
| 131 | + {"choices" [{"id" "Choice"}] |
| 132 | + "scale" [{"id" "Scale"}] |
| 133 | + "source" [{"id" "Source"}] |
| 134 | + "target" [{"id" "Target"}] |
| 135 | + "steps" [{"id" "Step"}]})} |
| 136 | + (-> (su/prepare-statement lrs-authority statement-4) |
| 137 | + (dissoc "timestamp" "stored" "authority" "version"))))))) |
68 | 138 |
|
69 | 139 | (deftest statements-equal-test |
70 | 140 | (testing "statement equality" |
|
0 commit comments