mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Add username validation and initial friends feature
Introduced a UsernameValidator with Cyrillic and length checks, integrated into AuthService and registration flow. Added InvalidUsernameException and related interface. Updated User model to support friend requests, added FriendsController (stub), and configured Friendship entity in EF Core. Adjusted UserValidator max name length and removed navigation properties from PrivateChat.
This commit is contained in:
@@ -19,6 +19,7 @@ public class AuthServiceTests
|
||||
private Mock<IJwtService> _jwtServiceMock;
|
||||
private Mock<IUsersRepository> _usersRepositoryMock;
|
||||
private Mock<IAdminsRepository> _adminsRepositoryMock;
|
||||
private Mock<IUsernameValidator> _usernameValidatorMock;
|
||||
|
||||
private IAccountService _accountService;
|
||||
|
||||
@@ -38,12 +39,14 @@ public class AuthServiceTests
|
||||
_passwordHasherMock = new Mock<IPasswordHasher>();
|
||||
_jwtServiceMock = new Mock<IJwtService>();
|
||||
_adminsRepositoryMock = new Mock<IAdminsRepository>();
|
||||
_usernameValidatorMock = new Mock<IUsernameValidator>();
|
||||
|
||||
_accountService = new AuthService(
|
||||
_usersRepositoryMock.Object,
|
||||
_jwtServiceMock.Object,
|
||||
_passwordHasherMock.Object,
|
||||
_adminsRepositoryMock.Object
|
||||
_adminsRepositoryMock.Object,
|
||||
_usernameValidatorMock.Object
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using Govor.Application.Validators; // или другой namespace
|
||||
using Govor.Application.Exceptions.AuthService;
|
||||
|
||||
namespace Govor.API.Tests.UnitTests.Services.Validators;
|
||||
|
||||
[TestFixture]
|
||||
public class UsernameValidatorTests
|
||||
{
|
||||
private UsernameValidator _validator;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_validator = new UsernameValidator();
|
||||
}
|
||||
|
||||
[TestCase("Иван")]
|
||||
[TestCase("Алексей")]
|
||||
[TestCase("Ёжик")]
|
||||
public void Validate_ValidUsernames_ShouldNotThrow(string username)
|
||||
{
|
||||
Assert.DoesNotThrow(() => _validator.Validate(username));
|
||||
}
|
||||
|
||||
[TestCase("Ivan")] // не кириллица
|
||||
[TestCase("123Иван")] // начинается не с буквы
|
||||
[TestCase("Иван123")] // содержит цифры
|
||||
[TestCase("!@#$")] // спецсимволы
|
||||
[TestCase("")] // пусто
|
||||
[TestCase("И")] // меньше минимума
|
||||
[TestCase("ИванИванИванИванИванИванИванИванИванИванИванИванИван")] // больше максимума (44 символа)
|
||||
public void Validate_InvalidUsernames_ShouldThrow(string username)
|
||||
{
|
||||
Assert.Throws<InvalidUsernameException>(() => _validator.Validate(username));
|
||||
}
|
||||
|
||||
[TestCase("Иван", ExpectedResult = true)]
|
||||
[TestCase("1234", ExpectedResult = false)]
|
||||
public bool TryValidate_ShouldReturnTrueRegardlessOfInput(string username)
|
||||
{
|
||||
return _validator.TryValidate(username);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user