Abstract out helper fn for timestamp react-query-tests

pull/8387/head
Ben Yorke 2023-01-20 18:14:54 +01:00
parent a2efbdb333
commit 6d1f26fa03
1 changed files with 30 additions and 197 deletions

View File

@ -22,6 +22,18 @@ adds rules that users often use"
(when-let [result (query-custom/custom-query test-helper/test-db query opts)]
(map first (deref result))))
(defn- blocks-created-between-inputs [a b]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [a b]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(deftest resolve-input-for-page-and-block-inputs
(load-test-files [{:file/path "pages/page1.md"
:file/content
@ -152,237 +164,58 @@ created-at:: %s"
(db-util/date-at-local-ms (t/plus (t/today) (t/months 1)) 0 0 0 0)
(db-util/date-at-local-ms (t/plus (t/today) (t/years 1)) 0 0 0 0))}])
(is (= ["today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-0d-ms :+0d-ms]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["today" "tonight"] (blocks-created-between-inputs :-0d-ms :+0d-ms))
":+0d-ms and :-0d-ms resolve to correct datetime range")
(is (= ["+1d" "-1d" "today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-1d-ms :+5d-ms]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "-1d" "today" "tonight"] (blocks-created-between-inputs :-1d-ms :+5d-ms))
":-Xd-ms and :+Xd-ms resolve to correct datetime range")
(is (= ["+1d" "+1w" "-1d" "-1w" "today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-1w-ms :+1w-ms]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "+1w" "-1d" "-1w" "today" "tonight"] (blocks-created-between-inputs :-1w-ms :+1w-ms))
":-Xw-ms and :+Xw-ms resolve to correct datetime range")
(is (= ["+1d" "+1m" "+1w" "-1d" "-1m" "-1w" "today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-1m-ms :+1m-ms]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "+1m" "+1w" "-1d" "-1m" "-1w" "today" "tonight"] (blocks-created-between-inputs :-1m-ms :+1m-ms))
":-Xm-ms and :+Xm-ms resolve to correct datetime range")
(is (= ["+1d" "+1m" "+1w" "+1y" "-1d" "-1m" "-1w" "-1y" "today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-1y-ms :+1y-ms]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "+1m" "+1w" "+1y" "-1d" "-1m" "-1w" "-1y" "today" "tonight"] (blocks-created-between-inputs :-1y-ms :+1y-ms))
":-Xy-ms and :+Xy-ms resolve to correct datetime range")
(is (= ["today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:start-of-today-ms :end-of-today-ms]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["today" "tonight"] (blocks-created-between-inputs :start-of-today-ms :end-of-today-ms))
":start-of-today-ms and :end-of-today-ms resolve to correct datetime range")
(is (= ["+1d" "-1d" "today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:1d-before-ms :5d-after-ms]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "-1d" "today" "tonight"] (blocks-created-between-inputs :1d-before-ms :5d-after-ms))
":Xd-before-ms and :Xd-after-ms resolve to correct datetime range")
(is (= ["today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:today-start :today-end]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["today" "tonight"] (blocks-created-between-inputs :today-start :today-end))
":today-start and :today-end resolve to correct datetime range")
(is (= ["+1d" "today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-0d-start :+1d-end]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "today" "tonight"] (blocks-created-between-inputs :-0d-start :+1d-end))
":-XT-start and :+XT-end resolve to correct datetime range")
(is (= ["today"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:today-1159 :today-1201]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["today"] (blocks-created-between-inputs :today-1159 :today-1201))
":today-HHMM and :today-HHMM resolve to correct datetime range")
(is (= ["today"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:today-115959 :today-120001]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["today"] (blocks-created-between-inputs :today-115959 :today-120001))
":today-HHMMSS and :today-HHMMSS resolve to correct datetime range")
(is (= ["today"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:today-115959999 :today-120000001]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["today"] (blocks-created-between-inputs :today-115959999 :today-120000001))
":today-HHMMSSmmm and :today-HHMMSSmmm resolve to correct datetime range")
(is (= ["today" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:today-1199 :today-9901]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["today" "tonight"] (blocks-created-between-inputs :today-1199 :today-9901))
":today-HHMM and :today-HHMM resolve to valid datetime ranges")
(is (= ["+1d" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-0d-1201 :+1d-2359]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "tonight"] (blocks-created-between-inputs :-0d-1201 :+1d-2359))
":-XT-HHMM and :+XT-HHMM resolve to correct datetime range")
(is (= ["+1d" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-0d-120001 :+1d-235959]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "tonight"] (blocks-created-between-inputs :-0d-120001 :+1d-235959))
":-XT-HHMMSS and :+XT-HHMMSS resolve to correct datetime range")
(is (= ["+1d" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-0d-120000001 :+1d-235959999]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "tonight"] (blocks-created-between-inputs :-0d-120000001 :+1d-235959999))
":-XT-HHMMSSmmm and :+XT-HHMMSSmmm resolve to correct datetime range")
(is (= ["+1d" "tonight"]
(sort
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-0d-1201 :+1d-2359]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]}))))
(is (= ["+1d" "tonight"] (blocks-created-between-inputs :-0d-1201 :+1d-2359))
":-XT-HHMM and :+XT-HHMM resolve to correct datetime range")
(is (= []
(map #(-> % :block/content string/split-lines first)
(custom-query {:inputs [:-0d-abcd :+1d-23.45]
:query '[:find (pull ?b [*])
:in $ ?start ?end
:where
[?b :block/content]
[?b :block/created-at ?timestamp]
[(>= ?timestamp ?start)]
[(<= ?timestamp ?end)]]})))
(is (= [] (blocks-created-between-inputs :-0d-abcd :+1d-23.45))
":-XT-HHMM and :+XT-HHMM will not reoslve with invalid time formats but will fail gracefully"))