account-test.nv
· 1.8 KiB · Text
Raw
Playground
|# 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:
| 1 | |# First, we need to import conditional statements. #| |
| 2 | ||'@include' https://gist.nouveau.community/june/72f7794abbf64eb3890e2715d7e7789b/raw/HEAD/conditional.nv |
| 3 | |
| 4 | |# Let's try something. #| |
| 5 | ||:: test the happy path |
| 6 | :: log in as june |
| 7 | :: transfer 100 from 1234 to 5678 |
| 8 | :: log out |
| 9 | |
| 10 | ||:: test the sad path |
| 11 | :: log in as june |
| 12 | :: transfer 100 from 1234 to 5678 |
| 13 | :: log out |
| 14 | |
| 15 | |:: test the happy path| |
| 16 | :test modifiers: |
| 17 | . authorized user |
| 18 | . sufficient funds |
| 19 | |
| 20 | |:: test the sad path| |
| 21 | :test modifiers: |
| 22 | . unauthorized user |
| 23 | . insufficient funds |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |# Our abstract pseudocode. #| |
| 29 | |:: transfer $amount from $source to $destination :user: $user?| |
| 30 | :: ensure the user is authorized to use $source |
| 31 | :: ensure account $source has a minimum balance of $amount |
| 32 | :: start a database transaction |
| 33 | :: withdraw $amount from $source |
| 34 | :: deposit $amount into $dest |
| 35 | :: commit changes to the database |
| 36 | |
| 37 | |:: ensure the user is authorized to use $account| |
| 38 | :: if :: the user is not authorized to use $source :: then |
| 39 | :: unauthorized user |
| 40 | :: end |
| 41 | |
| 42 | |:: ensure account $account has a minimum balance of $amount| |
| 43 | :: if :: the balance of $account is lower than $amount :: then |
| 44 | :: insufficient funds |
| 45 | :: end |
| 46 | |
| 47 | |
| 48 | |# A set of mocks. #| |
| 49 | |:: log in as $user| :user: $user |
| 50 | |:: log out :user: $user| |
| 51 | |
| 52 | |:: the user is not authorized to use $account :test modifiers: unauthorized user | |
| 53 | |:: the balance of $source is lower than $amount :test modifiers: insufficient funds| |
| 54 | |:: the user is not authorized to use $account :test modifiers: authorized user | :: fail |
| 55 | |:: the balance of $source is lower than $amount :test modifiers: sufficient funds | :: fail |
| 56 | |
| 57 | |:: start a database transaction | |
| 58 | |:: withdraw $amount from $account| :withdraw succeeded: |
| 59 | |:: deposit $amount into $account | :deposit succeeded: |
| 60 | |:: commit changes to the database| :commit successful: |