-
Notifications
You must be signed in to change notification settings - Fork 42
Feature/sales force lead #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
louisbaggins
wants to merge
22
commits into
master
Choose a base branch
from
feature/sales-force-lead
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e74e164
Add: Advanced config extensions
louisbaggins fe2855d
Add: ConfiguationExtension tests
louisbaggins bf6d708
Add: Configuration extension, set configuration tests
louisbaggins 826dd49
Add: Sales force and crm action models
louisbaggins 4fed7e9
Add: Integration service with sales force models
louisbaggins 5323503
Add: Sales force processor with create lead integration service
louisbaggins 12d4dcf
Refac: Separates Salesforce client from SalesForceProcessor in order …
louisbaggins c9b53ca
Add: SalesForce client integration methods
louisbaggins 7fc6740
Refac: Add equal overide method on crmconfig
louisbaggins f6f2a27
Refac: Create strategie folder
louisbaggins 7f76b66
Add: Get lead method on sales force client
louisbaggins 7d8fb42
Add: Get lead method on salesforce client
louisbaggins 87ff1b1
Merge with master
louisbaggins 79ad439
Add: ConfigurationExtension substitute on FlowManagerTestsBase
louisbaggins 5ddef20
Refac: Add async suffix on CrmProcessor async methods
louisbaggins ec250f5
Refac: Method call name
louisbaggins 478f9da
Add: Fail register lead test
louisbaggins 3028def
Fix: Refac crm config JsonProperty to adequate with json naming conve…
louisbaggins 32bf808
Refac: Change SalesForceRoutes to SalesForceUriTemplates
louisbaggins 61d8c5d
Refac: Replace HttpClient for IHttpClientFactory
louisbaggins 3005906
Refac: Enum starting as 1 to assure that default value will never be …
louisbaggins be80b98
Refac: Remove getDomaind_ShouldFailAsync test since parameter check i…
louisbaggins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
179 changes: 179 additions & 0 deletions
179
src/Take.Blip.Builder.UnitTests/Actions/GetLeadActionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Linq; | ||
| using NSubstitute; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Take.Blip.Builder.Actions.GetLead; | ||
| using Take.Blip.Builder.Models; | ||
| using Take.Blip.Builder.Strategies; | ||
| using Take.Blip.Builder.Utils.SalesForce; | ||
| using Take.Blip.Builder.Utils.SalesForce.Models; | ||
| using Take.Blip.Client.Extensions.AdvancedConfig; | ||
| using Xunit; | ||
|
|
||
| namespace Take.Blip.Builder.UnitTests.Actions | ||
| { | ||
| public class GetLeadActionTests : ActionTestsBase | ||
| { | ||
| private readonly IConfigurationExtension _configurationExtension = Substitute.For<IConfigurationExtension>(); | ||
| private readonly ICrmClient _salesForceClient = Substitute.For<ICrmClient>(); | ||
|
|
||
| private readonly ICrmContext _crmContext; | ||
| private readonly GetLeadAction _getLeadAction; | ||
|
|
||
| public GetLeadActionTests() | ||
| { | ||
| _crmContext = new CrmContext(); | ||
| _getLeadAction = new GetLeadAction( | ||
| _salesForceClient, | ||
| _crmContext, | ||
| _configurationExtension | ||
| ); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestGetLeadOnSalesForce_ShouldSuccedAsync() | ||
| { | ||
| // Arrange | ||
| var settings = new CrmSettings() | ||
| { | ||
| Crm = Crm.SalesForce, | ||
| LeadId = "1234", | ||
| ReturnValue = "sfReturn" | ||
| }; | ||
|
|
||
| var configurationResponse = new CrmConfig() | ||
| { | ||
| SalesForceConfig = new SalesForceConfig() | ||
| { | ||
| ClientId = "clientId", | ||
| ClientSecret = "clientSecret", | ||
| RefreshToken = "refreshToken" | ||
| } | ||
| }; | ||
| var salesForceConfig = configurationResponse.SalesForceConfig; | ||
|
|
||
| var mockedSalesForceAuth = new AuthorizationResponse | ||
| { | ||
| AccessToken = "123", | ||
| InstanceUrl = "salesforce.com", | ||
| TokenType = "Bearer" | ||
| }; | ||
|
|
||
| var mockedSalesForceResponse = new JObject | ||
| { | ||
| { "Id", "1234" }, | ||
| { "Email", "io@take.net" }, | ||
| { "FirstName", "John" }, | ||
| { "LastName", "Doe" }, | ||
| { "Company", "Take" } | ||
| }; | ||
|
|
||
| // Act | ||
| _configurationExtension.GetKeyValueAsync<CrmConfig>(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>()).Returns(configurationResponse); | ||
| _salesForceClient.GetAuthorizationAsync( | ||
| Arg.Is<CrmConfig>(sc => | ||
| sc.SalesForceConfig.ClientId == salesForceConfig.ClientId && | ||
| sc.SalesForceConfig.ClientSecret == salesForceConfig.ClientSecret && | ||
| sc.SalesForceConfig.RefreshToken == salesForceConfig.RefreshToken), | ||
| Context.OwnerIdentity, | ||
| Arg.Any<CancellationToken>()) | ||
| .Returns(mockedSalesForceAuth); | ||
|
|
||
| _salesForceClient.GetLeadAsync( | ||
| Arg.Is<CrmSettings>(rl => | ||
| rl.Crm == settings.Crm && | ||
| rl.ReturnValue == settings.ReturnValue | ||
| ), | ||
| Arg.Is<AuthorizationResponse>(ar => | ||
| ar.AccessToken == mockedSalesForceAuth.AccessToken && | ||
| ar.InstanceUrl == mockedSalesForceAuth.InstanceUrl && | ||
| ar.TokenType == mockedSalesForceAuth.TokenType | ||
| ), | ||
| Arg.Any<CancellationToken>() | ||
| ) | ||
| .Returns(mockedSalesForceResponse); | ||
|
|
||
| await _getLeadAction.ExecuteAsync(Context, settings, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| await Context.Received(1).SetVariableAsync( | ||
| settings.ReturnValue, | ||
| JsonConvert.SerializeObject(mockedSalesForceResponse), | ||
| CancellationToken.None | ||
| ); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestGetLeadActionTests_ShouldFailAsync() | ||
| { | ||
| // Arrange | ||
| var settings = new CrmSettings() | ||
| { | ||
| Crm = Crm.SalesForce, | ||
| LeadId = "1234", | ||
| ReturnValue = "sfReturn" | ||
| }; | ||
|
|
||
| var configurationResponse = new CrmConfig() | ||
| { | ||
| SalesForceConfig = new SalesForceConfig() | ||
| { | ||
| ClientId = "clientId", | ||
| ClientSecret = "clientSecret", | ||
| RefreshToken = "refreshToken" | ||
| } | ||
| }; | ||
| var salesForceConfig = configurationResponse.SalesForceConfig; | ||
|
|
||
| var mockedSalesForceAuth = new AuthorizationResponse | ||
| { | ||
| AccessToken = "123", | ||
| InstanceUrl = "salesforce.com", | ||
| TokenType = "Bearer" | ||
| }; | ||
|
|
||
| var mockedSalesForceResponse = new JObject | ||
| { | ||
| { "errorCode", "NOT_FOUND" }, | ||
| { "message", "Provided external ID field does not exist or is not accessible" } | ||
| }; | ||
|
|
||
| // Act | ||
| _configurationExtension.GetKeyValueAsync<CrmConfig>(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>()).Returns(configurationResponse); | ||
| _salesForceClient.GetAuthorizationAsync( | ||
| Arg.Is<CrmConfig>(sc => | ||
| sc.SalesForceConfig.ClientId == salesForceConfig.ClientId && | ||
| sc.SalesForceConfig.ClientSecret == salesForceConfig.ClientSecret && | ||
| sc.SalesForceConfig.RefreshToken == salesForceConfig.RefreshToken), | ||
| Context.OwnerIdentity, | ||
| Arg.Any<CancellationToken>()) | ||
| .Returns(mockedSalesForceAuth); | ||
|
|
||
| _salesForceClient.GetLeadAsync( | ||
| Arg.Is<CrmSettings>(rl => | ||
| rl.Crm == settings.Crm && | ||
| rl.ReturnValue == settings.ReturnValue | ||
| ), | ||
| Arg.Is<AuthorizationResponse>(ar => | ||
| ar.AccessToken == mockedSalesForceAuth.AccessToken && | ||
| ar.InstanceUrl == mockedSalesForceAuth.InstanceUrl && | ||
| ar.TokenType == mockedSalesForceAuth.TokenType | ||
| ), | ||
| Arg.Any<CancellationToken>() | ||
| ) | ||
| .Returns(mockedSalesForceResponse); | ||
|
|
||
| await _getLeadAction.ExecuteAsync(Context, settings, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| await Context.Received(1).SetVariableAsync( | ||
| settings.ReturnValue, | ||
| JsonConvert.SerializeObject(mockedSalesForceResponse), | ||
| CancellationToken.None | ||
| ); | ||
|
|
||
| } | ||
| } | ||
| } | ||
188 changes: 188 additions & 0 deletions
188
src/Take.Blip.Builder.UnitTests/Actions/RegisterLeadActionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| using Newtonsoft.Json; | ||
| using NSubstitute; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Take.Blip.Builder.Actions.CreateLead; | ||
| using Take.Blip.Builder.Models; | ||
| using Take.Blip.Builder.Strategies; | ||
| using Take.Blip.Builder.Utils.SalesForce; | ||
| using Take.Blip.Builder.Utils.SalesForce.Models; | ||
| using Take.Blip.Client.Extensions.AdvancedConfig; | ||
| using Xunit; | ||
|
|
||
| namespace Take.Blip.Builder.UnitTests.Actions | ||
| { | ||
| public class RegisterLeadActionTests : ActionTestsBase | ||
| { | ||
| private readonly IConfigurationExtension _configurationExtension = Substitute.For<IConfigurationExtension>(); | ||
| private readonly ICrmClient _crmClient = Substitute.For<ICrmClient>(); | ||
|
|
||
| private readonly ICrmContext _crmContext; | ||
| private readonly RegisterLeadAction _registerLeadAction; | ||
|
|
||
| public RegisterLeadActionTests() | ||
| { | ||
| _crmContext = new CrmContext(); | ||
| _registerLeadAction = new RegisterLeadAction( | ||
| _crmContext, | ||
| _configurationExtension, | ||
| _crmClient | ||
| ); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestCreateLeadOnSalesForce_ShouldSuccedAsync() | ||
EricJangola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // Arrange | ||
| var settings = new CrmSettings() | ||
| { | ||
| Crm = Crm.SalesForce, | ||
| LeadBody = new Dictionary<string, string>() | ||
| { | ||
| { "FirstName", "Gabriel" }, | ||
| { "LastName", "Rodrigues" }, | ||
| { "Email", "jsdpablo@take.net" }, | ||
| { "Company", "Take" }, | ||
| { "cidade__c", "Bh" }, | ||
| { "Suplemento__c", "Whey" } | ||
| }, | ||
| ReturnValue = "sfReturn" | ||
| }; | ||
|
|
||
| var configurationResponse = new CrmConfig() | ||
| { | ||
| SalesForceConfig = new SalesForceConfig() | ||
| { | ||
| ClientId = "clientId", | ||
| ClientSecret = "clientSecret", | ||
| RefreshToken = "refreshToken" | ||
| } | ||
| }; | ||
| var salesForceConfig = configurationResponse.SalesForceConfig; | ||
|
|
||
| var mockedSalesForceAuth = new AuthorizationResponse | ||
| { | ||
| AccessToken = "123", | ||
| InstanceUrl = "salesforce.com", | ||
| TokenType = "Bearer" | ||
| }; | ||
|
|
||
| var mockedSalesForceResponse = new LeadResponse | ||
| { | ||
| Message = "Deu", | ||
| Succes = true, | ||
| Id = "123" | ||
| }; | ||
|
|
||
| // Act | ||
| _configurationExtension.GetKeyValueAsync<CrmConfig>(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>()).Returns(configurationResponse); | ||
| _crmClient.GetAuthorizationAsync( | ||
| Arg.Is<CrmConfig>(sc => | ||
| sc.SalesForceConfig.ClientId == salesForceConfig.ClientId && | ||
| sc.SalesForceConfig.ClientSecret == salesForceConfig.ClientSecret && | ||
| sc.SalesForceConfig.RefreshToken == salesForceConfig.RefreshToken), | ||
| Context.OwnerIdentity, | ||
| Arg.Any<CancellationToken>()) | ||
| .Returns(mockedSalesForceAuth); | ||
|
|
||
| _crmClient.CreateLeadAsync( | ||
| Arg.Is<CrmSettings>(rl => | ||
| rl.Crm == settings.Crm && | ||
| rl.ReturnValue == settings.ReturnValue | ||
| ), | ||
| Arg.Is<AuthorizationResponse>(ar => | ||
| ar.AccessToken == mockedSalesForceAuth.AccessToken && | ||
| ar.InstanceUrl == mockedSalesForceAuth.InstanceUrl && | ||
| ar.TokenType == mockedSalesForceAuth.TokenType | ||
| )) | ||
| .Returns(mockedSalesForceResponse); | ||
|
|
||
| await _registerLeadAction.ExecuteAsync(Context, settings, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| await Context.Received(1).SetVariableAsync( | ||
| settings.ReturnValue, | ||
| JsonConvert.SerializeObject(mockedSalesForceResponse), | ||
| CancellationToken.None | ||
| ); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestCreateLeadOnSalesForce_ShouldFailAsync() | ||
| { | ||
| // Arrange | ||
| var settings = new CrmSettings() | ||
| { | ||
| Crm = Crm.SalesForce, | ||
| LeadBody = new Dictionary<string, string>() | ||
| { | ||
| { "FirstName", "Gabriel" }, | ||
| { "LastName", "Rodrigues" }, | ||
| { "Email", "jsdpablo@take.net" }, | ||
| { "Company", "Take" }, | ||
| { "cidade__c", "Bh" }, | ||
| { "Suplemento__c", "Whey" } | ||
| }, | ||
| ReturnValue = "sfReturn" | ||
| }; | ||
|
|
||
| var configurationResponse = new CrmConfig() | ||
| { | ||
| SalesForceConfig = new SalesForceConfig() | ||
| { | ||
| ClientId = "clientId", | ||
| ClientSecret = "clientSecret", | ||
| RefreshToken = "refreshToken" | ||
| } | ||
| }; | ||
| var salesForceConfig = configurationResponse.SalesForceConfig; | ||
|
|
||
| var mockedSalesForceAuth = new AuthorizationResponse | ||
| { | ||
| AccessToken = "123", | ||
| InstanceUrl = "salesforce.com", | ||
| TokenType = "Bearer" | ||
| }; | ||
|
|
||
| var mockedSalesForceResponse = new LeadResponse | ||
| { | ||
| Message = "Use one of these records?", | ||
| ErrorCode = "DUPLICATES_DETECTED", | ||
| Succes = false | ||
| }; | ||
|
|
||
| // Act | ||
| _configurationExtension.GetKeyValueAsync<CrmConfig>(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>()).Returns(configurationResponse); | ||
| _crmClient.GetAuthorizationAsync( | ||
| Arg.Is<CrmConfig>(sc => | ||
| sc.SalesForceConfig.ClientId == salesForceConfig.ClientId && | ||
| sc.SalesForceConfig.ClientSecret == salesForceConfig.ClientSecret && | ||
| sc.SalesForceConfig.RefreshToken == salesForceConfig.RefreshToken), | ||
| Context.OwnerIdentity, | ||
| Arg.Any<CancellationToken>()) | ||
| .Returns(mockedSalesForceAuth); | ||
|
|
||
| _crmClient.CreateLeadAsync( | ||
| Arg.Is<CrmSettings>(rl => | ||
| rl.Crm == settings.Crm && | ||
| rl.ReturnValue == settings.ReturnValue | ||
| ), | ||
| Arg.Is<AuthorizationResponse>(ar => | ||
| ar.AccessToken == mockedSalesForceAuth.AccessToken && | ||
| ar.InstanceUrl == mockedSalesForceAuth.InstanceUrl && | ||
| ar.TokenType == mockedSalesForceAuth.TokenType | ||
| )) | ||
| .Returns(mockedSalesForceResponse); | ||
|
|
||
| await _registerLeadAction.ExecuteAsync(Context, settings, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| await Context.Received(1).SetVariableAsync( | ||
| settings.ReturnValue, | ||
| JsonConvert.SerializeObject(mockedSalesForceResponse), | ||
| CancellationToken.None | ||
| ); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.