Add unit tests for dashboard repository and enhance BSON handling
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user