<commit_before>(ns asid.test.asid-facts
  (:use midje.sweet
        asid)

  (:require [clojure.data.json :as json]
            [ring.mock.request :as mr])

  (:require [asid.graph :as ag]
            [asid.trust-pool :as tp]
            [asid.trust-pool-repository :as tpr]
            [asid.wallet :as w]
            [asid.wallet.repository :as wr]))

(fact "GET /"
  (:status (app (mr/request :get "/"))) => 200)

(fact "POST /identity"
  (let [req (app (-> (mr/request :post "/identity")
                     (mr/body "sample-id-seed")))]
    (:status req) => 201
    (-> req :headers (get "Location")) => #"\/[a-z0-9-]+$")
  (let [req (app (-> (mr/request :post "/identity")
                     (mr/body "")))]
    (:status req) => 400))

(fact "GET /<wallet-id>"
  (let [req (app (-> (mr/request :get "/bada-bada-bada-1d")
                     (mr/header "Accept" "application/vnd.org.asidentity.wallet+json")))]
    (:status req) => 404
    (:body req) => "Not found.")
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        req (app (-> (mr/request :get (w/uri wallet))
                     (mr/header "Accept" "text/html, application/xml")))]
    (:status req) => 200)
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        req (app (-> (mr/request :get (w/uri wallet))
                     (mr/header "Accept" "application/vnd.org.asidentity.introduction+json")))
        intro-doc (json/read-str (:body req))]
    (:status req) => 200
    (-> intro-doc (get "bag")) => nil?))

(fact "POST /<wallet-id>/bag"
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        req (app (mr/request :post (w/bag-uri wallet) {"key" "key1" "value" "new-value"}))]
    (:status req) => 200))

(fact "POST /<wallet-id>/trustpool"
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        req (app (-> (mr/request :post (w/trustpool-uri wallet)
                                 (json/write-str {:name "hello" :challenge ["name"]}))
                     (mr/header "Content-Type" "application/vnd.org.asidentity.trust-pool+json")))]
    (:status req) => 201))

(fact "GET /<wallet-id>/trustpool/<pool-id>"
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        pool (tpr/save (tp/new-trust-pool "pool" ["name" "dob"]) repo)]
    (ag/trustpool pool wallet)
    (let [req (app (-> (mr/request :get (tp/uri wallet pool))
                       (mr/header "Accept" "application/vnd.org.asidentity.trust-pool+json")))]
      (:status req) => 200)
    (let [req (app (-> (mr/request :get (str (w/uri wallet) "/trustpool/bada-bada-bada-1d"))
                       (mr/header "Accept" "application/vnd.org.asidentity.trust-pool+json")))]
      (:status req) => 404
      (:body req) => "Not found.")))

<commit_msg>It's actually a response, not a request.<commit_after>(ns asid.test.asid-facts
  (:use midje.sweet
        asid)

  (:require [clojure.data.json :as json]
            [ring.mock.request :as mr])

  (:require [asid.graph :as ag]
            [asid.trust-pool :as tp]
            [asid.trust-pool-repository :as tpr]
            [asid.wallet :as w]
            [asid.wallet.repository :as wr]))

(fact "GET /"
  (:status (app (mr/request :get "/"))) => 200)

(fact "POST /identity"
  (let [resp (app (-> (mr/request :post "/identity")
                      (mr/body "sample-id-seed")))]
    (:status resp) => 201
    (-> resp :headers (get "Location")) => #"\/[a-z0-9-]+$")
  (let [resp (app (-> (mr/request :post "/identity")
                      (mr/body "")))]
    (:status resp) => 400))

(fact "GET /<wallet-id>"
  (let [resp (app (-> (mr/request :get "/bada-bada-bada-1d")
                      (mr/header "Accept" "application/vnd.org.asidentity.wallet+json")))]
    (:status resp) => 404
    (:body resp) => "Not found.")
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        resp (app (-> (mr/request :get (w/uri wallet))
                      (mr/header "Accept" "text/html, application/xml")))]
    (:status resp) => 200)
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        resp (app (-> (mr/request :get (w/uri wallet))
                      (mr/header "Accept" "application/vnd.org.asidentity.introduction+json")))
        intro-doc (json/read-str (:body resp))]
    (:status resp) => 200
    (-> intro-doc (get "bag")) => nil?))

(fact "POST /<wallet-id>/bag"
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        resp (app (mr/request :post (w/bag-uri wallet) {"key" "key1" "value" "new-value"}))]
    (:status resp) => 200))

(fact "POST /<wallet-id>/trustpool"
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        resp (app (-> (mr/request :post (w/trustpool-uri wallet)
                                  (json/write-str {:name "hello" :challenge ["name"]}))
                      (mr/header "Content-Type" "application/vnd.org.asidentity.trust-pool+json")))]
    (:status resp) => 201))

(fact "GET /<wallet-id>/trustpool/<pool-id>"
  (let [wallet (wr/save (w/new-wallet "seed") repo)
        pool (tpr/save (tp/new-trust-pool "pool" ["name" "dob"]) repo)]
    (ag/trustpool pool wallet)
    (let [resp (app (-> (mr/request :get (tp/uri wallet pool))
                        (mr/header "Accept" "application/vnd.org.asidentity.trust-pool+json")))]
      (:status resp) => 200)
    (let [resp (app (-> (mr/request :get (str (w/uri wallet) "/trustpool/bada-bada-bada-1d"))
                        (mr/header "Accept" "application/vnd.org.asidentity.trust-pool+json")))]
      (:status resp) => 404
      (:body resp) => "Not found.")))
{'fraction_non_alphanumeric': 0.2046943231441048, 'fraction_numerical': 0.012736535662299854, 'mean_word_length': 2.3174411587205794, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2736594', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1924, 'n_words': 462}