mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Add friendship feature with models, repository, and tests
Introduces Friendship and PrivateChat models, repository interfaces, and implementations for managing friendships. Adds validators and comprehensive unit and integration tests for friendship logic. Updates InviteUserController with new endpoints and restricts access to admin role. Removes unnecessary project references from Govor.API.csproj and registers new DbSets in GovorDbContext.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using AutoFixture;
|
||||
using Govor.Core.Infrastructure.Validators;
|
||||
using Govor.Core.Models;
|
||||
|
||||
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
|
||||
|
||||
[TestFixture]
|
||||
public class FriendshipValidatorTests
|
||||
{
|
||||
private IObjectValidator<Friendship> _friendshipValidator;
|
||||
private Fixture _fixture;
|
||||
|
||||
public FriendshipValidatorTests()
|
||||
{
|
||||
_friendshipValidator = new FriendshipValidator();
|
||||
|
||||
_fixture = new Fixture();
|
||||
|
||||
_fixture.Behaviors
|
||||
.OfType<ThrowingRecursionBehavior>()
|
||||
.ToList()
|
||||
.ForEach(b => _fixture.Behaviors.Remove(b));
|
||||
|
||||
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Given_ValidFriendship_When_Validate_Then_Returns_True()
|
||||
{
|
||||
var friendship = _fixture.Create<Friendship>();
|
||||
|
||||
// Act & Assert
|
||||
Assert.DoesNotThrow( () => _friendshipValidator.Validate(friendship));
|
||||
Assert.That(_friendshipValidator.TryValidate(friendship), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_EmptyFriendshipId_When_Validate_Then_Returns_False()
|
||||
{
|
||||
var friendship = _fixture.Create<Friendship>();
|
||||
friendship.Id = Guid.Empty;
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidObjectException<Friendship>>( () => _friendshipValidator.Validate(friendship));
|
||||
Assert.That(_friendshipValidator.TryValidate(friendship), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_EmptyRequesterId_When_Validate_Then_Returns_False()
|
||||
{
|
||||
var friendship = _fixture.Create<Friendship>();
|
||||
friendship.RequesterId = Guid.Empty;
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidObjectException<Friendship>>( () => _friendshipValidator.Validate(friendship));
|
||||
Assert.That(_friendshipValidator.TryValidate(friendship), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_AddresseeId_When_Validate_Then_Returns_False()
|
||||
{
|
||||
var friendship = _fixture.Create<Friendship>();
|
||||
friendship.AddresseeId = Guid.Empty;
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidObjectException<Friendship>>( () => _friendshipValidator.Validate(friendship));
|
||||
Assert.That(_friendshipValidator.TryValidate(friendship), Is.False);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class InvitationValidatorTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_ValidInvitation_When_Exist_Then_Returns_True()
|
||||
public void Given_ValidInvitation_When_Validate_Then_Returns_True()
|
||||
{
|
||||
var invitation = _fixture.Create<Invitation>();
|
||||
|
||||
@@ -35,7 +35,7 @@ public class InvitationValidatorTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_NullInvitation_When_Exist_Then_Returns_False()
|
||||
public void Given_NullInvitation_When_Validate_Then_Returns_False()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidObjectException<Invitation>>( () => _messageValidator.Validate(default));
|
||||
@@ -43,7 +43,7 @@ public class InvitationValidatorTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_EmptyInvitationId_When_Exist_Then_Returns_False()
|
||||
public void Given_EmptyInvitationId_When_Validate_Then_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
var invitation = _fixture.Create<Invitation>();
|
||||
@@ -55,7 +55,7 @@ public class InvitationValidatorTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_EmptyInvitationCreationDate_When_Exist_Then_Returns_False()
|
||||
public void Given_EmptyInvitationCreationDate_When_Validate_Then_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
var invitation = _fixture.Create<Invitation>();
|
||||
@@ -67,7 +67,7 @@ public class InvitationValidatorTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_InvalidEndDatesAndIsActive_When_Exist_Then_Returns_False()
|
||||
public void Given_InvalidEndDatesAndIsActive_When_Validate_Then_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
var invitation = _fixture.Create<Invitation>();
|
||||
@@ -79,7 +79,7 @@ public class InvitationValidatorTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_InvalidMaxParticipantsAndIsActive_When_Exist_Then_Returns_False()
|
||||
public void Given_InvalidMaxParticipantsAndIsActive_When_Validate_Then_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
var invitation = _fixture.Create<Invitation>();
|
||||
@@ -92,7 +92,7 @@ public class InvitationValidatorTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_InvalidCode_When_Exist_Then_Returns_False()
|
||||
public void Given_InvalidCode_When_Validate_Then_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
var invitation = _fixture.Create<Invitation>();
|
||||
|
||||
Reference in New Issue
Block a user