claro.middleware.mock

Generic I/O mocking middlewares.

wrap-mock

(wrap-mock engine class mock-fn & more)

Middleware that will prevent calling of resolve! or resolve-batch! for the given class, but instead use the given mock-fn to compute a result for each Resolvable. mock-fn takes the resolvable in question, as well as the environment as parameters.

Transformations declared by implementing the Transform protocol will still be performed.

For example, to mock resolution of Person records:

(def run-engine
  (-> (engine/engine)
      (wrap-mock
        Person
        (fn [{:keys [id]} env]
          {:id id
           :name (str "Person #" id)}))))

Note: Multiple class/mock-fn pairs can be given.

wrap-mock-result

(wrap-mock-result engine class mock-fn & more)

Middleware that will prevent calling of resolve! or resolve-batch! for the given class, but instead use the given mock-fn to compute a result for each Resolvable. mock-fn takes the resolvable in question, as well as the environment as parameters.

Transformations declared by implementing the Transform protocol will be ignored, so this really has to return the eventual result.

For example, to mock resolution of Person records:

(def run-engine
  (-> (engine/engine)
      (wrap-mock-result
        Person
        (fn [{:keys [id]} env]
          {:id      id
           :name    (str "Person #" id)
           :friends (map ->Person (range id))}))))

Note: Multiple class/mock-fn pairs can be given.