https://github.com/angristan/go-wallet-bdd-test
School assignment: Simple wallet using Behavior-driven development
https://github.com/angristan/go-wallet-bdd-test
Last synced: 7 months ago
JSON representation
School assignment: Simple wallet using Behavior-driven development
- Host: GitHub
- URL: https://github.com/angristan/go-wallet-bdd-test
- Owner: angristan
- Created: 2021-02-14T11:57:57.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-14T12:06:40.000Z (over 4 years ago)
- Last Synced: 2025-03-15T15:45:01.342Z (7 months ago)
- Language: Go
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple wallet using Behavior-driven development
## Assignement
> Given a Wallet containing Stocks, build a function that compute the value of wallet in a currency.
>
> The Stocks have a quantity and a StockType. The StockType can be for example petroleum, Euros, bitcoins and Dollars.
>
>To value the portfolio in a Currency you can use external api to provide rate exchanges## Running tests
This program is using Cucumber for Golang: [Godog](https://github.com/cucumber/godog).
Install godog:
```shell
go get github.com/cucumber/godog/cmd/godog@v0.11.0
```Run Gherking scenarios:
```shell
godog
```### Output
```
➜ wallet git:(main) godog
Feature: get wallet value
Get value of all assets in walletScenario Outline: Get wallet value in target currency with specified rate # features/get_wallet_value.feature:4
Given I have these assets: # wallet_test.go:28 -> iHaveTheseAssets
| type | ticker | quantity |
| stock | TSLA | 1.1 |
| stock | AAPL | 10 |
And "TSLA" is worth 1000 USD # wallet_test.go:62 -> setAssetPriceUSD
And "AAPL" is worth 130 USD # wallet_test.go:62 -> setAssetPriceUSD
And "" rate is # wallet_test.go:81 -> currencyRateIs
Then the total value should be "" # wallet_test.go:68 -> theTotalValueShouldBeExamples:
| Currency | Rate | Value |
| EUR | 0.83 | 1992 |
| JPY | 104.95 | 251880 |
| USD | 1.0 | 2400 |Scenario: Get wallet value in invalid currency # features/get_wallet_value.feature:20
Given I have these assets: # wallet_test.go:28 -> iHaveTheseAssets
| type | ticker | quantity |
| stock | TSLA | 1.1 |
| stock | AAPL | 10 |
Then the total value in "LOL" should show an error # wallet_test.go:108 -> theTotalValueInShouldShowAnErrorScenario: Get wallet value without assets # features/get_wallet_value.feature:27
Given I have these assets: # wallet_test.go:28 -> iHaveTheseAssets
| type | ticker | quantity |
Then the total value should be 0 USD # wallet_test.go:68 -> theTotalValueShouldBeScenario: Get wallet value in USD with stocks values from Yahoo Finance # features/get_wallet_value.feature:32
Given I have these assets: # wallet_test.go:28 -> iHaveTheseAssets
| type | ticker | quantity |
| stock | TSLA | 1.1 |
| stock | AAPL | 10 |
Then the total value should not be 0 # wallet_test.go:86 -> theTotalValueShouldNotBeUSDScenario: Get wallet value in EUR with exchange rate from exchangerate.host # features/get_wallet_value.feature:39
Given I have these assets: # wallet_test.go:28 -> iHaveTheseAssets
| type | ticker | quantity |
| stock | TSLA | 1.1 |
| stock | AAPL | 10 |
| crypto | BTC | 5 |
Then the total value should not be 0 EUR # wallet_test.go:97 -> theTotalValueShouldNotBeCurrency7 scenarios (7 passed)
23 steps (23 passed)
591.004488ms
```You can also see the output in the [Actions workflow](https://github.com/angristan/go-wallet-bdd-test/actions).