package exchangerates
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/mayswind/ezbookkeeping/pkg/core"
"github.com/mayswind/ezbookkeeping/pkg/models"
)
const nationalBankOfRomaniaMinimumRequiredContent = "\n" +
"\n" +
" \n" +
" 2024-11-15\n" +
" \n" +
" \n" +
" RON\n" +
" \n" +
" 3.0303\n" +
" 4.7057\n" +
" \n" +
" \n" +
""
func TestNationalBankOfRomaniaDataSource_StandardDataExtractBaseCurrency(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(nationalBankOfRomaniaMinimumRequiredContent))
assert.Equal(t, nil, err)
assert.Equal(t, "RON", actualLatestExchangeRateResponse.BaseCurrency)
}
func TestNationalBankOfRomaniaDataSource_StandardDataExtractUpdateTime(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(nationalBankOfRomaniaMinimumRequiredContent))
assert.Equal(t, nil, err)
assert.Equal(t, int64(1731668400), actualLatestExchangeRateResponse.UpdateTime)
}
func TestNationalBankOfRomaniaDataSource_StandardDataExtractExchangeRates(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(nationalBankOfRomaniaMinimumRequiredContent))
assert.Equal(t, nil, err)
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
Currency: "JPY",
Rate: "33.000033000033",
})
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
Currency: "USD",
Rate: "0.21250823469409438",
})
}
func TestNationalBankOfRomaniaDataSource_BlankContent(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfRomaniaDataSource_OnlyXMLHeader(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfRomaniaDataSource_EmptyExchangeRatesDataset(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""+
""+
""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfRomaniaDataSource_NoDailyRatesHeader(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""+
""+
" \n"+
""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfRomaniaDataSource_NoDailyRatesBody(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""+
""+
" \n"+
""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfRomaniaDataSource_NoDailyRatesCube(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""+
""+
" \n"+
" \n"+
" RON\n"+
" \n"+
""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfRomaniaDataSource_InvalidCurrency(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(""+
""+
" \n"+
" \n"+
" RON\n"+
" \n"+
" 1\n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
}
func TestNationalBankOfRomaniaDataSource_EmptyRate(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(""+
""+
" \n"+
" \n"+
" RON\n"+
" \n"+
" \n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
}
func TestNationalBankOfRomaniaDataSource_InvalidRate(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(""+
""+
" \n"+
" \n"+
" RON\n"+
" \n"+
" null\n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
actualLatestExchangeRateResponse, err = dataSource.Parse(context, []byte(""+
""+
" \n"+
" \n"+
" RON\n"+
" \n"+
" 0\n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
}
func TestNationalBankOfRomaniaDataSource_InvalidMultiplier(t *testing.T) {
dataSource := &NationalBankOfRomaniaDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(""+
""+
" \n"+
" \n"+
" RON\n"+
" \n"+
" 3.0303\n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
actualLatestExchangeRateResponse, err = dataSource.Parse(context, []byte(""+
""+
" \n"+
" \n"+
" RON\n"+
" \n"+
" 3.0303\n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
}