以下是我迷你餐厅应用的状态数据结构
{: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 spec并未验证我的谓词1。我在fdef spec中犯了什么错误?
(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)