我已经有一个数据结构,是我在迷你餐厅应用的状态
{: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函数不是验证我的谓词1。我在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)