|
16 | 16 | Must be real image name from `test-resources` folder."
|
17 | 17 | "1.png")
|
18 | 18 |
|
| 19 | +(def ^:private test-image-name-without-extension |
| 20 | + "Image name to be uploaded. |
| 21 | +
|
| 22 | + This image without extension to check `extract-file-extension` function." |
| 23 | + "2") |
| 24 | + |
19 | 25 | (deftest uuid-test
|
20 | 26 | (testing "Test `uuid` function returns unique string every time"
|
21 | 27 | (let [first-uuid (sut/uuid)
|
|
37 | 43 | (testing "Test POST /upload successfully"
|
38 | 44 | (with-redefs [sut/write-file (spy/spy)
|
39 | 45 | sut/uuid (spy/stub test-uuid)]
|
40 |
| - (let [app (test-app/api-routes-with-auth) |
| 46 | + (let [file (io/file (io/resource test-img-name)) |
| 47 | + app (test-app/api-routes-with-auth) |
| 48 | + response (app (-> (mock/request :post "/api/upload") |
| 49 | + (merge (mp/build {:file file})))) |
| 50 | + body (test-app/parse-body (:body response)) |
| 51 | + [[f name]] (spy/calls sut/write-file)] |
| 52 | + (is (= 200 (:status response))) |
| 53 | + (is (= {:url (str (config/base-url td/test-config) "/img/" test-uuid ".png")} body)) |
| 54 | + (is (= (str (config/storage-path td/test-config) "img/" test-uuid ".png") name)) |
| 55 | + (is (= (slurp f) (slurp file)))))) |
| 56 | + |
| 57 | + (testing "test POST /upload successfully without file extension" |
| 58 | + (with-redefs [sut/write-file (spy/spy) |
| 59 | + sut/uuid (spy/stub test-uuid)] |
| 60 | + (let [file (io/file (io/resource test-image-name-without-extension)) |
| 61 | + app (test-app/api-routes-with-auth) |
41 | 62 | response (app (-> (mock/request :post "/api/upload")
|
42 |
| - (merge (mp/build {:file (io/file (io/resource test-img-name))})))) |
| 63 | + (merge (mp/build {:file file})))) |
43 | 64 | body (test-app/parse-body (:body response))
|
44 |
| - [[_ name]] (spy/calls sut/write-file)] |
| 65 | + [[f name]] (spy/calls sut/write-file)] |
45 | 66 | (is (= 200 (:status response)))
|
46 |
| - (is (= {:url (str (config/base-url td/test-config) "/img/" test-uuid "_" test-img-name)} body)) |
47 |
| - (is (= (str (config/storage-path td/test-config) "img/" test-uuid "_" test-img-name) name))))) |
| 67 | + (is (= {:url (str (config/base-url td/test-config) "/img/" test-uuid)} body)) |
| 68 | + (is (= (str (config/storage-path td/test-config) "img/" test-uuid) name)) |
| 69 | + (is (= (slurp f) (slurp file)))))) |
48 | 70 |
|
49 | 71 | (testing "Test POST /upload with invalid request"
|
50 | 72 | (with-redefs [sut/write-file (spy/spy)]
|
|
0 commit comments