Skip to content

Commit

Permalink
573 | Add feature for deleting tickets permanently, Add async method …
Browse files Browse the repository at this point in the history
…for delete ticket permanently (#580)

Co-authored-by: palani-c <[email protected]>
  • Loading branch information
PalaniappanC and palani-c authored Oct 12, 2023
1 parent 430d1bd commit 9bdab30
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/ZendeskApi_v2/Requests/Tickets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public interface ITickets : ICore

bool DeleteMultiple(IEnumerable<long> ids);

bool DeleteTicketPermanently(long id);

GroupUserResponse GetCollaborators(long id);

GroupTicketResponse GetIncidents(long id);
Expand Down Expand Up @@ -205,6 +207,8 @@ public interface ITickets : ICore

Task<bool> DeleteMultipleAsync(IEnumerable<long> ids);

Task<bool> DeleteTicketPermanentlyAsync(long id);

Task<GroupUserResponse> GetCollaboratorsAsync(long id);

Task<GroupTicketResponse> GetIncidentsAsync(long id);
Expand Down Expand Up @@ -278,6 +282,7 @@ public interface ITickets : ICore
public class Tickets : Core, ITickets
{
private const string _tickets = "tickets";
private const string _deletedTickets = "deleted_tickets";
private const string _imports = "imports";
private const string _create_many = "create_many";
private const string _ticket_forms = "ticket_forms";
Expand Down Expand Up @@ -478,6 +483,16 @@ public bool DeleteMultiple(IEnumerable<long> ids)
return GenericDelete($"{_tickets}/destroy_many.json?ids={ids.ToCsv()}");
}

/// <summary>
/// Permanently deletes a soft-deleted ticket
/// </summary>
/// <param name="id">Id of ticket to be permanently deleted.</param>
/// <returns>Boolean response</returns>
public bool DeleteTicketPermanently(long id)
{
return GenericDelete($"{_deletedTickets}/{id}.json");
}

/// <summary>
/// Merges the source tickets in the "ids" list into the target ticket with comments as defined.
/// </summary>
Expand Down Expand Up @@ -848,6 +863,16 @@ public async Task<bool> DeleteMultipleAsync(IEnumerable<long> ids)
return await GenericDeleteAsync($"{_tickets}/destroy_many.json?ids={ids.ToCsv()}");
}

/// <summary>
/// Permanently deletes a soft-deleted ticket
/// </summary>
/// <param name="id">Id of ticket to be permanently deleted.</param>
/// <returns>Boolean response</returns>
public async Task<bool> DeleteTicketPermanentlyAsync(long id)
{
return await GenericDeleteAsync($"{_deletedTickets}/{id}.json");
}

public async Task<GroupUserResponse> GetCollaboratorsAsync(long id)
{
return await GenericGetAsync<GroupUserResponse>($"{_tickets}/{id}/collaborators.json");
Expand Down
53 changes: 53 additions & 0 deletions tests/ZendeskApi_v2.Tests/TicketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,36 @@ public void CanCreateUpdateAndDeleteTicket()
});
}

[Test]
public void CanPermanentlyDeleteTicket()
{
var ticket = new Ticket
{
Subject = "my printer is on fire",
Comment = new Comment() { Body = "HELP" },
Priority = TicketPriorities.Urgent,
CustomFields = new List<CustomField>()
{
new CustomField()
{
Id = Settings.CustomFieldId,
Value = "testing"
}
}
};

var res = Api.Tickets.CreateTicket(ticket).Ticket;

Assert.That(res, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(res.Id, Is.GreaterThan(0));
Assert.That(res.UpdatedAt, Is.EqualTo(res.CreatedAt));
Assert.That(Api.Tickets.Delete(res.Id.Value), Is.True);
Assert.That(Api.Tickets.DeleteTicketPermanently(res.Id.Value), Is.True);
});
}

[Test]
public void CanCreateUpdateAndDeleteHTMLTicket()
{
Expand Down Expand Up @@ -1767,4 +1797,27 @@ public async Task CanGetIncrementalTicketExportNextPageAsync()

Assert.That(res.Tickets, Is.Not.Empty);
}

[Test]
public async Task CanPermanentlyDeleteTicketAsync()
{
var ticket = new Ticket
{
Subject = "my printer is on fire",
Comment = new Comment() { Body = "HELP" },
Priority = TicketPriorities.Urgent,
};

var res = await Api.Tickets.CreateTicketAsync(ticket);
var deleteRes = await Api.Tickets.DeleteAsync(res.Ticket.Id.Value);
var deleteAsyncRes = await Api.Tickets.DeleteTicketPermanentlyAsync(res.Ticket.Id.Value);

Assert.Multiple(() =>
{
Assert.That(res, Is.Not.Null);
Assert.That(res.Ticket, Is.Not.Null);
Assert.That(deleteRes, Is.True);
Assert.That(deleteAsyncRes, Is.True);
});
}
}

0 comments on commit 9bdab30

Please sign in to comment.