Introducing the credit approval use case

In this section, we'll introduce a sample use case related to credit approval. Suppose that you are developing a system that has the ability to open a new credit card account for a customer upon a successful background check. You may create a Julia module that has the following structure:

module CreditApproval

# primary function to open an account
function open_account(first_name, last_name, email) end

# supportive functions
function check_background(first_name, last_name) end
function create_account(first_name, last_name, email) end
function notify_downstream(account_number) end

end

Now, let's implement each of the functions. We'll start with the check_background function, which just logs the event and returns true, meaning that the background check is successful. Consider the following code:

# Background check. 
# In practice, we would call a remote service for this.
# For this example, we just return true.
function check_background(first_name, last_name)
println("Doing background check for $first_name $last_name")
return true
end

The create_account function is similar to this. In this case, the expected behavior is to return an account number, that is, an integer value that refers to the account that has just been created. For this example, we just return a hardcoded value of 1, as follows:

# Create an account.
# In practice, we would actually create a record in database.
# For this example, we return an account number of 1.
function create_account(first_name, last_name, email)
println("Creating an account for $first_name $last_name")
return 1
end

The notify_customer function is supposed to send an email to the customer. For testing purposes, we will just log the event; nothing needs to be returned:

# Notify downstream system by sending a message.
# For this example, we just print to console and returns nothing.
function notify_downstream(account_number)
println("Notifying downstream system about new account $account_number")
return nothing
end

Finally, the open_account function is as follows:

# Open a new account. 
# Returns `:success` if account is created successfully.
# Returns `:failure` if background check fails.
function open_account(first_name, last_name, email)
check_background(first_name, last_name) || return :failure
account_number = create_account(first_name, last_name, email)
notify_downstream(account_number)
return :success
end

This is the FUT in our example. The logic involves checking the background for a customer and creating an account and notifying downstream about the new account if the background check is successful.

Let's think about how to test the open_account function. The obvious thing that needs our attention is the background check code. More specifically, we expect two possible execution paths when the background check is successful and when the background check fails. If we need to cover both cases, then we need to be able to simulate the different return values of the check_background function. We will do that next with a stub.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.153.69