<commit_before>(ns objective8.integration.api.up-down-votes
  (:require [midje.sweet :refer :all]
            [peridot.core :as p]
            [cheshire.core :as json]
            [objective8.core :as core]
            [objective8.utils :as utils]
            [objective8.integration.integration-helpers :as ih]
            [objective8.integration.storage-helpers :as sh]
            [objective8.middleware :as m]))

(def app (ih/test-context))

(facts "POST /api/v1/up-down-votes"
       (against-background
        (m/valid-credentials? anything anything anything) => true)
       (against-background
        [(before :contents (do (ih/db-connection)
                               (ih/truncate-tables)))
         (after :facts (ih/truncate-tables))]

        (fact "Upvotes an answer" ;; Make this generic
                     (let [{user-id :_id} (sh/store-a-user)
                           {global-id :global-id} (sh/store-an-answer)
                           {response :response} (p/request app (utils/path-for :api/post-up-down-vote)
                                                           :request-method :post
                                                           :content-type "application/json"
                                                           :body (json/generate-string {:created-by-id user-id
                                                                                        :global-id global-id
                                                                                        :vote-type :up}))]
                       (:status response) => 200))
        
        
        (fact "A second vote on the same entity is not permitted"
              (let [{global-id :global-id created-by-id :created-by-id} (sh/store-an-answer)
                           {response :response} (-> app
                                                    (p/request (utils/path-for :api/post-up-down-vote)
                                                               :request-method :post
                                                               :content-type "application/json"
                                                               :body (json/generate-string {:created-by-id created-by-id
                                                                                            :global-id global-id
                                                                                            :vote-type :up}))
                                                    (p/request (utils/path-for :api/post-up-down-vote)
                                                               :request-method :post
                                                               :content-type "application/json"
                                                               :body (json/generate-string {:created-by-id created-by-id
                                                                                            :global-id global-id
                                                                                            :vote-type :down})))]
                       (:status response) => 403
                       ;; Should also provide a reason for failure in the response
                       ))))<commit_msg>GR - wording in tests<commit_after>(ns objective8.integration.api.up-down-votes
  (:require [midje.sweet :refer :all]
            [peridot.core :as p]
            [cheshire.core :as json]
            [objective8.core :as core]
            [objective8.utils :as utils]
            [objective8.integration.integration-helpers :as ih]
            [objective8.integration.storage-helpers :as sh]
            [objective8.middleware :as m]))

(def app (ih/test-context))

(facts "POST /api/v1/up-down-votes"
       (against-background
        (m/valid-credentials? anything anything anything) => true)
       (against-background
        [(before :contents (do (ih/db-connection)
                               (ih/truncate-tables)))
         (after :facts (ih/truncate-tables))]

        (fact "A user can upvote an answer" ;; Make this generic
                     (let [{user-id :_id} (sh/store-a-user)
                           {global-id :global-id} (sh/store-an-answer)
                           {response :response} (p/request app (utils/path-for :api/post-up-down-vote)
                                                           :request-method :post
                                                           :content-type "application/json"
                                                           :body (json/generate-string {:created-by-id user-id
                                                                                        :global-id global-id
                                                                                        :vote-type :up}))]
                       (:status response) => 200))
        
        
        (fact "A second vote by the same user on the same entity is not permitted"
              (let [{global-id :global-id created-by-id :created-by-id} (sh/store-an-answer)
                           {response :response} (-> app
                                                    (p/request (utils/path-for :api/post-up-down-vote)
                                                               :request-method :post
                                                               :content-type "application/json"
                                                               :body (json/generate-string {:created-by-id created-by-id
                                                                                            :global-id global-id
                                                                                            :vote-type :up}))
                                                    (p/request (utils/path-for :api/post-up-down-vote)
                                                               :request-method :post
                                                               :content-type "application/json"
                                                               :body (json/generate-string {:created-by-id created-by-id
                                                                                            :global-id global-id
                                                                                            :vote-type :down})))]
                       (:status response) => 403
                       ;; Should also provide a reason for failure in the response
                       ))))
{'fraction_non_alphanumeric': 0.08777285910548008, 'fraction_numerical': 0.0039688597160738815, 'mean_word_length': 0.7504675394068928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 92, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1882089', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1250, 'n_words': 302}