package exchangerates import ( "testing" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/models" ) const nationalBankOfPolandMinimumRequiredContent = "\n" + "\n" + " 3.8986\n" + " 0.5941\n" + "" func TestNationalBankOfPolandDataSource_StandardDataExtractBaseCurrency(t *testing.T) { dataSource := &NationalBankOfPolandDataSource{} context := &core.Context{ Context: &gin.Context{}, } 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.Context{ Context: &gin.Context{}, } actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(nationalBankOfPolandMinimumRequiredContent)) assert.Equal(t, nil, err) assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{ Currency: "USD", Rate: "0.25650233417124096", }) assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{ Currency: "CNY", Rate: "1.68321831341525", }) } func TestNationalBankOfPolandDataSource_BlankContent(t *testing.T) { dataSource := &NationalBankOfPolandDataSource{} context := &core.Context{ Context: &gin.Context{}, } _, err := dataSource.Parse(context, []byte("")) assert.NotEqual(t, nil, err) } func TestNationalBankOfPolandDataSource_OnlyXMLHeader(t *testing.T) { dataSource := &NationalBankOfPolandDataSource{} context := &core.Context{ Context: &gin.Context{}, } _, err := dataSource.Parse(context, []byte("")) assert.NotEqual(t, nil, err) } func TestNationalBankOfPolandDataSource_EmptyExchangeRatesContent(t *testing.T) { dataSource := &NationalBankOfPolandDataSource{} context := &core.Context{ Context: &gin.Context{}, } _, err := dataSource.Parse(context, []byte("\n"+ "\n"+ "")) assert.NotEqual(t, nil, err) } func TestNationalBankOfPolandDataSource_InvalidCurrency(t *testing.T) { dataSource := &NationalBankOfPolandDataSource{} context := &core.Context{ Context: &gin.Context{}, } actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("\n"+ "\n"+ " 1\n"+ "")) assert.Equal(t, nil, err) assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0) } func TestNationalBankOfPolandDataSource_EmptyRate(t *testing.T) { dataSource := &NationalBankOfPolandDataSource{} context := &core.Context{ Context: &gin.Context{}, } actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("\n"+ "\n"+ " \n"+ "")) assert.Equal(t, nil, err) assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0) } func TestNationalBankOfPolandDataSource_InvalidRate(t *testing.T) { dataSource := &NationalBankOfPolandDataSource{} context := &core.Context{ Context: &gin.Context{}, } actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("\n"+ "\n"+ " null\n"+ "")) assert.Equal(t, nil, err) assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0) }