Skip to content

Commit

Permalink
re #19767 - External orders - CRM bubble + hubspot sdk (#41)
Browse files Browse the repository at this point in the history
* re #19767 - External orders - CRM bubble + hubspot sdk

Added http client to retrieve pipelines. Added unit tests for the module.
Updated deal model to include pipeline.
Retrieving a deal will also retrieve the pipeline associated.

* re #19767 - External orders - CRM bubble + hubspot sdk

Implemented PR feedback

* re #19767 - External orders - CRM bubble + hubspot sdk

Fix feedback. Pass NotFoundException as paramater instead of manually creating it.

* Test commit

* re #19767 - External orders - CRM bubble + hubspot sdk

Remove API request to retrieve associated Pipeline for deal. Cleanup deal model to only contain the pipeline guid. Cleanup unit tests for pipeline module.
  • Loading branch information
diaconu96vi authored Nov 17, 2021
1 parent 002b914 commit 35bb505
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 34 deletions.
2 changes: 0 additions & 2 deletions src/HubSpot/Deals/Deal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class Deal : IHubSpotDealEntity
[CustomProperty("pipeline")]
public string PipelineGuid { get; set; }

public Pipeline Pipeline { get; set; }

public IReadOnlyList<long> AssociatedCompanyIds { get; set; } = Array.Empty<long>();

public IReadOnlyList<long> AssociatedContactIds { get; set; } = Array.Empty<long>();
Expand Down
1 change: 0 additions & 1 deletion src/HubSpot/Deals/HubSpotDealConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public HubSpotDealConnector(IHubSpotClient client, IDealTypeManager typeManager)
{
var hubspotDeal = await selector.GetDeal(_client).ConfigureAwait(false);
var deal = _typeManager.ConvertTo<TDeal>(hubspotDeal);
deal.Pipeline = await _client.Pipelines.GetByGuidAsync(deal.PipelineGuid);
return deal;
}
catch (NotFoundException)
Expand Down
32 changes: 1 addition & 31 deletions tests/Tests.HubSpot/Deals/HubSpotDealConnectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ public async Task GetAsync_invokes_deal_type_manager_to_convert_selector_result(
}

[Test, CustomAutoData]
public async Task GetAsync_returns_converted_deal([Frozen] IDealTypeManager dealTypeManager, [Frozen] IHubSpotClient hubSpotClient, [Frozen] IDealSelector dealSelector, HubSpotDealConnector sut, IFixture fixture)
public async Task GetAsync_returns_converted_deal([Frozen] IDealTypeManager dealTypeManager, [Frozen] IHubSpotClient hubSpotClient, [Frozen] IDealSelector dealSelector, HubSpot.Deals.Deal convertedDeal, HubSpotDealConnector sut, IFixture fixture)
{
//Arrange
var convertedDeal = fixture.Build<HubSpot.Deals.Deal>().Without(x => x.Pipeline).Create();
Mock.Get(dealTypeManager).Setup(x => x.ConvertTo<HubSpot.Deals.Deal>(It.IsAny<HubSpot.Model.Deals.Deal>())).Returns(convertedDeal);
Mock.Get(hubSpotClient).Setup(x => x.Pipelines.GetByGuidAsync(It.IsAny<string>())).Returns(Task.FromResult((Pipeline)null));

//Act
var result = await sut.GetAsync<HubSpot.Deals.Deal>(dealSelector);
Expand All @@ -81,21 +79,6 @@ public async Task GetAsync_returns_converted_deal([Frozen] IDealTypeManager deal
Assert.That(result, Is.EqualTo(convertedDeal));
}

[Test, CustomAutoData]
public async Task GetAsync_returns_deal_with_pipeline_retrieved_by_http_client([Frozen] IDealTypeManager dealTypeManager, [Frozen] IHubSpotClient hubSpotClient, [Frozen] IDealSelector dealSelector, HubSpotDealConnector sut, IFixture fixture, Pipeline pipeline)
{
//Arrange
var convertedDeal = fixture.Build<HubSpot.Deals.Deal>().Without(x => x.Pipeline).Create();
Mock.Get(dealTypeManager).Setup(x => x.ConvertTo<HubSpot.Deals.Deal>(It.IsAny<HubSpot.Model.Deals.Deal>())).Returns(convertedDeal);
Mock.Get(hubSpotClient).Setup(x => x.Pipelines.GetByGuidAsync(It.IsAny<string>())).Returns(Task.FromResult(pipeline));

//Act
var result = await sut.GetAsync<HubSpot.Deals.Deal>(dealSelector);

//Assert
Assert.That(result.Pipeline, Is.EqualTo(pipeline));
}

[Test, CustomAutoData]
public async Task GetAsync_returns_null_if_deal_retrieving_throws_NotFoundException([Frozen] IHubSpotClient hubSpotClient, [Frozen] IDealSelector dealSelector, HubSpotDealConnector sut, NotFoundException notFoundException)
{
Expand All @@ -108,18 +91,5 @@ public async Task GetAsync_returns_null_if_deal_retrieving_throws_NotFoundExcept
//Assert
Assert.That(result, Is.Null);
}

[Test, CustomAutoData]
public async Task GetAsync_returns_null_if_pipeline_retrieving_throws_NotFoundeException([Frozen] IHubSpotClient hubSpotClient, [Frozen] IDealSelector dealSelector, HubSpotDealConnector sut, NotFoundException notFoundException)
{
//Arrange
Mock.Get(hubSpotClient).Setup(x => x.Pipelines.GetByGuidAsync(It.IsAny<string>())).Throws(notFoundException);

//Act
var result = await sut.GetAsync<HubSpot.Deals.Deal>(dealSelector);

//Assert
Assert.That(result, Is.Null);
}
}
}

0 comments on commit 35bb505

Please sign in to comment.