This clojure challenge is made up of 3 questions that reflect the learning you accumulated for the past week. Complete the following instructions:
-
Create a Gitlab repo to show the challenge code. When complete, send us the link to your challenge results.
-
Duration: About 4 hours
-
Install Cursive Plugin to Intellij and setup a clojure deps project. https://cursive-ide.com/userguide/deps.html
-
Enjoy!
Given the invoice defined in invoice.edn in this repo, use the thread-last ->> operator to find all invoice items that satisfy the given conditions. Please write a function that receives an invoice as an argument and returns all items that satisfy the conditions described below.
- Load invoice to play around with the function like this:
(def invoice (clojure.edn/read-string (slurp "invoice.edn")))
- An invoice item is a clojure map { โฆ } which has an :invoice-item/id field. EG.
{:invoice-item/id "ii2"
:invoice-item/sku "SKU 2"}
- An invoice has two fields :invoice/id (its identifier) and :invoice/items a vector of invoice items
- At least have one item that has :iva 19%
- At least one item has retention :ret_fuente 1%
- Every item must satisfy EXACTLY one of the above two conditions. This means that an item cannot have BOTH :iva 19% and retention :ret_fuente 1%.
Given the invoice defined in invoice.json found in this repo, generate an invoice that passes the spec ::invoice defined in invoice-spec.clj. Write a function that as an argument receives a file name (a JSON file name in this case) and returns a clojure map such that
(s/valid? ::invoice invoice) => true
where invoice represents an invoice constructed from the JSON.
Given the function subtotal defined in invoice-item.clj in this repo, write at least five tests using clojure core deftest that demonstrates its correctness. This subtotal function calculates the subtotal of an invoice-item taking a discount-rate into account. Make sure the tests cover as many edge cases as you can!