Skip to content

Commit

Permalink
feat: deal get persons endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRouyer committed Jun 18, 2021
1 parent f69ad24 commit 8838bb7
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 4 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ You can debug this library right from your application by configuring the [NuGet
- [x] getDealMailMessages
- [x] getDealParticipants
- [ ] getDealUsers
- [ ] getDealPersons
- [x] getDealPersons
- [x] getDealProducts
- [x] addDeal
- [ ] duplicateDeal
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 @@ -554,6 +554,65 @@ public async Task ReturnsDistinctInfosBasedOnStartPage()
}
}

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

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

var dealPersons = await pipedrive.Deal.GetPersons(4, options);
Assert.Equal(3, dealPersons.Count);
}

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

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

var dealPersons = await pipedrive.Deal.GetPersons(4, options);
Assert.Equal(2, dealPersons.Count);
}

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

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

var firstPage = await pipedrive.Deal.GetPersons(4, startOptions);

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

var secondPage = await pipedrive.Deal.GetPersons(4, skipStartOptions);

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

public class TheGetParticipantsMethod
{
[IntegrationTest]
Expand Down
40 changes: 38 additions & 2 deletions src/Pipedrive.net.Tests/Clients/DealsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,43 @@ await connection.GetAll<DealActivity>(
}
}

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

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

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

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

await client.GetPersons(123, filters);

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

public class TheGetParticipantsMethod
{
[Fact]
Expand Down Expand Up @@ -605,8 +642,7 @@ public async Task RequestsCorrectUrl()
{
await connection.GetAll<DealParticipant>(
Arg.Is<Uri>(u => u.ToString() == "deals/123/participants"),
Arg.Is<Dictionary<string, string>>(d => d.Count == 1
&& d["id"] == "123"),
Arg.Is<Dictionary<string, string>>(d => d.Count == 0),
Arg.Is<ApiOptions>(o => o.PageSize == 1
&& o.PageCount == 1
&& o.StartPage == 0));
Expand Down
16 changes: 15 additions & 1 deletion src/Pipedrive.net/Clients/DealsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,26 @@ public Task<IReadOnlyList<DealActivity>> GetActivities(long dealId, DealActivity
return ApiConnection.GetAll<DealActivity>(ApiUrls.DealActivities(dealId), parameters, options);
}

public Task<IReadOnlyList<Person>> GetPersons(long dealId, DealPersonFilters 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<Person>(ApiUrls.DealPersons(dealId), parameters, options);
}

public Task<IReadOnlyList<DealParticipant>> GetParticipants(long dealId, DealParticipantFilters filters)
{
Ensure.ArgumentNotNull(filters, nameof(filters));

var parameters = filters.Parameters;
parameters.Add("id", dealId.ToString());
var options = new ApiOptions
{
StartPage = filters.StartPage,
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 @@ -46,6 +46,8 @@ public interface IDealsClient

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

Task<IReadOnlyList<Person>> GetPersons(long dealId, DealPersonFilters filters);

Task<IReadOnlyList<DealParticipant>> GetParticipants(long dealId, DealParticipantFilters filters);

Task<DealParticipant> AddParticipant(long dealId, long personId);
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 @@ -195,6 +195,15 @@ public static Uri DealActivities(long id)
return new Uri($"deals/{id}/activities", UriKind.Relative);
}

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

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

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

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 8838bb7

Please sign in to comment.