From 35bb505017d576a91613edfa47a0fdd91c423df8 Mon Sep 17 00:00:00 2001 From: Diaconu Ionut-Victor <36921680+diaconu96vi@users.noreply.github.com> Date: Wed, 17 Nov 2021 15:33:22 +0100 Subject: [PATCH] re #19767 - External orders - CRM bubble + hubspot sdk (#41) * 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. --- src/HubSpot/Deals/Deal.cs | 2 -- src/HubSpot/Deals/HubSpotDealConnector.cs | 1 - .../Deals/HubSpotDealConnectorTests.cs | 32 +------------------ 3 files changed, 1 insertion(+), 34 deletions(-) diff --git a/src/HubSpot/Deals/Deal.cs b/src/HubSpot/Deals/Deal.cs index 79a006c..245689e 100644 --- a/src/HubSpot/Deals/Deal.cs +++ b/src/HubSpot/Deals/Deal.cs @@ -36,8 +36,6 @@ public class Deal : IHubSpotDealEntity [CustomProperty("pipeline")] public string PipelineGuid { get; set; } - public Pipeline Pipeline { get; set; } - public IReadOnlyList AssociatedCompanyIds { get; set; } = Array.Empty(); public IReadOnlyList AssociatedContactIds { get; set; } = Array.Empty(); diff --git a/src/HubSpot/Deals/HubSpotDealConnector.cs b/src/HubSpot/Deals/HubSpotDealConnector.cs index de6175c..98e9a67 100644 --- a/src/HubSpot/Deals/HubSpotDealConnector.cs +++ b/src/HubSpot/Deals/HubSpotDealConnector.cs @@ -30,7 +30,6 @@ public HubSpotDealConnector(IHubSpotClient client, IDealTypeManager typeManager) { var hubspotDeal = await selector.GetDeal(_client).ConfigureAwait(false); var deal = _typeManager.ConvertTo(hubspotDeal); - deal.Pipeline = await _client.Pipelines.GetByGuidAsync(deal.PipelineGuid); return deal; } catch (NotFoundException) diff --git a/tests/Tests.HubSpot/Deals/HubSpotDealConnectorTests.cs b/tests/Tests.HubSpot/Deals/HubSpotDealConnectorTests.cs index 8494519..2e28446 100644 --- a/tests/Tests.HubSpot/Deals/HubSpotDealConnectorTests.cs +++ b/tests/Tests.HubSpot/Deals/HubSpotDealConnectorTests.cs @@ -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().Without(x => x.Pipeline).Create(); Mock.Get(dealTypeManager).Setup(x => x.ConvertTo(It.IsAny())).Returns(convertedDeal); - Mock.Get(hubSpotClient).Setup(x => x.Pipelines.GetByGuidAsync(It.IsAny())).Returns(Task.FromResult((Pipeline)null)); //Act var result = await sut.GetAsync(dealSelector); @@ -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().Without(x => x.Pipeline).Create(); - Mock.Get(dealTypeManager).Setup(x => x.ConvertTo(It.IsAny())).Returns(convertedDeal); - Mock.Get(hubSpotClient).Setup(x => x.Pipelines.GetByGuidAsync(It.IsAny())).Returns(Task.FromResult(pipeline)); - - //Act - var result = await sut.GetAsync(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) { @@ -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())).Throws(notFoundException); - - //Act - var result = await sut.GetAsync(dealSelector); - - //Assert - Assert.That(result, Is.Null); - } } }