Add notification for ticket reopening to Telegram admins
- 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.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using NSubstitute;
|
||||
using PnvPanel.Application.Common.Interfaces;
|
||||
using PnvPanel.Application.Support;
|
||||
using PnvPanel.Application.Support.Reopen;
|
||||
using PnvPanel.Application.Tests.TestSupport;
|
||||
@@ -8,6 +10,8 @@ namespace PnvPanel.Application.Tests.Support;
|
||||
|
||||
public class ReopenTicketCommandHandlerTests
|
||||
{
|
||||
private readonly ITelegramNotifier _telegramNotifier = Substitute.For<ITelegramNotifier>();
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenResolved_SetsOpen()
|
||||
{
|
||||
@@ -19,12 +23,14 @@ public class ReopenTicketCommandHandlerTests
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var currentUser = FakeCurrentUser.Authenticated(userId);
|
||||
var handler = new ReopenTicketCommandHandler(dbContext, currentUser);
|
||||
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]
|
||||
@@ -37,7 +43,7 @@ public class ReopenTicketCommandHandlerTests
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var currentUser = FakeCurrentUser.Authenticated(userId);
|
||||
var handler = new ReopenTicketCommandHandler(dbContext, currentUser);
|
||||
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
|
||||
|
||||
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
|
||||
|
||||
@@ -55,7 +61,7 @@ public class ReopenTicketCommandHandlerTests
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid());
|
||||
var handler = new ReopenTicketCommandHandler(dbContext, currentUser);
|
||||
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
|
||||
|
||||
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user