 (def valid-change-feature
   {:action :change
    :dataset "known-dataset"
-   :collection "collection1"
+   :collection "collection-1"
    :id "valid-feature"
    :validity default-validity
    :current-validity default-validity
    :geometry {:type "dummy"}
    :attributes {:field2 "test"}})
+
+(defn- init-with-feature [persistence {:keys [dataset collection id action validity]}]
+  (pers/create-stream persistence dataset collection id)
+  (pers/append-to-stream persistence nil action dataset collection id validity nil nil))
 
 (deftest inititialized-processor
   (let [processor (processor (create-persistence) (create-projectors 2))]

      (testing (str name " should break")
        (is (not (nil? processed)))
        (is (:invalid? processed))
        (is (= 0 @(-> processor :persistence :appends-n)))
        (is (= 0 @(-> processor :projectors first :features-n))) ; no new features
        (is (= 0 @(-> processor :projectors first :changes-n))))
      )))

          invalid-new-feature (transform valid-new-feature)
          processed (first(consume processor invalid-new-feature))]
      (testing (str name " should break")
        (is (= false (nil? processed)))
        (is (:invalid? processed))
        (is (= 0 (-> processor :persistence :streams-n deref)))
        (is (= 0 (-> processor :persistence :events-n deref)))
        (is (= 0 @(-> processor :projectors first :features-n)))))))

(deftest ok-change-feature
  (let [processor (create-processor)
        persistence (:persistence processor)
        _ (init-with-feature persistence valid-new-feature)
        processed (first (consume processor valid-change-feature))]
    (is (= false (nil? processed)))
    (is (not (:invalid? processed)) (str (:invalid-reasons processed)))
    (is (= 1 (-> processor :persistence :streams-n deref))) ; no new stream
    (is (= 2 (-> processor :persistence :events-n deref)))
    (is (= 0 @(-> processor :projectors first :features-n))) ; no new features
    (is (= 1 @(-> processor :projectors first :changes-n)))
    ))
