|# First, we need to import conditional statements. #| ||'@include' https://gist.nouveau.community/june/72f7794abbf64eb3890e2715d7e7789b/raw/HEAD/conditional.nv |# Let's try something. #| ||:: test the happy path :: log in as june :: transfer 100 from 1234 to 5678 :: log out ||:: test the sad path :: log in as june :: transfer 100 from 1234 to 5678 :: log out |:: test the happy path| :test modifiers: . authorized user . sufficient funds |:: test the sad path| :test modifiers: . unauthorized user . insufficient funds |# Our abstract pseudocode. #| |:: transfer $amount from $source to $destination :user: $user?| :: ensure the user is authorized to use $source :: ensure account $source has a minimum balance of $amount :: start a database transaction :: withdraw $amount from $source :: deposit $amount into $dest :: commit changes to the database |:: ensure the user is authorized to use $account| :: if :: the user is not authorized to use $source :: then :: unauthorized user :: end |:: ensure account $account has a minimum balance of $amount| :: if :: the balance of $account is lower than $amount :: then :: insufficient funds :: end |# A set of mocks. #| |:: log in as $user| :user: $user |:: log out :user: $user| |:: the user is not authorized to use $account :test modifiers: unauthorized user | |:: the balance of $source is lower than $amount :test modifiers: insufficient funds| |:: the user is not authorized to use $account :test modifiers: authorized user | :: fail |:: the balance of $source is lower than $amount :test modifiers: sufficient funds | :: fail |:: start a database transaction | |:: withdraw $amount from $account| :withdraw succeeded: |:: deposit $amount into $account | :deposit succeeded: |:: commit changes to the database| :commit successful: