package identity

import "testing"

func TestRedisKeysMatchPythonConvention(t *testing.T) {
	if got := codeKey("email_login", "USER@Example.COM"); got != "qycw:verification_code:email_login:user@example.com" {
		t.Fatalf("unexpected code key: %s", got)
	}
	if got := cooldownKey("sms_register", "13800138000"); got != "qycw:verification_code_cooldown:sms_register:13800138000" {
		t.Fatalf("unexpected cooldown key: %s", got)
	}
	if got := attemptKey("email_bind", "a@example.com"); got != "qycw:verification_code_attempts:email_bind:a@example.com" {
		t.Fatalf("unexpected attempt key: %s", got)
	}
}

func TestGenerateCode(t *testing.T) {
	code, err := generateCode()
	if err != nil {
		t.Fatalf("generate code: %v", err)
	}
	if !validateCode(code) {
		t.Fatalf("expected 6 digit code, got %q", code)
	}
}
