
package currencies_test

import "seekia/internal/currencies"

import "testing"


func TestCurrencies(t *testing.T){

	currencyObjectsList, err := currencies.GetCurrencyObjectsList()
	if (err != nil){
		t.Fatal("GetCurrencyObjectsList failed: " + err.Error())
	}

	// We make sure there are no collisions of currency names or codes

	currencyNamesMap := make(map[string]struct{})
	currencyCodesMap := make(map[string]struct{})

	for _, currencyObject := range currencyObjectsList{

		currencyName := currencyObject.Name
		currencyCode := currencyObject.Code

		if (currencyName == ""){
			t.Fatal("Empty currency name exists.")
		}
		if (currencyCode == ""){
			t.Fatal("Empty currency code exists.")
		}

		_, exists := currencyNamesMap[currencyName]
		if (exists == true){
			t.Fatal("Currency name collision exists: " + currencyName)	
		}
		_, exists = currencyCodesMap[currencyCode]
		if (exists == true){
			t.Fatal("Currency code collision exists: " + currencyCode)
		}

		currencyNamesMap[currencyName] = struct{}{}
		currencyCodesMap[currencyCode] = struct{}{}
	}
}


