- Introduced a new support ticket system allowing users to submit bug reports and role requests. - Implemented endpoints for creating, updating, and managing support tickets, including file attachments. - Enhanced Telegram bot integration to handle role requests directly within the bot, enabling admins to approve or reject requests without accessing the website. - Updated database schema to include support ticket entities and their relationships. - Improved API documentation to reflect new support ticket endpoints and their usage. - Added necessary localization for support ticket features in both Russian and English.
125 lines
3.2 KiB
C#
125 lines
3.2 KiB
C#
using PnvPanel.Domain.Exceptions;
|
|
using PnvPanel.Domain.Support;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Domain.Tests.Support;
|
|
|
|
public class SupportTicketTests
|
|
{
|
|
[Fact]
|
|
public void CreateBugReport_SetsOpenStatus()
|
|
{
|
|
var userId = Guid.NewGuid();
|
|
|
|
var ticket = SupportTicket.CreateBugReport(userId);
|
|
|
|
Assert.Equal(userId, ticket.UserId);
|
|
Assert.Equal(TicketType.BugReport, ticket.Type);
|
|
Assert.Equal(TicketStatus.Open, ticket.Status);
|
|
Assert.Null(ticket.RequestedRoleId);
|
|
Assert.Null(ticket.ProposedRoleName);
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateRoleRequestForExistingRole_SetsRequestedRoleId()
|
|
{
|
|
var userId = Guid.NewGuid();
|
|
var roleId = Guid.NewGuid();
|
|
|
|
var ticket = SupportTicket.CreateRoleRequestForExistingRole(userId, roleId);
|
|
|
|
Assert.Equal(TicketType.RoleRequest, ticket.Type);
|
|
Assert.Equal(roleId, ticket.RequestedRoleId);
|
|
Assert.Null(ticket.ProposedRoleName);
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateRoleRequestForNewRole_SetsProposedFields()
|
|
{
|
|
var ticket = SupportTicket.CreateRoleRequestForNewRole(Guid.NewGuid(), "premium", 5, 3);
|
|
|
|
Assert.Equal(TicketType.RoleRequest, ticket.Type);
|
|
Assert.Null(ticket.RequestedRoleId);
|
|
Assert.Equal("premium", ticket.ProposedRoleName);
|
|
Assert.Equal(5, ticket.ProposedMaxConfigs);
|
|
Assert.Equal(3, ticket.ProposedMaxIpLimit);
|
|
}
|
|
|
|
[Fact]
|
|
public void Resolve_WhenOpen_SetsResolved()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
|
|
ticket.Resolve();
|
|
|
|
Assert.Equal(TicketStatus.Resolved, ticket.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Resolve_WhenNotOpen_Throws()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
ticket.Resolve();
|
|
|
|
Assert.Throws<DomainException>(() => ticket.Resolve());
|
|
}
|
|
|
|
[Fact]
|
|
public void Close_WhenOpen_SetsClosed()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
|
|
ticket.Close();
|
|
|
|
Assert.Equal(TicketStatus.Closed, ticket.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Close_WhenResolved_SetsClosed()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
ticket.Resolve();
|
|
|
|
ticket.Close();
|
|
|
|
Assert.Equal(TicketStatus.Closed, ticket.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Close_WhenAlreadyClosed_Throws()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
ticket.Close();
|
|
|
|
Assert.Throws<DomainException>(() => ticket.Close());
|
|
}
|
|
|
|
[Fact]
|
|
public void Reopen_WhenResolved_SetsOpen()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
ticket.Resolve();
|
|
|
|
ticket.Reopen();
|
|
|
|
Assert.Equal(TicketStatus.Open, ticket.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Reopen_WhenOpen_Throws()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
|
|
Assert.Throws<DomainException>(() => ticket.Reopen());
|
|
}
|
|
|
|
[Fact]
|
|
public void Reopen_WhenClosed_Throws()
|
|
{
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
ticket.Close();
|
|
|
|
Assert.Throws<DomainException>(() => ticket.Reopen());
|
|
}
|
|
}
|