mirror of
https://github.com/mruwnik/chicken-master.git
synced 2025-06-08 13:24:42 +02:00
48 lines
2.6 KiB
Clojure
48 lines
2.6 KiB
Clojure
(ns chicken-master.sutendar-test
|
|
(:require
|
|
[chicken-master.calendar :as sut]
|
|
[cljs.test :refer-macros [deftest is testing run-tests]]))
|
|
|
|
|
|
(deftest format-raw-order-test
|
|
(testing "no products"
|
|
(is (= (sut/format-raw-order {}) {:who {:name nil :id nil} :notes nil :products {}}))
|
|
(is (= (sut/format-raw-order {"who" "bla" "notes" "ble"})
|
|
{:who {:name "bla" :id nil} :notes "ble" :products {}}))
|
|
(is (= (sut/format-raw-order {"who" "bla" "who-id" "123" "notes" "ble"})
|
|
{:who {:name "bla" :id 123} :notes "ble" :products {}})))
|
|
|
|
(testing "decent products"
|
|
(is (= (sut/format-raw-order {"who" "bla" "who-id" "123" "notes" "ble"
|
|
"product-eggs" "eggs" "amount-eggs" "12"
|
|
"product-cows" "cows" "amount-cows" "22"
|
|
"product-milk" "milk" "amount-milk" "3.2"})
|
|
{:who {:name "bla" :id 123} :notes "ble" :products {:eggs 12 :cows 22 :milk 3.2}})))
|
|
|
|
(testing "duplicate products"
|
|
(is (= (sut/format-raw-order {"who" "bla" "who-id" "123" "notes" "ble"
|
|
"product-eggs" "eggs" "amount-eggs" "12"
|
|
"product-eggs1" "eggs" "amount-eggs1" "12"
|
|
"product-cows1" "cows" "amount-cows1" "1"
|
|
"product-cows2" "cows" "amount-cows2" "2"
|
|
"product-milk" "milk" "amount-milk" "3.2"})
|
|
{:who {:name "bla" :id 123} :notes "ble" :products {:eggs 24 :cows 3 :milk 3.2}})))
|
|
|
|
(testing "unselected are ignored"
|
|
(is (= (sut/format-raw-order {"who" "bla" "who-id" "123" "notes" "ble"
|
|
"product-eggs" "eggs" "amount-eggs" "12"
|
|
"product-bad1" "" "amount-bad1" "12"
|
|
"product-bad2" "" "amount-bad2" "1"
|
|
"product-milk" "milk" "amount-milk" "3.2"
|
|
"product-bad3" "" "amount-bad3" "2"})
|
|
{:who {:name "bla" :id 123} :notes "ble" :products {:eggs 12 :milk 3.2}})))
|
|
|
|
(testing "items with 0 are removed"
|
|
(is (= (sut/format-raw-order {"who" "bla" "who-id" "123" "notes" "ble"
|
|
"product-eggs" "eggs" "amount-eggs" "12"
|
|
"product-eggs1" "eggs" "amount-eggs1" "0"
|
|
"product-cow" "cow" "amount-cow" "0"
|
|
"product-milk" "milk" "amount-milk" "3.2"})
|
|
{:who {:name "bla" :id 123} :notes "ble" :products {:eggs 12 :milk 3.2}}))))
|
|
(run-tests)
|