jacekschae / learn-reitit-course-files

🎦 Learn Reitit course files for building Cheffy REST API

Home Page:https://www.learnreitit.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot run tests in lesson 27 recipes tests: "app" is null

kentbull opened this issue · comments

I am getting 1 error running tests near the middle of lesson 27, a NullPointerException saying the "app" is null.

It's referring to the app defined in the let binding of test-endpoint

(defn test-endpoint
  ([method uri]
   (test-endpoint method uri nil))
  ([method uri opts]
   (let [app (-> state/system :cheffy/app)
         request (app (-> (mock/request method uri)
                        (cond-> (:body opts) (mock/json-body (:body opts)))))]
     (update request :body (partial m/decode "application/json")))))

Error:

❯ lein test
2023-07-05 16:02:34.957:INFO::main: Logging initialized @977ms to org.eclipse.jetty.util.log.StdErrLog
Warning: environ value /path.../.jenv/versions/17.0 for key :java-home has been overwritten with /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home

lein test cheffy.recipes-test

lein test :only cheffy.recipes-test/recipes-tests

ERROR in (recipes-tests) (test_system.clj:12)
Uncaught exception, not in assertion.
expected: nil
  actual: java.lang.NullPointerException: Cannot invoke "clojure.lang.IFn.invoke(Object)" because "app" is null
 at cheffy.test_system$test_endpoint.invokeStatic (test_system.clj:12)
    cheffy.test_system$test_endpoint.invoke (test_system.clj:7)
    cheffy.test_system$test_endpoint.invokeStatic (test_system.clj:9)
    cheffy.test_system$test_endpoint.invoke (test_system.clj:7)

It seems like somehow integrant is not pulling in the "app" state correctly.

The same problem occurs when I run lein test in the increment folder for video 28.

I am able to run tests at the REPL. I run them by sending the forms to the REPL and then running the functions from the REPL.

How does your system look like at this point? When you evaluate state/system what do you get?

state/system looks like the following, with the jdbc URL redacted:

{:db/postgres #next.jdbc.default_options.DefaultOptions{
    :connectable "jdbc:postgresql://my_heroku_psql_instance_url",
    :options {:qualifier-fn #'camel-snake-kebab.core/->kebab-case,
                    :label-fn #'camel-snake-kebab.core/->kebab-case,
                    :builder-fn #'next.jdbc.result-set/as-kebab-maps,
                    :column-fn #'camel-snake-kebab.core/->snake_case,
                    :table-fn #'camel-snake-kebab.core/->snake_case}},
 :cheffy/app #object[clojure.lang.AFunction$1 0x78d6ec88 "clojure.lang.AFunction$1@78d6ec88"],
 :server/jetty #object[org.eclipse.jetty.server.Server 0x12be30ac "Server@12be30ac{STARTED}[9.4.28.v20200408]"]}

Well, that is only when running in the REPL. Are you referring to evaluating state/system from within the lein test call?

Well, this does make sense. I have been running tests from the REPL, which is a live running system, and there hasn't been any code written to initialize the application for the Leiningen tests. Maybe this is a non-issue. I can run the tests successfully from within the REPL, just not with lein test