Add unit tests for dashboard repository and enhance BSON handling
continuous-integration/drone/push Build is passing

This commit is contained in:
Mazyar
2026-06-21 10:03:17 +03:30
parent 45cfa24a72
commit e31bccced6
5 changed files with 114 additions and 28 deletions
+44
View File
@@ -0,0 +1,44 @@
package dashboard
import (
"testing"
"go.mongodb.org/mongo-driver/v2/bson"
)
func TestFacetCountDecodesBSOND(t *testing.T) {
facet := bson.M{
"total": bson.A{
bson.D{{Key: "count", Value: int32(42)}},
},
"active": bson.A{
bson.D{{Key: "count", Value: int64(7)}},
},
}
if got := facetCount(facet, "total"); got != 42 {
t.Fatalf("expected total 42, got %d", got)
}
if got := facetCount(facet, "active"); got != 7 {
t.Fatalf("expected active 7, got %d", got)
}
}
func TestFacetCurrencyValueDecodesBSOND(t *testing.T) {
facet := bson.M{
"currency_value": bson.A{
bson.D{
{Key: "_id", Value: "eur"},
{Key: "total", Value: float64(12345.67)},
},
},
}
currency, total := facetCurrencyValue(facet)
if currency != "EUR" {
t.Fatalf("expected EUR, got %q", currency)
}
if total != 12345.67 {
t.Fatalf("expected 12345.67, got %f", total)
}
}