Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRouyer committed Mar 3, 2020
2 parents afd18b0 + 55ebfbe commit f6d99a9
Show file tree
Hide file tree
Showing 30 changed files with 1,570 additions and 14 deletions.
101 changes: 101 additions & 0 deletions src/Pipedrive.net.Tests.Integration/Clients/DealsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Pipedrive.CustomFields;
using Pipedrive.Models.Request;
using Xunit;

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

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

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

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

// Cleanup
await fixture.Delete(deal.Id);
Expand Down Expand Up @@ -436,5 +441,101 @@ public async Task CanDeleteParticipant()
await fixture.DeleteParticipant(1, 5);
}
}

public class TheGetProductsForDealMethod
{
[IntegrationTest]
public async Task GetProductsForDeal()
{
var dealProductFilters = new DealProductFilters
{
PageSize = 2,
PageCount = 1,
StartPage = 0,
IncludeProductData = "1"
};

var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Deal;

var dealProducts = await fixture.GetProductsForDeal(1, dealProductFilters);

Assert.Equal(2, dealProducts.Count);
Assert.True(dealProducts.All(x => x.DealId == 1));
}
}

public class TheAddProductToDealMethod
{
[IntegrationTest]
public async Task AddProductToDeal()
{
var newDealProduct = new NewDealProduct(1, 10, 30)
{
DiscountPercentage = 55,
EnabledFlag = true
};

var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Deal;

var dealProduct = await fixture.AddProductToDeal(1, newDealProduct);

Assert.Equal(1, dealProduct.DealId);
Assert.Equal(1, dealProduct.ProductId);
Assert.Equal(10, dealProduct.ItemPrice);
Assert.Equal(30, dealProduct.Quantity);
Assert.Equal(135, dealProduct.Sum);
Assert.Equal(55, dealProduct.DiscountPercentage);

// Cleanup
await fixture.DeleteDealProduct(1, dealProduct.ProductAttachmentId.Value);
}
}

public class TheUpdateDealProductMethod
{
[IntegrationTest]
public async Task UpdateDealProduct()
{
var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Deal;

var createdDealProduct = await fixture.AddProductToDeal(1, new NewDealProduct(1, 10, 30));

var dealProductUpdate = new DealProductUpdate
{
ItemPrice = 44,
Quantity = 1,
Duration = 1,
DiscountPercentage = 11
};

var updatedDealProduct = await fixture.UpdateDealProduct(1, createdDealProduct.ProductAttachmentId.Value, dealProductUpdate);

Assert.Equal(1, updatedDealProduct.DealId);
Assert.Equal(1, updatedDealProduct.ProductId);
Assert.Equal(44, updatedDealProduct.ItemPrice);
Assert.Equal(1, updatedDealProduct.Quantity);
Assert.Equal(39.16m, updatedDealProduct.Sum);

// Cleanup
await fixture.DeleteDealProduct(1, createdDealProduct.ProductAttachmentId.Value);
}
}

public class TheDeleteDealProductMethod
{
[IntegrationTest]
public async Task DeleteDealProduct()
{
var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Deal;

var dealProduct = await fixture.AddProductToDeal(1, new NewDealProduct(1, 10, 30));

await fixture.DeleteDealProduct(1, dealProduct.ProductAttachmentId.Value);
}
}
}
}
250 changes: 250 additions & 0 deletions src/Pipedrive.net.Tests.Integration/Clients/ProductsClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Pipedrive.Models.Request;
using Xunit;

namespace Pipedrive.Tests.Integration.Clients
{
public class ProductsClientTests
{
public class TheGetAllMethod
{
[IntegrationTest]
public async Task ReturnsCorrectCountWithoutStart()
{
var pipedrive = Helper.GetAuthenticatedClient();

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

var products = await pipedrive.Product.GetAll(options);
Assert.Equal(3, products.Count);
}

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

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

var products = await pipedrive.Product.GetAll(options);
Assert.Equal(2, products.Count);
}

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

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

var firstPage = await pipedrive.Product.GetAll(startOptions);

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

var secondPage = await pipedrive.Product.GetAll(skipStartOptions);

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

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

var products = await pipedrive.Product.GetByName("productname", "GBP");

Assert.True(products.Count == 1);
Assert.Equal(12.32M, products[0].Price);
}
}

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

var product = await pipedrive.Product.Get(2);

Assert.Equal("productname", product.Name);
}
}

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

var deals = await pipedrive.Product.GetDealsForProduct(2);

Assert.Equal(1, deals.Count);
}
}

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

var files = await pipedrive.Product.GetFilesForProduct(1);

Assert.Equal(1, files.Count);
}
}

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

var followers = await pipedrive.Product.GetFollowersForProduct(1);

Assert.Equal(1, followers.Count);
}
}

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

var permittedUsers = await pipedrive.Product.GetPermittedUsers(2);

Assert.Equal(2, permittedUsers.Count);
}
}

public class TheCreateMethod
{
[IntegrationTest]
public async Task CanCreate()
{
var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Product;

var newProduct = new NewProduct("New Product Name")
{
Prices = new List<NewProductPrice> { new NewProductPrice { Currency = "GBP", Price = 10.23M } }
};

var product = await fixture.Create(newProduct);
Assert.NotNull(product);

var retrieved = await fixture.Get(product.Id);
Assert.NotNull(retrieved);
Assert.Equal("GBP", retrieved.Prices.First().Currency);
Assert.Equal(10.23M, retrieved.Prices.First().Price);

// Cleanup
await fixture.Delete(product.Id);
}
}

public class TheEditMethod
{
[IntegrationTest]
public async Task CanEdit()
{
var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Product;

var newProduct = new NewProduct("product")
{
Prices = new List<NewProductPrice> { new NewProductPrice { Currency = "GBP", Price = 10.23M } }
};
var product = await fixture.Create(newProduct);

var editedProduct = product.ToUpdate();
editedProduct.Name = "updated-name";
editedProduct.Prices.First(x => x.Currency == "GBP").Price = 20.50M;

var updatedProduct = await fixture.Edit(product.Id, editedProduct);

Assert.Equal("updated-name", updatedProduct.Name);
Assert.Equal(20.50M, updatedProduct.Prices["GBP"].Price);

// Cleanup
await fixture.Delete(updatedProduct.Id);
}
}

public class TheDeleteMethod
{
[IntegrationTest]
public async Task CanDelete()
{
var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Product;

var newProduct = new NewProduct("new-name");
var product = await fixture.Create(newProduct);

var createdProduct = await fixture.Get(product.Id);

Assert.NotNull(createdProduct);

await fixture.Delete(createdProduct.Id);

var deletedProduct = await fixture.Get(createdProduct.Id);
Assert.False(deletedProduct.ActiveFlag);
}
}

public class TheAddFollowerMethod
{
[IntegrationTest]
public async Task CanAddFollower()
{
var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Product;

var addFollower = await fixture.AddFollower(1, 9953182);
Assert.NotNull(addFollower);
}
}

public class TheDeleteFollowerMethod
{
[IntegrationTest]
public async Task CanDeleteFollower()
{
var pipedrive = Helper.GetAuthenticatedClient();
var fixture = pipedrive.Product;

await fixture.DeleteFollower(1, 1);
}
}
}
}
Loading

0 comments on commit f6d99a9

Please sign in to comment.