package usecase

import (
	"testing"

	"apps/backend/internal/module/member/domain"
)

func TestValidatePasswordPolicy(t *testing.T) {
	cases := []struct {
		pw   string
		want error
	}{
		{"short", domain.ErrWeakPassword},
		{"alllowercase1!", domain.ErrWeakPassword},  // no upper
		{"ALLUPPERCASE1!", domain.ErrWeakPassword},  // no lower
		{"NoDigitsHere!!", domain.ErrWeakPassword},  // no digit
		{"NoSymbolHere12", domain.ErrWeakPassword},  // no symbol
		{"Admin123!@#x", nil},                       // 12 ok
		{"GoodPassw0rd!", nil},
	}
	for _, c := range cases {
		err := ValidatePasswordPolicy(c.pw)
		if c.want == nil && err != nil {
			t.Fatalf("%q: unexpected %v", c.pw, err)
		}
		if c.want != nil && err != c.want {
			t.Fatalf("%q: got %v want %v", c.pw, err, c.want)
		}
	}
}

func TestGenerateTempPasswordMeetsPolicy(t *testing.T) {
	for i := 0; i < 20; i++ {
		pw := GenerateTempPassword()
		if err := ValidatePasswordPolicy(pw); err != nil {
			t.Fatalf("temp %q: %v", pw, err)
		}
	}
}
