Customer details specificationλ︎
Create a new file for the specifications,
src/practicalli/banking_specifications.cljc, with the namespace
clojure.spec.alpha library with an alias of
Define basic customer detailsλ︎
Define a specification for the customer-details map, composed of all the required keys that define a customer.
The bank legally requires specific information about a customer in order to add them as an account holder
INFO::A more detailed email specificationλ︎
Use a regular expression to define the syntax of an email address, eg. email@example.com
This specification will require a custom generator
A residential address is made from several pieces of information and is defined as a composite specification, from several specifications.
A social security number specification is also a candidate for a composite specification. Social security numbers may take different forms and even have different names in different countries, eg. the USA SSN is a nine-digit number in the format "AAA-GG-SSSS"
In the UK the social security number is called the National Insurance number and is of the form QQ123456C
INFO::Detailed social security numbers would check the different formsλ︎
Predicate functions can be defined to check for the size of the different social security forms.
These specifications required a custom generator in order to produce correct data each time.
A general social security specification can now be defined, with one of any of the country specific specifications
Composing the customer details specificationλ︎
A customer details specification is a hash-map of key value pairs. The keys are the specifications that have just been defined.
spec/keys creates a specification for a hash-map with required and optional keys.
spec/keys also includes a check for a map, so no explicit check for a map is required.