         token (e/login (s/context) "user1")
         _ (index/wait-until-indexed)
         tag (tags/save-tag token (tags/make-tag {:tag-key "tag1"}) [coll])
-        assert-tag-associated (fn [collection]
-                                (let [refs (search/find-refs :collection {:tag-key "tag1"})]
-                                  (is (nil? (:errors refs)))
-                                  (is (d/refs-match?
-                                        [collection]
-                                        (search/find-refs :collection {:tag-key "tag1"})))))
+        assert-tag-associated (partial assert-tag-associated-with-query nil {:tag-key "tag1"})
         assert-tag-not-associated (fn []
                                     (let [refs (search/find-refs :collection {:tag-key "tag1"})]
                                       (is (nil? (:errors refs)))

        token (e/login (s/context) "user1")
        prov3-token (e/login (s/context) "prov3-user" ["groupguid1"])
        {:keys [concept-id]} (tags/create-tag token tag)
        assert-tag-associated (fn [expected-colls query]
                                (is (d/refs-match?
                                      expected-colls
                                      (search/find-refs :collection
                                                        (assoc query
                                                               :token prov3-token
                                                               :page_size 30)))))]
    (index/wait-until-indexed)
    ;; Associate the tag with every collection
    (tags/associate-by-query prov3-token tag-key {:or [{:provider "PROV1"}

    (testing "Disassociate using query that finds nothing"
      (let [{:keys [status]} (tags/disassociate-by-query token tag-key {:provider "foo"})]
        (is (= 200 status))
        (assert-tag-associated all-colls)))

    (testing "ACLs are applied to collections found"
      ;; None of PROV3's collections are visible to normal users
      (let [{:keys [status]} (tags/disassociate-by-query token tag-key {:provider "PROV3"})]
        (is (= 200 status))
        (assert-tag-associated all-colls)))

    (testing "Successfully disassociate tag with collections"
      (let [{:keys [status]} (tags/disassociate-by-query token tag-key {:provider "PROV1"})]
        (is (= 200 status))
        (assert-tag-associated (concat all-prov2-colls all-prov3-colls)))

      ;; disassociate tag again is OK. Since there is no existing tag association, it does nothing.
      (let [{:keys [status]} (tags/disassociate-by-query token tag-key {:provider "PROV1"})]
        (is (= 200 status))
        (assert-tag-associated (concat all-prov2-colls all-prov3-colls))))))

(deftest disassociate-tags-with-collections-by-concept-ids-test
  ;; Grant all collections in PROV1 and 2
