Skip to content

Commit

Permalink
feat: deal get mailMessages endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRouyer committed Jun 18, 2021
1 parent 7e7c6d8 commit f69ad24
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 1 deletion.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ You can debug this library right from your application by configuring the [NuGet
- [x] getDealFiles
- [x] getDealUpdates
- [x] getDealFollowers
- [ ] getDealMailMessages
- [x] getDealMailMessages
- [x] getDealParticipants
- [ ] getDealUsers
- [ ] getDealPersons
Expand Down
59 changes: 59 additions & 0 deletions src/Pipedrive.net.Tests.Integration/Clients/DealsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,65 @@ public async Task CanDeleteFollower()
}
}

public class TheGetMailMessagesMethod
{
[IntegrationTest]
public async Task ReturnsCorrectCountWithoutStart()
{
var pipedrive = Helper.GetAuthenticatedClient();

var options = new DealMailMessageFilters
{
PageSize = 3,
PageCount = 1
};

var dealMailMessages = await pipedrive.Deal.GetMailMessages(1, options);
Assert.Equal(3, dealMailMessages.Count);
}

[IntegrationTest]
public async Task ReturnsCorrectCountWithStart()
{
var pipedrive = Helper.GetAuthenticatedClient();

var options = new DealMailMessageFilters
{
PageSize = 2,
PageCount = 1,
StartPage = 1
};

var dealMailMessages = await pipedrive.Deal.GetMailMessages(1, options);
Assert.Equal(2, dealMailMessages.Count);
}

[IntegrationTest]
public async Task ReturnsDistinctInfosBasedOnStartPage()
{
var pipedrive = Helper.GetAuthenticatedClient();

var startOptions = new DealMailMessageFilters
{
PageSize = 1,
PageCount = 1
};

var firstPage = await pipedrive.Deal.GetMailMessages(1, startOptions);

var skipStartOptions = new DealMailMessageFilters
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};

var secondPage = await pipedrive.Deal.GetMailMessages(1, skipStartOptions);

Assert.NotEqual(firstPage[0].Data.Id, secondPage[0].Data.Id);
}
}

public class TheGetActivitiesMethod
{
[IntegrationTest]
Expand Down
37 changes: 37 additions & 0 deletions src/Pipedrive.net.Tests/Clients/DealsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,43 @@ public void DeletesCorrectUrl()
}
}

public class TheGetMailMessagesMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new DealsClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetMailMessages(1, null));
}

[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new DealsClient(connection);

var filters = new DealMailMessageFilters
{
PageSize = 1,
PageCount = 1,
StartPage = 0,
};

await client.GetMailMessages(123, filters);

Received.InOrder(async () =>
{
await connection.GetAll<EntityUpdateFlow>(
Arg.Is<Uri>(u => u.ToString() == "deals/123/mailMessages"),
Arg.Is<Dictionary<string, string>>(d => d.Count == 0),
Arg.Is<ApiOptions>(o => o.PageSize == 1
&& o.PageCount == 1
&& o.StartPage == 0));
});
}
}

public class TheGetActivitiesMethod
{
[Fact]
Expand Down
15 changes: 15 additions & 0 deletions src/Pipedrive.net/Clients/DealsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ public Task DeleteFollower(long dealId, long followerId)
return ApiConnection.Delete(ApiUrls.DeleteDealFollower(dealId, followerId));
}

public Task<IReadOnlyList<EntityUpdateFlow>> GetMailMessages(long dealId, DealMailMessageFilters filters)
{
Ensure.ArgumentNotNull(filters, nameof(filters));

var parameters = filters.Parameters;
var options = new ApiOptions
{
StartPage = filters.StartPage,
PageCount = filters.PageCount,
PageSize = filters.PageSize
};

return ApiConnection.GetAll<EntityUpdateFlow>(ApiUrls.DealMailMessages(dealId), parameters, options);
}

public Task<IReadOnlyList<DealActivity>> GetActivities(long dealId, DealActivityFilters filters)
{
Ensure.ArgumentNotNull(filters, nameof(filters));
Expand Down
2 changes: 2 additions & 0 deletions src/Pipedrive.net/Clients/IDealsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface IDealsClient

Task DeleteFollower(long dealId, long followerId);

Task<IReadOnlyList<EntityUpdateFlow>> GetMailMessages(long dealId, DealMailMessageFilters filters);

Task<IReadOnlyList<DealActivity>> GetActivities(long dealId, DealActivityFilters filters);

Task<IReadOnlyList<DealParticipant>> GetParticipants(long dealId, DealParticipantFilters filters);
Expand Down
9 changes: 9 additions & 0 deletions src/Pipedrive.net/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ public static Uri DealUpdates(long id)
return new Uri($"deals/{id}/flow", UriKind.Relative);
}

/// <summary>
/// Returns the <see cref="Uri"/> for all the mail messages of the specified deal.
/// </summary>
/// <param name="id">The id of the deal</param>
public static Uri DealMailMessages(long id)
{
return new Uri($"deals/{id}/mailMessages", UriKind.Relative);
}

/// <summary>
/// Returns the <see cref="Uri"/> for all the followers of the specified deal.
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions src/Pipedrive.net/Models/Request/Deals/DealMailMessageFilters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;

namespace Pipedrive
{
public class DealMailMessageFilters
{
public static DealMailMessageFilters None
{
get { return new DealMailMessageFilters(); }
}

public int? StartPage { get; set; }

public int? PageCount { get; set; }

public int? PageSize { get; set; }

/// <summary>
/// Get the query parameters that will be appending onto the search
/// </summary>
public IDictionary<string, string> Parameters
{
get
{
var d = new Dictionary<string, string>();
return d;
}
}
}
}

0 comments on commit f69ad24

Please sign in to comment.