package paymenthandler

import (
	"path"
	"runtime"
	"testing"
	"time"

	"github.com/pingcap/dbaas/billing2/config"
	"github.com/pingcap/dbaas/billing2/forms"
	"github.com/pingcap/dbaas/billing2/utils/panicIf"
	"github.com/shopspring/decimal"
	"github.com/stretchr/testify/assert"
)

func TestGetLocalCurrencyComment(t *testing.T) {
	a := assert.New(t)
	config.Get().Set(config.EnableRemoteConfig, false)
	_, codeFile, _, _ := runtime.Caller(0)
	config.Get().AddConfigPath(path.Join(path.Dir(codeFile), "../../config/"))
	panicIf.Error(config.Init())
	s := &StripePaymentHandlerImpl{}
	taxRate := &forms.TaxRate{
		DisplayName: "GST",
		Value:       decimal.RequireFromString("9"),
	}
	fx := &forms.InvoiceAppliedFXRate{
		Date:   time.Date(2024, 6, 30, 0, 0, 0, 0, time.UTC),
		Base:   forms.CurrencyUSD,
		Target: forms.CurrencySGD,
		Value:  decimal.RequireFromString("1.3555"),
	}
	ret, err := s.getLocalCurrencyComment(decimal.NewFromInt(100), taxRate, fx)
	a.NoError(err)
	target := `Due to regulatory requirements, we will show you the invoice price in SGD*: 
Total excluding tax: $135.55 
GST: $12.2 (9% on $135.55) 
Total: $147.75 

* The SGD price shown on this invoice is for your reference only. Your final bill will still be paid in USD. Currency converted at the average exchange rate on June 30, 2024: 1 USD = 1.3555 SGD.`
	a.Equal(target, ret)
}
