package exchangerates
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/mayswind/ezbookkeeping/pkg/core"
"github.com/mayswind/ezbookkeeping/pkg/models"
)
const nationalBankOfPolandMinimumRequiredContent = "\n" +
"\n" +
" \n" +
" 2024-02-28\n" +
" \n" +
" \n" +
" USD\n" +
" 3.9922\n" +
" \n" +
" \n" +
" CNY\n" +
" 0.5545\n" +
" \n" +
" \n" +
" \n" +
""
func TestNationalBankOfPolandDataSource_StandardDataExtractBaseCurrency(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(nationalBankOfPolandMinimumRequiredContent))
assert.Equal(t, nil, err)
assert.Equal(t, "PLN", actualLatestExchangeRateResponse.BaseCurrency)
}
func TestNationalBankOfPolandDataSource_StandardDataExtractExchangeRates(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(nationalBankOfPolandMinimumRequiredContent))
assert.Equal(t, nil, err)
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
Currency: "USD",
Rate: "0.2504884524823406",
})
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
Currency: "CNY",
Rate: "1.8034265103697025",
})
}
func TestNationalBankOfPolandDataSource_BlankContent(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfPolandDataSource_OnlyXMLHeader(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte(""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfPolandDataSource_EmptyArrayOfExchangeRatesTable(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte("\n"+
"\n"+
""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfPolandDataSource_EmptyExchangeRatesTable(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte("\n"+
"\n"+
" \n"+
" \n"+
""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfPolandDataSource_EmptyExchangeRatesContent(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
_, err := dataSource.Parse(context, []byte("\n"+
"\n"+
" \n"+
" 2024-02-28\n"+
" \n"+
" \n"+
" \n"+
""))
assert.NotEqual(t, nil, err)
}
func TestNationalBankOfPolandDataSource_InvalidCurrency(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("\n"+
"\n"+
" \n"+
" 2024-02-28\n"+
" \n"+
" \n"+
" XXX\n"+
" 1\n"+
" \n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
}
func TestNationalBankOfPolandDataSource_EmptyRate(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("\n"+
"\n"+
" \n"+
" 2024-02-28\n"+
" \n"+
" \n"+
" USD\n"+
" \n"+
" \n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
}
func TestNationalBankOfPolandDataSource_InvalidRate(t *testing.T) {
dataSource := &NationalBankOfPolandDataSource{}
context := core.NewNullContext()
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("\n"+
"\n"+
" \n"+
" 2024-02-28\n"+
" \n"+
" \n"+
" USD\n"+
" null\n"+
" \n"+
" \n"+
" \n"+
""))
assert.Equal(t, nil, err)
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
}