Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misled by using martian-test with martian-http/bootstrap #188

Open
MutableR opened this issue Sep 20, 2023 · 2 comments
Open

Misled by using martian-test with martian-http/bootstrap #188

MutableR opened this issue Sep 20, 2023 · 2 comments

Comments

@MutableR
Copy link

MutableR commented Sep 20, 2023

I've reviewed both the documentation and the blog, but unfortunately, they didn't prove to be helpful for my case.

Is there a possibility of enhancing the documentation by including examples of tests with martian-http/bootstrap? Alternatively, if this isn't feasible, could you please offer additional information to clarify this matter?

@oliyh
Copy link
Owner

oliyh commented Sep 21, 2023

Hi,

The code on the test readme looks like this:

(-> (martian/bootstrap-swagger "https://api.com" user-api-swagger-definition)
      (martian-test/respond-with-generated {:load-user :success}))

The respond-with-generated looks for and replaces the perform-request interceptor that comes from the various martian-http packages and also removes body (de)serialisation, so it should not matter if you use martian-http or martian.core from that perspective.

Could you share some code and tell me about the behaviour / errors you are seeing?

Cheers

@MutableR
Copy link
Author

MutableR commented Sep 21, 2023

The primary issue is that my client doesn't use Swagger, and I rely on routes for my API. Is there a way to test this scenario, or does the library not support it?

This situation is not unique to my current project; in fact, many of my projects lack Swagger, and I employ this approach.

Code examples:

(defn bootstrap
  [token store & {:keys []}]
  (martian-http/bootstrap
   (base-url store)
   (routes/prepare-routes)
   {:credentials {:token token}
    :interceptors (concat martian/default-interceptors
                          [(add-auth-headers)
                           (ignore-invalid-cookies)
                           interceptors/default-encode-body
                           (decode-body)
                           martian-http/perform-request])}))
(ns shopify.impl.routes
  (:require
   [schema.core :as s]))


(def orders
  [{:route-name :get-orders
    :method :get
    :path-parts ["/orders.json"]
    :query-schema {(s/optional-key :page_info) s/Str
                   (s/optional-key :financial_status) s/Str
                   (s/optional-key :status) s/Str
                   (s/optional-key :limit) s/Int
                   (s/optional-key :created_at_min) s/Str
                   (s/optional-key :created_at_max) s/Str
                   (s/optional-key :order) s/Str}}])


(def fulfillment
  [{:route-name :get:fulfillment-order!
    :method :get
    :path-parts ["/orders/" :order-id "/fulfillment_orders.json"]
    :path-schema {:order-id s/Int}}
   {:route-name :create-fulfillment
    :method :post
    :path-parts ["/fulfillments.json"]
    :body-schema {:body {:fulfillment {:message                         s/Str
                                       :notify_customer                 s/Bool
                                       :tracking_info                   {:number  s/Str
                                                                         :url     s/Str}
                                       :line_items_by_fulfillment_order [{:fulfillment_order_id s/Int}]}}}}])


(def routes
  [orders fulfillment])

(defn prepare-routes
  []
  (reduce into [] routes))

I'm not encountering any errors (just get nil because haven't Swagger I think), but I'm struggling to grasp how to implement this for my specific situation.

I would greatly appreciate your assistance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants