Skip to content

Commit f6d99a9

Browse files
committed
2 parents afd18b0 + 55ebfbe commit f6d99a9

30 files changed

+1570
-14
lines changed

src/Pipedrive.net.Tests.Integration/Clients/DealsClientTests.cs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using Pipedrive.CustomFields;
5+
using Pipedrive.Models.Request;
46
using Xunit;
57

68
namespace Pipedrive.Tests.Integration.Clients
@@ -101,12 +103,15 @@ public async Task CanCreate()
101103
var fixture = pipedrive.Deal;
102104

103105
var newDeal = new NewDeal("title");
106+
newDeal.CustomFields["8bbb7cf46a85a3a42538d500a29ecc8ac244eacd"] = new StringCustomField("my custom string field");
104107

105108
var deal = await fixture.Create(newDeal);
109+
Assert.Equal("my custom string field", ((StringCustomField)deal.CustomFields["8bbb7cf46a85a3a42538d500a29ecc8ac244eacd"]).Value);
106110
Assert.NotNull(deal);
107111

108112
var retrieved = await fixture.Get(deal.Id);
109113
Assert.NotNull(retrieved);
114+
Assert.Equal("my custom string field", ((StringCustomField)retrieved.CustomFields["8bbb7cf46a85a3a42538d500a29ecc8ac244eacd"]).Value);
110115

111116
// Cleanup
112117
await fixture.Delete(deal.Id);
@@ -436,5 +441,101 @@ public async Task CanDeleteParticipant()
436441
await fixture.DeleteParticipant(1, 5);
437442
}
438443
}
444+
445+
public class TheGetProductsForDealMethod
446+
{
447+
[IntegrationTest]
448+
public async Task GetProductsForDeal()
449+
{
450+
var dealProductFilters = new DealProductFilters
451+
{
452+
PageSize = 2,
453+
PageCount = 1,
454+
StartPage = 0,
455+
IncludeProductData = "1"
456+
};
457+
458+
var pipedrive = Helper.GetAuthenticatedClient();
459+
var fixture = pipedrive.Deal;
460+
461+
var dealProducts = await fixture.GetProductsForDeal(1, dealProductFilters);
462+
463+
Assert.Equal(2, dealProducts.Count);
464+
Assert.True(dealProducts.All(x => x.DealId == 1));
465+
}
466+
}
467+
468+
public class TheAddProductToDealMethod
469+
{
470+
[IntegrationTest]
471+
public async Task AddProductToDeal()
472+
{
473+
var newDealProduct = new NewDealProduct(1, 10, 30)
474+
{
475+
DiscountPercentage = 55,
476+
EnabledFlag = true
477+
};
478+
479+
var pipedrive = Helper.GetAuthenticatedClient();
480+
var fixture = pipedrive.Deal;
481+
482+
var dealProduct = await fixture.AddProductToDeal(1, newDealProduct);
483+
484+
Assert.Equal(1, dealProduct.DealId);
485+
Assert.Equal(1, dealProduct.ProductId);
486+
Assert.Equal(10, dealProduct.ItemPrice);
487+
Assert.Equal(30, dealProduct.Quantity);
488+
Assert.Equal(135, dealProduct.Sum);
489+
Assert.Equal(55, dealProduct.DiscountPercentage);
490+
491+
// Cleanup
492+
await fixture.DeleteDealProduct(1, dealProduct.ProductAttachmentId.Value);
493+
}
494+
}
495+
496+
public class TheUpdateDealProductMethod
497+
{
498+
[IntegrationTest]
499+
public async Task UpdateDealProduct()
500+
{
501+
var pipedrive = Helper.GetAuthenticatedClient();
502+
var fixture = pipedrive.Deal;
503+
504+
var createdDealProduct = await fixture.AddProductToDeal(1, new NewDealProduct(1, 10, 30));
505+
506+
var dealProductUpdate = new DealProductUpdate
507+
{
508+
ItemPrice = 44,
509+
Quantity = 1,
510+
Duration = 1,
511+
DiscountPercentage = 11
512+
};
513+
514+
var updatedDealProduct = await fixture.UpdateDealProduct(1, createdDealProduct.ProductAttachmentId.Value, dealProductUpdate);
515+
516+
Assert.Equal(1, updatedDealProduct.DealId);
517+
Assert.Equal(1, updatedDealProduct.ProductId);
518+
Assert.Equal(44, updatedDealProduct.ItemPrice);
519+
Assert.Equal(1, updatedDealProduct.Quantity);
520+
Assert.Equal(39.16m, updatedDealProduct.Sum);
521+
522+
// Cleanup
523+
await fixture.DeleteDealProduct(1, createdDealProduct.ProductAttachmentId.Value);
524+
}
525+
}
526+
527+
public class TheDeleteDealProductMethod
528+
{
529+
[IntegrationTest]
530+
public async Task DeleteDealProduct()
531+
{
532+
var pipedrive = Helper.GetAuthenticatedClient();
533+
var fixture = pipedrive.Deal;
534+
535+
var dealProduct = await fixture.AddProductToDeal(1, new NewDealProduct(1, 10, 30));
536+
537+
await fixture.DeleteDealProduct(1, dealProduct.ProductAttachmentId.Value);
538+
}
539+
}
439540
}
440541
}
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Pipedrive.Models.Request;
5+
using Xunit;
6+
7+
namespace Pipedrive.Tests.Integration.Clients
8+
{
9+
public class ProductsClientTests
10+
{
11+
public class TheGetAllMethod
12+
{
13+
[IntegrationTest]
14+
public async Task ReturnsCorrectCountWithoutStart()
15+
{
16+
var pipedrive = Helper.GetAuthenticatedClient();
17+
18+
var options = new ProductFilters
19+
{
20+
PageSize = 3,
21+
PageCount = 1
22+
};
23+
24+
var products = await pipedrive.Product.GetAll(options);
25+
Assert.Equal(3, products.Count);
26+
}
27+
28+
[IntegrationTest]
29+
public async Task ReturnsCorrectCountWithStart()
30+
{
31+
var pipedrive = Helper.GetAuthenticatedClient();
32+
33+
var options = new ProductFilters
34+
{
35+
PageSize = 2,
36+
PageCount = 1,
37+
StartPage = 1
38+
};
39+
40+
var products = await pipedrive.Product.GetAll(options);
41+
Assert.Equal(2, products.Count);
42+
}
43+
44+
[IntegrationTest]
45+
public async Task ReturnsDistinctInfosBasedOnStartPage()
46+
{
47+
var pipedrive = Helper.GetAuthenticatedClient();
48+
49+
var startOptions = new ProductFilters
50+
{
51+
PageSize = 1,
52+
PageCount = 1
53+
};
54+
55+
var firstPage = await pipedrive.Product.GetAll(startOptions);
56+
57+
var skipStartOptions = new ProductFilters
58+
{
59+
PageSize = 1,
60+
PageCount = 1,
61+
StartPage = 1
62+
};
63+
64+
var secondPage = await pipedrive.Product.GetAll(skipStartOptions);
65+
66+
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
67+
}
68+
}
69+
70+
public class TheGetByNameMethod
71+
{
72+
[IntegrationTest]
73+
public async Task CanRetrieveProductsByName()
74+
{
75+
var pipedrive = Helper.GetAuthenticatedClient();
76+
77+
var products = await pipedrive.Product.GetByName("productname", "GBP");
78+
79+
Assert.True(products.Count == 1);
80+
Assert.Equal(12.32M, products[0].Price);
81+
}
82+
}
83+
84+
public class TheGetMethod
85+
{
86+
[IntegrationTest]
87+
public async Task CanRetrieveProduct()
88+
{
89+
var pipedrive = Helper.GetAuthenticatedClient();
90+
91+
var product = await pipedrive.Product.Get(2);
92+
93+
Assert.Equal("productname", product.Name);
94+
}
95+
}
96+
97+
public class TheGetDealsForProductMethod
98+
{
99+
[IntegrationTest]
100+
public async Task CanRetrieveDeals()
101+
{
102+
var pipedrive = Helper.GetAuthenticatedClient();
103+
104+
var deals = await pipedrive.Product.GetDealsForProduct(2);
105+
106+
Assert.Equal(1, deals.Count);
107+
}
108+
}
109+
110+
public class TheGetFilesForProductMethod
111+
{
112+
[IntegrationTest]
113+
public async Task ReturnsCorrectCount()
114+
{
115+
var pipedrive = Helper.GetAuthenticatedClient();
116+
117+
var files = await pipedrive.Product.GetFilesForProduct(1);
118+
119+
Assert.Equal(1, files.Count);
120+
}
121+
}
122+
123+
public class TheGetFollowersForProductMethod
124+
{
125+
[IntegrationTest]
126+
public async Task ReturnsCorrectCount()
127+
{
128+
var pipedrive = Helper.GetAuthenticatedClient();
129+
130+
var followers = await pipedrive.Product.GetFollowersForProduct(1);
131+
132+
Assert.Equal(1, followers.Count);
133+
}
134+
}
135+
136+
public class TheGetPermittedUsersMethod
137+
{
138+
[IntegrationTest]
139+
public async Task ReturnsCorrectCount()
140+
{
141+
var pipedrive = Helper.GetAuthenticatedClient();
142+
143+
var permittedUsers = await pipedrive.Product.GetPermittedUsers(2);
144+
145+
Assert.Equal(2, permittedUsers.Count);
146+
}
147+
}
148+
149+
public class TheCreateMethod
150+
{
151+
[IntegrationTest]
152+
public async Task CanCreate()
153+
{
154+
var pipedrive = Helper.GetAuthenticatedClient();
155+
var fixture = pipedrive.Product;
156+
157+
var newProduct = new NewProduct("New Product Name")
158+
{
159+
Prices = new List<NewProductPrice> { new NewProductPrice { Currency = "GBP", Price = 10.23M } }
160+
};
161+
162+
var product = await fixture.Create(newProduct);
163+
Assert.NotNull(product);
164+
165+
var retrieved = await fixture.Get(product.Id);
166+
Assert.NotNull(retrieved);
167+
Assert.Equal("GBP", retrieved.Prices.First().Currency);
168+
Assert.Equal(10.23M, retrieved.Prices.First().Price);
169+
170+
// Cleanup
171+
await fixture.Delete(product.Id);
172+
}
173+
}
174+
175+
public class TheEditMethod
176+
{
177+
[IntegrationTest]
178+
public async Task CanEdit()
179+
{
180+
var pipedrive = Helper.GetAuthenticatedClient();
181+
var fixture = pipedrive.Product;
182+
183+
var newProduct = new NewProduct("product")
184+
{
185+
Prices = new List<NewProductPrice> { new NewProductPrice { Currency = "GBP", Price = 10.23M } }
186+
};
187+
var product = await fixture.Create(newProduct);
188+
189+
var editedProduct = product.ToUpdate();
190+
editedProduct.Name = "updated-name";
191+
editedProduct.Prices.First(x => x.Currency == "GBP").Price = 20.50M;
192+
193+
var updatedProduct = await fixture.Edit(product.Id, editedProduct);
194+
195+
Assert.Equal("updated-name", updatedProduct.Name);
196+
Assert.Equal(20.50M, updatedProduct.Prices["GBP"].Price);
197+
198+
// Cleanup
199+
await fixture.Delete(updatedProduct.Id);
200+
}
201+
}
202+
203+
public class TheDeleteMethod
204+
{
205+
[IntegrationTest]
206+
public async Task CanDelete()
207+
{
208+
var pipedrive = Helper.GetAuthenticatedClient();
209+
var fixture = pipedrive.Product;
210+
211+
var newProduct = new NewProduct("new-name");
212+
var product = await fixture.Create(newProduct);
213+
214+
var createdProduct = await fixture.Get(product.Id);
215+
216+
Assert.NotNull(createdProduct);
217+
218+
await fixture.Delete(createdProduct.Id);
219+
220+
var deletedProduct = await fixture.Get(createdProduct.Id);
221+
Assert.False(deletedProduct.ActiveFlag);
222+
}
223+
}
224+
225+
public class TheAddFollowerMethod
226+
{
227+
[IntegrationTest]
228+
public async Task CanAddFollower()
229+
{
230+
var pipedrive = Helper.GetAuthenticatedClient();
231+
var fixture = pipedrive.Product;
232+
233+
var addFollower = await fixture.AddFollower(1, 9953182);
234+
Assert.NotNull(addFollower);
235+
}
236+
}
237+
238+
public class TheDeleteFollowerMethod
239+
{
240+
[IntegrationTest]
241+
public async Task CanDeleteFollower()
242+
{
243+
var pipedrive = Helper.GetAuthenticatedClient();
244+
var fixture = pipedrive.Product;
245+
246+
await fixture.DeleteFollower(1, 1);
247+
}
248+
}
249+
}
250+
}

0 commit comments

Comments
 (0)