; Follow-up — notification feed over an inbox. (feed-test name got expected)

; an inbox is a stream of {:to receiver :activity act} events
(define mk-ev (fn (to act) {:activity act :to to}))

(define
  IB
  (feed/stream
    (list
      (mk-ev "alice" (feed/activity "bob" "like" "P" 10 (list)))
      (mk-ev "alice" (feed/activity "carol" "like" "P" 20 (list)))
      (mk-ev "alice" (feed/activity "dave" "reply" "Q" 30 (list)))
      (mk-ev "bob" (feed/activity "eve" "like" "R" 40 (list))))))

; ---------- raw notifications ----------

(feed-test
  "alice notification count"
  (feed/count (feed/notifications IB "alice"))
  3)
(feed-test
  "bob notification count"
  (feed/count (feed/notifications IB "bob"))
  1)
(feed-test
  "zoe no notifications"
  (feed/count (feed/notifications IB "zoe"))
  0)

; ---------- verb filtering ----------

(feed-test
  "alice likes only"
  (feed/count (feed/notify-verbs IB "alice" (list "like")))
  2)
(feed-test
  "alice replies only"
  (feed/count (feed/notify-verbs IB "alice" (list "reply")))
  1)
(feed-test
  "alice like+reply"
  (feed/count (feed/notify-verbs IB "alice" (list "like" "reply")))
  3)
(feed-test
  "alice follow (none)"
  (feed/count (feed/notify-verbs IB "alice" (list "follow")))
  0)

; ---------- digest ----------

(define dig (feed/notify-digest IB "alice"))

(feed-test "digest group count" (len dig) 2)
(feed-test
  "digest sorted by key (like|P before reply|Q)"
  (map (fn (g) (get g :object)) dig)
  (list "P" "Q"))
(feed-test
  "like group actors"
  (get (nth dig 0) :actors)
  (list "bob" "carol"))
(feed-test "like group count" (get (nth dig 0) :count) 2)
(feed-test "like group verb" (get (nth dig 0) :verb) "like")
(feed-test "reply group count" (get (nth dig 1) :count) 1)
(feed-test
  "reply group actors"
  (get (nth dig 1) :actors)
  (list "dave"))
(feed-test "empty digest for zoe" (feed/notify-digest IB "zoe") (list))
