package price import ( "log" "testing" "gitea.urkob.com/urko/btc-pay-checker/internal/domain" "gitea.urkob.com/urko/btc-pay-checker/kit" "gitea.urkob.com/urko/btc-pay-checker/kit/cfg" "github.com/stretchr/testify/require" ) func TestConversor(t *testing.T) { config := cfg.NewConfig(kit.RootDir() + "/.test.env") p := NewPriceConversor(config.ConversorApi, config.DollarRateApi) usd, err := p.USD(domain.CoinBTC) require.NoError(t, err) log.Println("$", usd) require.Greater(t, usd, 0.0) usd, err = p.USD(domain.CoinBTC) require.NoError(t, err) log.Println("$", usd) require.Greater(t, usd, 0.0) usdAmount := 100.0 btcPrice, err := p.UsdToBtc(usdAmount) require.NoError(t, err) log.Println("btcPrice", btcPrice) require.Equal(t, btcPrice, usdAmount/usd) usd, err = p.USD(domain.CoinBTC) require.NoError(t, err) log.Println("$", usd) require.Greater(t, usd, 0.0) btcAmount := 0.0001 usdPrice, err := p.BtcToUsd(btcAmount) require.NoError(t, err) log.Println("usdPrice", usdPrice) require.Equal(t, usdPrice, btcAmount*usd) euroRate, err := p.USDTo(domain.FiatCurrencyEuro) require.NoError(t, err) require.Greater(t, euroRate, 0.0) log.Println("euroRate", euroRate) usdAmount = 150.0 converted := usdAmount * euroRate require.Greater(t, converted, 0.0) require.Equal(t, usdAmount, converted/euroRate) }