Files
Overlord 8f0eda5d4d Add alerts, currency conversion and notifications.
Items fire when a page is available from an accepted seller at or below
max_price, converted with the ECB's daily rates when the page uses
another currency. A per-item cooldown, kept in the state file, holds
back repeat alerts unless the price drops. Alerts go to Discord, ntfy
and JSON webhooks with retries, and to the desktop;
'dibs notify test' sends a sample.
2026-10-14 11:55:27 +02:00

29 lines
664 B
Go

package fx
import (
"math"
"testing"
)
func TestConvert(t *testing.T) {
r := &Rates{PerEUR: map[string]float64{"USD": 1.25, "GBP": 0.8}}
cases := []struct {
amount float64
from, to string
want float64
} {
{100, "EUR", "USD", 125},
{125, "USD", "EUR", 100},
{100, "GBP", "USD", 156.25},
{100, "GBP", "GBP", 100},
}
for _, c := range cases {
got, err := r.Convert(c.amount, c.from, c.to)
if err != nil || math.Abs(got-c.want) > 1e-9 { t.Errorf("%v %s in %s = %v, %v; want %v", c.amount, c.from, c.to, got, err, c.want) }
}
if _, err := r.Convert(1, "JPY", "EUR"); err == nil { t.Error("converted a currency without a rate") }
}