Identity
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using FluentAssertions;
|
||||
using Nashel.Modules.Identity.Domain.Aggregates;
|
||||
using Nashel.Modules.Identity.Domain.Enums;
|
||||
using Xunit;
|
||||
|
||||
namespace Nashel.Modules.Identity.Tests.Domain;
|
||||
|
||||
public class AccountTests
|
||||
{
|
||||
[Fact]
|
||||
public void Create_Should_Create_Account_With_User_Role()
|
||||
{
|
||||
// Arrange & Act
|
||||
var phone = "1234567890";
|
||||
var passwordHash = "hash";
|
||||
var account = Account.Create(phone, passwordHash);
|
||||
|
||||
// Assert
|
||||
account.Should().NotBeNull();
|
||||
account.Roles.Should().ContainSingle(r => r == Role.User);
|
||||
account.Roles.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BecomePerformer_Should_Add_Candidate_Role()
|
||||
{
|
||||
// Arrange
|
||||
var account = Account.Create("123", "hash");
|
||||
|
||||
// Act
|
||||
account.BecomePerformer();
|
||||
|
||||
// Assert
|
||||
account.Roles.Should().Contain(Role.Candidate);
|
||||
account.Roles.Should().Contain(Role.User);
|
||||
account.Roles.Should().HaveCount(2); // User + Candidate
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BecomePerformer_Should_Do_Nothing_If_Already_Candidate()
|
||||
{
|
||||
// Arrange
|
||||
var account = Account.Create("123", "hash");
|
||||
account.BecomePerformer();
|
||||
|
||||
// Act
|
||||
account.BecomePerformer();
|
||||
|
||||
// Assert
|
||||
account.Roles.Should().ContainSingle(r => r == Role.Candidate);
|
||||
account.Roles.Should().HaveCount(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PromoteToMaster_Should_Replace_Candidate_With_Master()
|
||||
{
|
||||
// Arrange
|
||||
var account = Account.Create("123", "hash");
|
||||
account.BecomePerformer(); // Has Candidate
|
||||
|
||||
// Act
|
||||
account.PromoteToMaster();
|
||||
|
||||
// Assert
|
||||
account.Roles.Should().NotContain(Role.Candidate);
|
||||
account.Roles.Should().Contain(Role.Master);
|
||||
account.Roles.Should().Contain(Role.User);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user