- Implemented NotifyAdminsTicketReopenedAsync method in TelegramNotifier to notify admins when a ticket is reopened, including a link to the ticket on the public site. - Updated ITelegramNotifier interface to include the new notification method. - Modified ReopenTicketCommandHandler to invoke the new notification method after a ticket is reopened. - Enhanced unit tests for ReopenTicketCommandHandler to verify the notification functionality.
72 lines
2.7 KiB
C#
72 lines
2.7 KiB
C#
using NSubstitute;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Support;
|
|
using PnvPanel.Application.Support.Reopen;
|
|
using PnvPanel.Application.Tests.TestSupport;
|
|
using PnvPanel.Domain.Support;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Application.Tests.Support;
|
|
|
|
public class ReopenTicketCommandHandlerTests
|
|
{
|
|
private readonly ITelegramNotifier _telegramNotifier = Substitute.For<ITelegramNotifier>();
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenResolved_SetsOpen()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var ticket = SupportTicket.CreateBugReport(userId);
|
|
ticket.Resolve();
|
|
dbContext.SupportTickets.Add(ticket);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var currentUser = FakeCurrentUser.Authenticated(userId);
|
|
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
|
|
|
|
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.Equal(TicketStatus.Open, ticket.Status);
|
|
await _telegramNotifier.Received(1).NotifyAdminsTicketReopenedAsync(
|
|
ticket.Id, Arg.Any<string>(), TicketType.BugReport, Arg.Any<CancellationToken>());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenOpen_ReturnsNotResolved()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var ticket = SupportTicket.CreateBugReport(userId);
|
|
dbContext.SupportTickets.Add(ticket);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var currentUser = FakeCurrentUser.Authenticated(userId);
|
|
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
|
|
|
|
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
|
|
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(SupportErrors.NotResolved, result.Error);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenNotOwner_ReturnsNotFound()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
ticket.Resolve();
|
|
dbContext.SupportTickets.Add(ticket);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid());
|
|
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
|
|
|
|
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
|
|
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(SupportErrors.NotFound, result.Error);
|
|
}
|
|
}
|