Testing business logic

Let's write a test that verifies we're able to get the right customer by its id. In Customer.re, there is a function called getCustomer that accepts an array of customers, and imperatively gets the id by calling getId. The getId function accepts a pathname that exists outside the scope of getCustomer:

let getCustomer = customers => {  let id = getId(pathname);  customers |> Js.Array.find(customer => customer.CustomerType.id == id);};

Right away, we notice that this is less than ideal. It would be much better if getCustomer accepted an array of customers and an id, and focused on getting the customer by their id. Otherwise, it will be harder to write a test just for getCustomer.

So, we refactor getCustomer to also accept ...

Get ReasonML Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.