Skip to content

Commit

Permalink
Abstract out helper fn for timestamp react-query-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bendyorke committed Jan 20, 2023
1 parent a2efbdb commit 6d1f26f
Showing 1 changed file with 30 additions and 197 deletions.
227 changes: 30 additions & 197 deletions src/test/frontend/db/query_react_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))


Expand Down

0 comments on commit 6d1f26f

Please sign in to comment.