LCOV - code coverage report
Current view: top level - matchscore/domain/event - entity.clj Coverage Total Hit
Test: lcov.info Lines: 96.6 % 29 28
Test Date: 2026-11-23 18:11:10 Functions: - 0 0

            Line data    Source code
       1            4 : (ns matchscore.domain.event.entity
       2              :   (:require
       3              :    [schemas.domain.events :as event-schemas]))
       4              : 
       5              : 
       6            4 : (def imported-sources
       7              :   "Sources whose events are copies of another federation's data."
       8           16 :   #{"psa" "fsu" "esf"})
       9              : 
      10              : 
      11            4 : (defn read-only?
      12              :  "True when nobody in Matchscore may change the event: copies of PSA, FSU and
      13              :   ESF events, and Rankedin events without an owner (the mirrors that
      14              :   `fsu-link-rankedin` imports). A Rankedin event imported for an organiser has
      15              :   `created-by` set and stays editable."
      16              :  [{:keys [source created-by]}]
      17           39 :  (let [source (some->
      18            4 :                 source
      19            4 :                 name)]
      20            4 :    (boolean
      21           62 :     (or (contains? imported-sources source) (and (= "rankedin" source) (nil? created-by))))))
      22              : 
      23              : 
      24            4 : (def updatable-fields
      25           80 :   [:datetime-start
      26              :    :datetime-end
      27              :    :state
      28              :    :visibility
      29              :    :club-id
      30              :    :club-ids
      31              :    :name
      32              :    :fee
      33              :    :fee-type
      34              :    :currency
      35              :    :duration
      36              :    :score-entry-mode
      37              :    :score-entry-default
      38              :    :timezone
      39              :    :language
      40              :    :description
      41              :    :sport-code
      42              :    :activity-type-code
      43              :    :settings])
      44              : 
      45              : 
      46            4 : (defn make-event
      47              :  "Creates a validated Event map."
      48              :  [data & [from-qualified]]
      49            8 :  (if from-qualified
      50           12 :    (event-schemas/make-event-record-from-qualified data)
      51            0 :    (event-schemas/make-event-record data)))
      52              : 
      53              : 
      54            4 : (defn- normalize-numerics
      55              :   [m]
      56            6 :   (reduce-kv
      57            3 :    (fn [acc k v]
      58           30 :     (assoc acc k (if (number? v) (bigdec v) v)))
      59            3 :    {}
      60            3 :    m))
      61              : 
      62              : 
      63            4 : (defn has-changes?
      64              :  "Returns true if any updatable field present in updates differs from existing."
      65              :  [existing updates]
      66            6 :  (not=
      67           18 :   (normalize-numerics (select-keys existing updatable-fields))
      68           27 :   (normalize-numerics (select-keys (merge existing updates) updatable-fields))))
      69              : 
      70              : 
      71            4 : (defn only-settings-changed?
      72              :  "True when the update changes the event's settings and nothing else. Settings (court
      73              :   plan, payments, match notifications) aren't shown in the Telegram main post, so such
      74              :   an update needs no re-post."
      75              :  [existing updates]
      76           49 :  (and (has-changes? existing updates) (not (has-changes? existing (dissoc updates :settings)))))
      77              : 
      78              : 
      79            4 : (defn merge-updates
      80              :  "Merges updatable fields from updates into existing event."
      81              :  [existing updates]
      82           21 :  (merge existing (select-keys updates updatable-fields)))
        

Generated by: LCOV version 2.0-1