Skip to content

Commit dd977d6

Browse files
committed
fix: regression test for a real .xlsx upload
1 parent 1794bab commit dd977d6

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

test/agiladmin/view_timesheet_test.clj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(ns agiladmin.view-timesheet-test
22
(:require [agiladmin.view-timesheet :as view-timesheet]
3+
[clojure.java.io :as io]
34
[hiccup.core :as hiccup]
45
[failjure.core]
6+
[me.raynes.fs :as fs]
57
[midje.sweet :refer :all]))
68

79
(fact "Timesheet upload form uses HTMX for progressive enhancement"
@@ -171,6 +173,30 @@
171173
(:body response) => (contains "This is a new timesheet, no historical information available to compare")
172174
(:body response) => (contains "Uploaded: upload.xlsx"))))
173175

176+
(fact "Timesheet upload accepts a real xlsx workbook fixture"
177+
(let [temp-root (.toFile (java.nio.file.Files/createTempDirectory "agiladmin-upload-test"
178+
(make-array java.nio.file.attribute.FileAttribute 0)))
179+
upload-path (str temp-root "/fixture-upload.xlsx")
180+
budgets-path (str temp-root "/budgets/")]
181+
(.mkdirs (io/file budgets-path))
182+
(io/copy (io/file "test/assets/2016_timesheet_Luca-Pacioli.xlsx")
183+
(io/file upload-path))
184+
(try
185+
(let [response (view-timesheet/upload
186+
{:params {:file {:size (.length (io/file upload-path))
187+
:filename "2016_timesheet_Luca-Pacioli.xlsx"
188+
:tempfile (io/file upload-path)}}}
189+
{:agiladmin {:budgets {:path budgets-path}}}
190+
{:name "Admin User"
191+
:role "admin"})]
192+
(:body response) => (contains "Uploaded: 2016_timesheet_Luca-Pacioli.xlsx")
193+
(:body response) => (contains "Contents of the new timesheet")
194+
(:body response) => (contains "Differences: old (to the left) and new (to the right)")
195+
(:body response) => (contains "This is a new timesheet, no historical information available to compare")
196+
(:body response) =not=> (contains "Error parsing timesheet"))
197+
(finally
198+
(fs/delete-dir temp-root)))))
199+
174200
(fact "Timesheet submit explains when the budgets directory is missing"
175201
(with-redefs [clojure.java.io/file
176202
(fn [path]

0 commit comments

Comments
 (0)