package alert

import (
	"testing"
	"time"
)

func TestIsStale(t *testing.T) {
	now := time.Now()
	within := now.Add(-(StalenessWindow - time.Hour))
	past := now.Add(-(StalenessWindow + time.Hour))

	cases := []struct {
		name string
		a    Alert
		want bool
	}{
		{"just created", Alert{CreatedAt: now}, false},
		{"within window", Alert{CreatedAt: within}, false},
		{"past window", Alert{CreatedAt: past}, true},
	}
	for _, c := range cases {
		if got := isStale(&c.a); got != c.want {
			t.Errorf("%s: isStale = %v, want %v", c.name, got, c.want)
		}
	}
}

func TestIsValidResolution(t *testing.T) {
	valid := []string{
		ResolutionHandled,
		ResolutionSelfRecovered,
		ResolutionNoise,
	}
	for _, resolution := range valid {
		if !isValidResolution(resolution) {
			t.Errorf("expected %q to be valid", resolution)
		}
	}

	// The pre-taxonomy values are rejected: accepting them would quietly
	// resurrect the seven-way split the migration collapsed.
	for _, resolution := range []string{"", "unknown", "handled ", "resolved", "mitigated", "no_action_needed", "fake_alert"} {
		if isValidResolution(resolution) {
			t.Errorf("expected %q to be invalid", resolution)
		}
	}
}
