I have a function something like this
def update do
{:ok, users} = Restaurant.load_user_transactions()
users
|> Enum.map(&load_restaurant_order/1)
|> Enum.map(&update_order/1)
end
So first here load_user_transactions() will load all the id for the users. Then with that list of users, I’m loading the corresponding restaurant orders and in the end, I’m updating some fields in the users table.
So I have written a unit test case like this
test "update" do
users = [
%User{
id: 1,
name: "max",
description: "maaxx"
}
]
expect(UserDomainMock, :load_user_transactions, fn -> {:ok, users} end)
restaurants = RestaurantMock.payment_order()
expect(RestaurantMock, :load_restaurant_order, fn _ -> {:ok, restaurants} end)
expect(RestaurantMock, :update_order, fn _, _ -> {:ok, nil} end)
assert TransactionUpdate.load()
end
1 . here load_user_transactions
expect list of users id.
2. Then the id will be passed on load_restaurant_order
3. Then it will update some fields here update_order