package helpers import ( "strconv" "testing" ) func TestMaskPhone(t *testing.T) { for _, tc := range []struct{ input, want string }{ {"", ""}, {"1", "**"}, {"123456", "**"}, {"1234567", "1234**67"}, {"+251911234567", "+251**67"}, {"\u1230\u120b\u121d12345", "\u1230\u120b\u121d1**45"}, } { t.Run(tc.input, func(t *testing.T) { if got := MaskPhone(tc.input); got != tc.want { t.Errorf("MaskPhone(%q) = %q, want %q", tc.input, got, tc.want) } }) } } func TestMaskEmail(t *testing.T) { for _, tc := range []struct{ input, want string }{ {"", ""}, {"invalid", "**"}, {"@example.com", "**"}, {"abc@", "**"}, {"a@example.com", "**@example.com"}, {"ab@example.com", "a**@example.com"}, {"abc@example.com", "ab**@example.com"}, {"alice@example.com", "ali**@example.com"}, {"\u1230\u120b\u121d@example.com", "\u1230\u120b**@example.com"}, } { t.Run(tc.input, func(t *testing.T) { if got := MaskEmail(tc.input); got != tc.want { t.Errorf("MaskEmail(%q) = %q, want %q", tc.input, got, tc.want) } }) } } func TestGenerateOTP(t *testing.T) { for range 100 { code, err := GenerateOTP() if err != nil { t.Fatal(err) } value, err := strconv.Atoi(code) if err != nil || len(code) != 6 || value < 100000 || value > 999999 { t.Fatalf("invalid OTP %q", code) } } }