package user

import (
	"testing"

	"github.com/perfect-panel/server/internal/types"
)

func TestMarshalUserSubscribeTrafficLimit(t *testing.T) {
	rules := []types.TrafficLimit{
		{
			StatType:     "hour",
			StatValue:    1,
			TrafficUsage: 1,
			SpeedLimit:   1,
		},
	}

	got, err := marshalUserSubscribeTrafficLimit(rules)
	if err != nil {
		t.Fatalf("marshalUserSubscribeTrafficLimit() error = %v", err)
	}
	if got == nil {
		t.Fatal("marshalUserSubscribeTrafficLimit() returned nil")
		return
	}

	want := `[{"stat_type":"hour","stat_value":1,"traffic_usage":1,"speed_limit":1}]`
	if *got != want {
		t.Fatalf("marshalUserSubscribeTrafficLimit() = %q, want %q", *got, want)
	}
}
