<commit_before>(ns objective8.integration.db.activities
  (:require [midje.sweet :refer :all]
            [objective8.utils :as utils]
            [objective8.integration.integration-helpers :as ih]
            [objective8.integration.storage-helpers :as sh]
            [objective8.back-end.domain.activities :as activities]
            [objective8.back-end.domain.objectives :as objectives]))

(background
  [(before :contents (do (ih/db-connection)
                         (ih/truncate-tables)))
   (after :facts (ih/truncate-tables))])

(fact "an activity can be stored and retrieved"
      (let [{user-id :_id username :username} (sh/store-a-user)
            objective-data {:created-by-id user-id
                            :description "objective description"
                            :title "objective title"}
            stored-objective (objectives/store-objective! objective-data)
            stored-objective-timestamp (:_created_at stored-objective)
            stored-objective-url (str utils/host-url (:uri stored-objective))
            retrieved-objective (objectives/get-objective (:_id stored-objective))]
        (activities/store-activity! retrieved-objective) => {"@context" "http://www.w3.org/ns/activitystreams"
                                                             "@type" "Create"
                                                             "published" stored-objective-timestamp
                                                             "actor" {"@type" "Person"
                                                                      "displayName" username}
                                                             "object" {"@type" "Objective"
                                                                       "displayName" "objective title"
                                                                       "description" "objective description"
                                                                       "url" stored-objective-url}}))

(fact "about retrieving activities"<commit_msg>AB & RS | 127 | Update test names<commit_after>(ns objective8.integration.db.activities
  (:require [midje.sweet :refer :all]
            [objective8.utils :as utils]
            [objective8.integration.integration-helpers :as ih]
            [objective8.integration.storage-helpers :as sh]
            [objective8.back-end.domain.activities :as activities]
            [objective8.back-end.domain.objectives :as objectives]))

(background
  [(before :contents (do (ih/db-connection)
                         (ih/truncate-tables)))
   (after :facts (ih/truncate-tables))])

(fact "an activity can be stored"
      (let [{user-id :_id username :username} (sh/store-a-user)
            objective-data {:created-by-id user-id
                            :description "objective description"
                            :title "objective title"}
            stored-objective (objectives/store-objective! objective-data)
            stored-objective-timestamp (:_created_at stored-objective)
            stored-objective-url (str utils/host-url (:uri stored-objective))
            retrieved-objective (objectives/get-objective (:_id stored-objective))]
        (activities/store-activity! retrieved-objective) => {"@context" "http://www.w3.org/ns/activitystreams"
                                                             "@type" "Create"
                                                             "published" stored-objective-timestamp
                                                             "actor" {"@type" "Person"
                                                                      "displayName" username}
                                                             "object" {"@type" "Objective"
                                                                       "displayName" "objective title"
                                                                       "description" "objective description"
                                                                       "url" stored-objective-url}}))

(fact "activities can be retrieved"
{'fraction_non_alphanumeric': 0.09747204666990764, 'fraction_numerical': 0.004132231404958678, 'mean_word_length': 1.25109409190372, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3945668', 'n_tokens_mistral': 914, 'n_tokens_neox': 896, 'n_words': 195}