Liking cljdoc? Tell your friends :D

donut.endpoint.test.harness

Includes:

  • Macros and a fixture for dealing with a system for the duration of a test
  • Helpers for composing and dispatching requests
  • read-body multimethod for parsing response bodies of different types (transit, json etc)
  • assertions that work with response segments
Includes:

* Macros and a fixture for dealing with a system for the duration of a test
* Helpers for composing and dispatching requests
* `read-body` multimethod for parsing response bodies of different types (transit, json etc)
* assertions that work with response segments
raw docstring

BaseRequestclj


comparison-entitiesclj

(comparison-entities test-ent-attrs resp-data)

Returns a set that can be used to test if test-ent-attrs is contained in a response

Returns a set that can be used to test if `test-ent-attrs` is
contained in a response
raw docstring

configured-valueclj

(configured-value config-key)

Look up a component instance that has path configured by the ::config component group

Look up a component instance that has path configured by the `::config`
component group
raw docstring

contains-entity?clj

(contains-entity? resp-data test-ent-attrs)

Request's response data has a map with key/value pairs identical to test-ent-attrs.

Request's response data has a map with key/value pairs identical to
`test-ent-attrs`.
raw docstring

content-type-requestcljmultimethod

Multi method that sets headers and encodes body for a content type

Multi method that sets headers and encodes body for a content type
raw docstring

Entitiesclj


Entityclj


handle-requestclj

(handle-request {:keys [path route-name route-params body-params query-params
                        content-type]
                 :as req-map})
(handle-request method
                path-or-route-name
                &
                [route-params body-params query-params])

Perform a request with the system's ring handler

Perform a request with the system's ring handler
raw docstring

handlerclj

(handler)

Retrieve endpoint handler from ds/system. Relies on :donut/http-handler being set in the system's ::ds/registry

Retrieve endpoint handler from ds/*system*. Relies on `:donut/http-handler`
being set in the system's `::ds/registry`
raw docstring

headersclj

(headers req headers)

Add all headers to request

Add all headers to request
raw docstring

Methodclj


prep-comparisonclj

(prep-comparison resp-entity test-ent-attrs)

When testing whether a response contains test-ent-attrs, we modify a response entity by:

  1. selecting only the keys that are present in test-ent-attrs. This allows us to do an = comparison that won't fail if the response entity contains attributes we don't want to test.

  2. Putting the result in a map to handle case where resp-entity is a record.

When testing whether a response contains `test-ent-attrs`, we modify
a response entity by:

1. selecting only the keys that are present in
   `test-ent-attrs`. This allows us to do an `=` comparison that won't
   fail if the response entity contains attributes we don't want to
   test.

2. Putting the result in a map to handle case where `resp-entity` is
   a record.
raw docstring

read-bodycljmultimethod

Decodes a response body, transforming it from JSON or whatever back into Clojure, which we love

Decodes a response body, transforming it from JSON or whatever back into
Clojure, which we love
raw docstring

Requestclj


requestclj

(request {:keys [path route-name route-params query-params content-type]
          :as req-map})
(request method path-or-route-name & [route-params body-params query-params])

Construct a ring.mock.request/request using your ds/system router to build a path. Adds content-type and accept headers.

Single-arity version takes a map with:

  :method HTTP method
    :path string; use if you don't want to use router to build path

:route-name used to build path :route-params map to populate your route's params, e.g. :book/id in /api/books {book/id} :query-params map to add a query string :body-params the data for your request

Construct a ring.mock.request/request using your ds/*system* router to
build a path. Adds content-type and accept headers.

Single-arity version takes a map with:

      :method HTTP method
        :path string; use if you don't want to use router to build path
  :route-name used to build path
:route-params map to populate your route's params,
              e.g. :book/id in /api/books {book/id}
:query-params map to add a query string
:body-params  the data for your request
raw docstring

Responseclj


responseclj

(response {:keys [path route-name route-params body-params query-params
                  content-type]
           :as req-map})
(response method path-or-route-name & [route-params body-params query-params])

Comp of handle-request and read-body; handles a request and reads the body.

Comp of handle-request and read-body; handles a request and reads the body.
raw docstring

response-entitiesclj

(response-entities resp-data)

Walk response data and return all entities from entity segments

Walk response data and return all entities from entity segments
raw docstring

route-pathclj

(route-path route-name)
(route-path route-name route-params)
(route-path route-name route-params query-params)

Construct a path like /api/v1/books/1. Can also build query string.

Construct a path like /api/v1/books/1. Can also build query string.
raw docstring

RouteIdentifierclj


routerclj

(router)

Retrieve endpoint router from ds/system. Relies on :donut/endpoint-router being set in the system's ::ds/registry

Retrieve endpoint router from ds/*system*. Relies on `:donut/endpoint-router`
being set in the system's `::ds/registry`
raw docstring

Segmentclj


Segmentsclj


systemclj

(system)

Get ds/system and throw when it's not set. Used by other helpers. Intention is to reduce the boilerplate of system retrieval in your tests.

Get ds/*system* and throw when it's not set. Used by other helpers. Intention
is to reduce the boilerplate of system retrieval in your tests.
raw docstring

test-harness-pluginclj

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close