mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
add exchange data source unit test
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
package exchangerates
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mayswind/lab/pkg/core"
|
||||
"github.com/mayswind/lab/pkg/models"
|
||||
)
|
||||
|
||||
const bankOfCanadaMinimumRequiredContent = "{\n" +
|
||||
" \"observations\": [\n" +
|
||||
" {\n" +
|
||||
" \"d\": \"2019-12-31\",\n" +
|
||||
" \"FXVNDCAD\": {\n" +
|
||||
" \"v\": \"0.000056\"\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"d\": \"2021-04-01\",\n" +
|
||||
" \"FXCNYCAD\": {\n" +
|
||||
" \"v\": \"0.1913\"\n" +
|
||||
" },\n" +
|
||||
" \"FXUSDCAD\": {\n" +
|
||||
" \"v\": \"1.2565\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}"
|
||||
|
||||
func TestBankOfCanadaDataSource_StandardDataExtractBaseCurrency(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(bankOfCanadaMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "CAD", actualLatestExchangeRateResponse.BaseCurrency)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_StandardDataExtractExchangeRates(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(bankOfCanadaMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "USD",
|
||||
Rate: "0.7958615200955034",
|
||||
})
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "CNY",
|
||||
Rate: "5.2273915316257185",
|
||||
})
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "VND",
|
||||
Rate: "17857.14285714286",
|
||||
})
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_BlankContent(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte(""))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_EmptyJsonObject(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("{}"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_EmptyObservationsContent(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("{"+
|
||||
" \"observations\": []"+
|
||||
"}"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_InvalidObservationFormat(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("{"+
|
||||
" \"observations\": [\n"+
|
||||
" {\n"+
|
||||
" \"d\": \"2021-04-01\",\n"+
|
||||
" \"CNYCAD\": {\n"+
|
||||
" \"v\": \"0.1913\"\n"+
|
||||
" }\n"+
|
||||
" }\n"+
|
||||
" ]\n"+
|
||||
"}"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_InvalidObservationFormat2(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("{"+
|
||||
" \"observations\": [\n"+
|
||||
" {\n"+
|
||||
" \"d\": \"2021-04-01\",\n"+
|
||||
" \"FXCADCNY\": {\n"+
|
||||
" \"v\": \"0.1913\"\n"+
|
||||
" }\n"+
|
||||
" }\n"+
|
||||
" ]\n"+
|
||||
"}"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_InvalidCurrency(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("{"+
|
||||
" \"observations\": [\n"+
|
||||
" {\n"+
|
||||
" \"d\": \"2021-04-01\",\n"+
|
||||
" \"FXXXXCAD\": {\n"+
|
||||
" \"v\": \"1\"\n"+
|
||||
" }\n"+
|
||||
" }\n"+
|
||||
" ]\n"+
|
||||
"}"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_EmptyRate(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("{"+
|
||||
" \"observations\": [\n"+
|
||||
" {\n"+
|
||||
" \"d\": \"2021-04-01\",\n"+
|
||||
" \"FXUSDCAD\": {\n"+
|
||||
" \"v\": \"\"\n"+
|
||||
" }\n"+
|
||||
" }\n"+
|
||||
" ]\n"+
|
||||
"}"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestBankOfCanadaDataSource_InvalidRate(t *testing.T) {
|
||||
dataSource := &BankOfCanadaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("{"+
|
||||
" \"observations\": [\n"+
|
||||
" {\n"+
|
||||
" \"d\": \"2021-04-01\",\n"+
|
||||
" \"FXUSDCAD\": {\n"+
|
||||
" \"v\": null\n"+
|
||||
" }\n"+
|
||||
" }\n"+
|
||||
" ]\n"+
|
||||
"}"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package exchangerates
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mayswind/lab/pkg/core"
|
||||
"github.com/mayswind/lab/pkg/models"
|
||||
)
|
||||
|
||||
const czechNationalBankMinimumRequiredContent = "01 Apr 2021 #64\n" +
|
||||
"Country|Currency|Amount|Code|Rate\n" +
|
||||
"China|renminbi|1|CNY|3.379\n" +
|
||||
"USA|dollar|1|USD|22.206\n"
|
||||
|
||||
func TestCzechNationalBankDataSource_StandardDataExtractBaseCurrency(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(czechNationalBankMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "CZK", actualLatestExchangeRateResponse.BaseCurrency)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_StandardDataExtractExchangeRates(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(czechNationalBankMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "USD",
|
||||
Rate: "0.04503287399801856",
|
||||
})
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "CNY",
|
||||
Rate: "0.2959455460195324",
|
||||
})
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_BlankContent(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte(""))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_OnlyHeader(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("01 Apr 2021 #64"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_OnlyHeaderAndTitle(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("01 Apr 2021 #64\n"+
|
||||
"Country|Currency|Amount|Code|Rate"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_TitleMissingCode(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("01 Apr 2021 #64\n"+
|
||||
"Country|Currency|Amount|Rate\n"+
|
||||
"China|renminbi|1|3.379\n"+
|
||||
"USA|dollar|1|22.206\n"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_TitleMissingRate(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("01 Apr 2021 #64\n"+
|
||||
"Country|Currency|Amount|Code\n"+
|
||||
"China|renminbi|1|CNY\n"+
|
||||
"USA|dollar|1|USD\n"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_InvalidCurrency(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("01 Apr 2021 #64\n"+
|
||||
"Country|Currency|Amount|Code|Rate\n"+
|
||||
"XXX|xxx|1|XXX|1\n"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_EmptyRate(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("01 Apr 2021 #64\n"+
|
||||
"Country|Currency|Amount|Code|Rate\n"+
|
||||
"USA|dollar|1|USD|\n"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestCzechNationalBankDataSource_InvalidRate(t *testing.T) {
|
||||
dataSource := &CzechNationalBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("01 Apr 2021 #64\n"+
|
||||
"Country|Currency|Amount|Code|Rate\n"+
|
||||
"USA|dollar|1|USD|null\n"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package exchangerates
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mayswind/lab/pkg/core"
|
||||
"github.com/mayswind/lab/pkg/models"
|
||||
)
|
||||
|
||||
const euroCentralBankMinimumRequiredContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<gesmes:Envelope xmlns:gesmes=\"http://www.gesmes.org/xml/2002-08-01\" xmlns=\"http://www.ecb.int/vocabulary/2002-08-01/eurofxref\">\n" +
|
||||
" <Cube>\n" +
|
||||
" <Cube time=\"2021-04-01\">\n" +
|
||||
" <Cube currency=\"USD\" rate=\"1.1746\" />\n" +
|
||||
" <Cube currency=\"CNY\" rate=\"7.7195\" />\n" +
|
||||
" </Cube>\n" +
|
||||
" </Cube>\n" +
|
||||
"</gesmes:Envelope>"
|
||||
|
||||
func TestEuroCentralBankDataSource_StandardDataExtractBaseCurrency(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(euroCentralBankMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "EUR", actualLatestExchangeRateResponse.BaseCurrency)
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_StandardDataExtractExchangeRates(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(euroCentralBankMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "USD",
|
||||
Rate: "1.1746",
|
||||
})
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "CNY",
|
||||
Rate: "7.7195",
|
||||
})
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_BlankContent(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte(""))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_OnlyXMLHeader(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_EmptyEnvelopeContent(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<gesmes:Envelope xmlns:gesmes=\"http://www.gesmes.org/xml/2002-08-01\" xmlns=\"http://www.ecb.int/vocabulary/2002-08-01/eurofxref\">" +
|
||||
"</gesmes:Envelope>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_EmptyCubeContent(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<gesmes:Envelope xmlns:gesmes=\"http://www.gesmes.org/xml/2002-08-01\" xmlns=\"http://www.ecb.int/vocabulary/2002-08-01/eurofxref\">" +
|
||||
"<Cube>" +
|
||||
"</Cube>" +
|
||||
"</gesmes:Envelope>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_InvalidCurrency(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<gesmes:Envelope xmlns:gesmes=\"http://www.gesmes.org/xml/2002-08-01\" xmlns=\"http://www.ecb.int/vocabulary/2002-08-01/eurofxref\">" +
|
||||
"<Cube>" +
|
||||
"<Cube time=\"2021-04-01\">" +
|
||||
"<Cube currency=\"XXX\" rate=\"1\" />" +
|
||||
"</Cube>" +
|
||||
"</Cube>" +
|
||||
"</gesmes:Envelope>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_EmptyRate(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<gesmes:Envelope xmlns:gesmes=\"http://www.gesmes.org/xml/2002-08-01\" xmlns=\"http://www.ecb.int/vocabulary/2002-08-01/eurofxref\">" +
|
||||
"<Cube>" +
|
||||
"<Cube time=\"2021-04-01\">" +
|
||||
"<Cube currency=\"USD\" rate=\"\" />" +
|
||||
"</Cube>" +
|
||||
"</Cube>" +
|
||||
"</gesmes:Envelope>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestEuroCentralBankDataSource_InvalidRate(t *testing.T) {
|
||||
dataSource := &EuroCentralBankDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<gesmes:Envelope xmlns:gesmes=\"http://www.gesmes.org/xml/2002-08-01\" xmlns=\"http://www.ecb.int/vocabulary/2002-08-01/eurofxref\">" +
|
||||
"<Cube>" +
|
||||
"<Cube time=\"2021-04-01\">" +
|
||||
"<Cube currency=\"USD\" rate=\"null\" />" +
|
||||
"</Cube>" +
|
||||
"</Cube>" +
|
||||
"</gesmes:Envelope>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package exchangerates
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mayswind/lab/pkg/core"
|
||||
"github.com/mayswind/lab/pkg/models"
|
||||
)
|
||||
|
||||
const nationalBankOfPolandMinimumRequiredContent = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
|
||||
"<exchange_rates table=\"A\" date=\"2021-04-02\" number=\"064/A/NBP/2021\" uid=\"21a064\">\n" +
|
||||
" <mid-rate currency=\"US Dollar\" units=\"1\" code=\"USD\">3.8986</mid-rate>\n" +
|
||||
" <mid-rate currency=\"Yuan Renminbi\" units=\"1\" code=\"CNY\">0.5941</mid-rate>\n" +
|
||||
"</exchange_rates>"
|
||||
|
||||
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("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestNationalBankOfPolandDataSource_EmptyExchangeRatesContent(t *testing.T) {
|
||||
dataSource := &NationalBankOfPolandDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
|
||||
"<exchange_rates table=\"A\" date=\"2021-04-02\" number=\"064/A/NBP/2021\" uid=\"21a064\">\n"+
|
||||
"</exchange_rates>"))
|
||||
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("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
|
||||
"<exchange_rates table=\"A\" date=\"2021-04-02\" number=\"064/A/NBP/2021\" uid=\"21a064\">\n"+
|
||||
" <mid-rate currency=\"XXX\" units=\"1\" code=\"XXX\">1</mid-rate>\n"+
|
||||
"</exchange_rates>"))
|
||||
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("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
|
||||
"<exchange_rates table=\"A\" date=\"2021-04-02\" number=\"064/A/NBP/2021\" uid=\"21a064\">\n"+
|
||||
" <mid-rate currency=\"US Dollar\" units=\"1\" code=\"USD\"></mid-rate>\n"+
|
||||
"</exchange_rates>"))
|
||||
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("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
|
||||
"<exchange_rates table=\"A\" date=\"2021-04-02\" number=\"064/A/NBP/2021\" uid=\"21a064\">\n"+
|
||||
" <mid-rate currency=\"US Dollar\" units=\"1\" code=\"USD\">null</mid-rate>\n"+
|
||||
"</exchange_rates>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
package exchangerates
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mayswind/lab/pkg/core"
|
||||
"github.com/mayswind/lab/pkg/models"
|
||||
)
|
||||
|
||||
const reserveBankOfAustraliaMinimumRequiredContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n" +
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n" +
|
||||
" <dc:date>2021-04-01T16:45:00+11:00</dc:date>\n" +
|
||||
" </channel>\n" +
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#USD\">\n" +
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n" +
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n" +
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n" +
|
||||
" <cb:value>0.7543</cb:value>\n" +
|
||||
" <cb:unit>AUD</cb:unit>\n" +
|
||||
" </cb:observation>\n" +
|
||||
" <cb:baseCurrency>AUD</cb:baseCurrency>\n" +
|
||||
" <cb:targetCurrency>USD</cb:targetCurrency>\n" +
|
||||
" </cb:exchangeRate>\n" +
|
||||
" </cb:statistics>\n" +
|
||||
" </item>\n" +
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#CNY\">\n" +
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n" +
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n" +
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n" +
|
||||
" <cb:value>4.9577</cb:value>\n" +
|
||||
" <cb:unit>AUD</cb:unit>\n" +
|
||||
" </cb:observation>\n" +
|
||||
" <cb:baseCurrency>AUD</cb:baseCurrency>\n" +
|
||||
" <cb:targetCurrency>CNY</cb:targetCurrency>\n" +
|
||||
" </cb:exchangeRate>\n" +
|
||||
" </cb:statistics>\n" +
|
||||
" </item>\n" +
|
||||
"</rdf:RDF>"
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_StandardDataExtractBaseCurrency(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(reserveBankOfAustraliaMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "AUD", actualLatestExchangeRateResponse.BaseCurrency)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_StandardDataExtractExchangeRates(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte(reserveBankOfAustraliaMinimumRequiredContent))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "USD",
|
||||
Rate: "0.7543",
|
||||
})
|
||||
assert.Contains(t, actualLatestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "CNY",
|
||||
Rate: "4.9577",
|
||||
})
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_BlankContent(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte(""))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_OnlyXMLHeader(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_EmptyRDFContent(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_EmptyChannelContent(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n"+
|
||||
" </channel>"+
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#USD\">\n"+
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:value>0.7543</cb:value>\n"+
|
||||
" <cb:unit>AUD</cb:unit>\n"+
|
||||
" </cb:observation>\n"+
|
||||
" <cb:baseCurrency>AUD</cb:baseCurrency>\n"+
|
||||
" <cb:targetCurrency>USD</cb:targetCurrency>\n"+
|
||||
" </cb:exchangeRate>\n"+
|
||||
" </cb:statistics>\n"+
|
||||
" </item>\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_NoItem(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
_, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n"+
|
||||
" <dc:date>2021-04-01T16:45:00+11:00</dc:date>\n"+
|
||||
" </channel>\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.NotEqual(t, nil, err)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_BaseCurrencyNotEqualPreset(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n"+
|
||||
" <dc:date>2021-04-01T16:45:00+11:00</dc:date>\n"+
|
||||
" </channel>\n"+
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#USD\">\n"+
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:value>0.7543</cb:value>\n"+
|
||||
" <cb:unit>AUD</cb:unit>\n"+
|
||||
" </cb:observation>\n"+
|
||||
" <cb:baseCurrency>USD</cb:baseCurrency>\n"+
|
||||
" <cb:targetCurrency>USD</cb:targetCurrency>\n"+
|
||||
" </cb:exchangeRate>\n"+
|
||||
" </cb:statistics>\n"+
|
||||
" </item>\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_UnitCurrencyNotEqualPreset(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n"+
|
||||
" <dc:date>2021-04-01T16:45:00+11:00</dc:date>\n"+
|
||||
" </channel>\n"+
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#USD\">\n"+
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:value>0.7543</cb:value>\n"+
|
||||
" <cb:unit>USD</cb:unit>\n"+
|
||||
" </cb:observation>\n"+
|
||||
" <cb:baseCurrency>AUD</cb:baseCurrency>\n"+
|
||||
" <cb:targetCurrency>USD</cb:targetCurrency>\n"+
|
||||
" </cb:exchangeRate>\n"+
|
||||
" </cb:statistics>\n"+
|
||||
" </item>\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_InvalidCurrency(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n"+
|
||||
" <dc:date>2021-04-01T16:45:00+11:00</dc:date>\n"+
|
||||
" </channel>\n"+
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#USD\">\n"+
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:value>1</cb:value>\n"+
|
||||
" <cb:unit>AUD</cb:unit>\n"+
|
||||
" </cb:observation>\n"+
|
||||
" <cb:baseCurrency>AUD</cb:baseCurrency>\n"+
|
||||
" <cb:targetCurrency>XXX</cb:targetCurrency>\n"+
|
||||
" </cb:exchangeRate>\n"+
|
||||
" </cb:statistics>\n"+
|
||||
" </item>\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_EmptyRate(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n"+
|
||||
" <dc:date>2021-04-01T16:45:00+11:00</dc:date>\n"+
|
||||
" </channel>\n"+
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#USD\">\n"+
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:value></cb:value>\n"+
|
||||
" <cb:unit>AUD</cb:unit>\n"+
|
||||
" </cb:observation>\n"+
|
||||
" <cb:baseCurrency>AUD</cb:baseCurrency>\n"+
|
||||
" <cb:targetCurrency>USD</cb:targetCurrency>\n"+
|
||||
" </cb:exchangeRate>\n"+
|
||||
" </cb:statistics>\n"+
|
||||
" </item>\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
|
||||
func TestReserveBankOfAustraliaDataSource_InvalidRate(t *testing.T) {
|
||||
dataSource := &ReserveBankOfAustraliaDataSource{}
|
||||
context := &core.Context{
|
||||
Context: &gin.Context{},
|
||||
}
|
||||
|
||||
actualLatestExchangeRateResponse, err := dataSource.Parse(context, []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rba=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html\" xmlns:cb=\"http://www.cbwiki.net/wiki/index.php/Specification_1.2/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://purl.org/rss/1.0/\" xsi:schemaLocation=\"http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd\">\n"+
|
||||
" <channel rdf:about=\"https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml\">\n"+
|
||||
" <dc:date>2021-04-01T16:45:00+11:00</dc:date>\n"+
|
||||
" </channel>\n"+
|
||||
" <item rdf:about=\"https://www.rba.gov.au/statistics/frequency/exchange-rates.html#USD\">\n"+
|
||||
" <cb:statistics rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:exchangeRate rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:observation rdf:parseType=\"Resource\">\n"+
|
||||
" <cb:value>null</cb:value>\n"+
|
||||
" <cb:unit>AUD</cb:unit>\n"+
|
||||
" </cb:observation>\n"+
|
||||
" <cb:baseCurrency>AUD</cb:baseCurrency>\n"+
|
||||
" <cb:targetCurrency>USD</cb:targetCurrency>\n"+
|
||||
" </cb:exchangeRate>\n"+
|
||||
" </cb:statistics>\n"+
|
||||
" </item>\n"+
|
||||
"</rdf:RDF>"))
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Len(t, actualLatestExchangeRateResponse.ExchangeRates, 0)
|
||||
}
|
||||
Reference in New Issue
Block a user