我有一个迷你餐厅应用程序的状态数据结构如下
{:orders {:e4d55743-c964-48e8-9cd1-cb1cf9075617 [#:helloworld.restaurant{:name "chilly parotta", :quantity 3} #:helloworld.restaurant{:name "masal dosa", :quantity 2}]}, :menu {:kothu-parotta #:helloworld.restaurant{:name "Kothu Parotta", :price 9.5, :quantity 50}, :butter-naan #:helloworld.restaurant{:name "Butter Naan", :price 3, :quantity 50}, :paneer-butter-masala #:helloworld.restaurant{:name "Paneer Butter Masala", :price 9.5, :quantity 50}}}
我有一个函数用于更新订单中订货项目的菜单项,从库存中减去订货数量并返回新的菜单。我想验证
- 订单项目中的项目应在菜单中存在
- 在库存中的项目数量应大于订货数量
我有以下规格(注意:目前我尚未验证第2项)。当我运行这个时,对update-menu-item-for-order-item函数的调用没有验证我的断言。我在 fdef 规格中有何错误?
(s/def ::name string?)
(s/def ::price number?)
(s/def ::quantity number?)
(s/def ::order-item (s/keys :req [::name ::quantity]))
(s/def ::order-items (s/coll-of ::order-item))
(s/def ::menu-item (s/keys :req [::name ::price ::quantity]))
(s/def ::menu-item-id keyword?)
(s/def ::menu (s/map-of ::menu-item-id ::menu-item))
(s/fdef restaurant-save-menu :args (s/cat :menu-items (s/coll-of ::menu-item)))
(s/fdef update-menu-item-for-order-item
:args (s/and (s/cat :menu ::menu :order-item ::order-item)
#(contains? (:menu %) (keyword (slugify (::name (:order-item %))))))
:ret ::menu)
(stest/instrument `update-menu-item-for-order-item)
(stest/instrument `restaurant-save-menu)