(ns ajet.chat.shared.storage-unit-test
  (:require [clojure.test :refer [deftest testing is]]
            [ajet.chat.shared.storage :as storage]))

;;; ---------------------------------------------------------------------------
;;; validate-upload! tests
;;; ---------------------------------------------------------------------------

(deftest validate-upload-valid-jpeg
  (is (nil? (storage/validate-upload! "image/jpeg" 1024))))

(deftest validate-upload-valid-png
  (is (nil? (storage/validate-upload! "image/png" (* 5 1024 1024)))))

(deftest validate-upload-invalid-content-type
  (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Invalid content type"
        (storage/validate-upload! "application/pdf" 1024))))

(deftest validate-upload-too-large
  (is (thrown-with-msg? clojure.lang.ExceptionInfo #"File too large"
        (storage/validate-upload! "image/png" (* 11 1024 1024)))))

;;; ---------------------------------------------------------------------------
;;; storage-key tests
;;; ---------------------------------------------------------------------------

(deftest storage-key-format
  (let [id "abc-123"
        fname "photo.jpg"
        result (storage/storage-key id fname)]
    (is (= "attachments/abc-123/photo.jpg" result))))
