-
-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance Salesforce data handling with opportunity support and refactor attribute management #14
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
84f9026
feat: enhance Salesforce data handling with new opportunity support a…
rulasg dd8f8fb
feat: add Get-HashCode function for MD5 hashing and update tests with…
rulasg 24f11a6
feat: introduce Set-MyInvokeCommandAlias function and related module …
rulasg fd9df0e
feat: add Invoke Command Mock functionality with support for command …
rulasg a732cd0
fix: adjust file import order in SfHelper.psm1 for improved module lo…
rulasg 9fb4866
feat: enhance configuration and database modules with improved docume…
rulasg d8d5c58
feat: implement Get-SfObjectTypeFromUrl function and enhance URL vali…
rulasg c03365e
refactor: clean up whitespace and improve code formatting in test and…
rulasg 0cf053d
refactor: remove unused START.ps1 file and clean up import logic in S…
rulasg 20f579c
feat: enhance Get-SfAccount function with improved attribute transfor…
rulasg 14e0361
refactor: remove unnecessary whitespace in getsfopportunity.test.ps1
rulasg 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
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
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
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
18 changes: 13 additions & 5 deletions
18
Test/private/InvokeCommandMock.ps1 → Test/include/invokeCommand.Mock.ps1
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
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,19 @@ | ||
| function Mock_SfDataQuery { | ||
| [CmdletBinding()] | ||
| param ( | ||
| [Parameter(Mandatory = $true)][string]$attrib, | ||
| [Parameter(Mandatory = $true)][string]$type, | ||
| [Parameter(Mandatory = $true)][string]$id, | ||
| [Parameter(Mandatory = $true)][string]$filename | ||
|
|
||
| ) | ||
|
|
||
| $command = 'sf data query --query "SELECT {attributes} FROM {type} WHERE Id=''{id}''" -r=json' | ||
| $command = $command -replace "{attributes}", $attrib | ||
| $command = $command -replace "{type}", $type | ||
| $command = $command -replace "{id}", $id | ||
| MockCall -Command $command -filename $filename | ||
| } | ||
|
|
||
| #sf data query --query "SELECT Id,Name,OwnerId FROM opportunity WHERE Id='0065c00001SFRbYAAX'" -r=json | ||
| #sf data query --query "SELECT Id,Name FROM Opportunity WHERE Id='0065c00001SFRbYAAX'" -r=json |
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,6 @@ | ||
|
|
||
| # Required for INVOKE COMMAND MOCK | ||
|
|
||
| $MODULE_INVOKATION_TAG = "SfHelperModule" | ||
| $MODULE_INVOKATION_TAG_MOCK = "SfHelperModule-Mock" | ||
Check warningCode scanning / PSScriptAnalyzer The variable 'MODULE_INVOKATION_TAG_MOCK' is assigned but never used. Warning
The variable 'MODULE_INVOKATION_TAG_MOCK' is assigned but never used.
|
||
| $MOCK_PATH = $PSScriptRoot | Split-Path -Parent | Join-Path -ChildPath 'private' -AdditionalChildPath 'mocks' | ||
Check warningCode scanning / PSScriptAnalyzer The variable 'MOCK_PATH' is assigned but never used. Warning
The variable 'MOCK_PATH' is assigned but never used.
|
||
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
Test/private/mocks/sf-data-query-opportunity_0065c00001SFRbYAAX.json
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,18 @@ | ||
| { | ||
| "status": 0, | ||
| "result": { | ||
| "records": [ | ||
| { | ||
| "attributes": { | ||
| "type": "Opportunity", | ||
| "url": "/services/data/v63.0/sobjects/Opportunity/0065c00001SFRbYAAX" | ||
| }, | ||
| "Id": "0065c00001SFRbYAAX", | ||
| "Name": "Secret Services IT 10 Seat 2025_Q3 Order", | ||
| "OwnerId": "0053o000008Skv3AAC" | ||
| } | ||
| ], | ||
| "totalSize": 1, | ||
| "done": true | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
| function Test_sfObjectIdFromUrl{ | ||
|
|
||
| . $PSScriptRoot/../../private/auxiliarfunctions.ps1 | ||
|
|
||
| $urlList = @( | ||
| "https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB/view", | ||
| "https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB/", | ||
| "https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB", | ||
| "https://github.my.salesforce.com/0010V00002Q8r78QAB" | ||
| ) | ||
|
|
||
| $urlList | ForEach-Object { | ||
| $result = Get-SfObjectIdFromUrl $_ | ||
| Assert-AreEqual -Expected "0010V00002Q8r78QAB" -Presented $result | ||
| } | ||
|
|
||
| } | ||
|
|
||
| function Test_sfObjectTypeFromUrl{ | ||
|
|
||
| . $PSScriptRoot/../../private/auxiliarfunctions.ps1 | ||
|
|
||
| $urlList = @( | ||
| "https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB/view", | ||
| "https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB/", | ||
| "https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB" | ||
| ) | ||
|
|
||
| $urlList | ForEach-Object { | ||
| $result = Get-SfObjectTypeFromUrl $_ | ||
| Assert-AreEqual -Expected "Account" -Presented $result | ||
| } | ||
|
|
||
| $urlList = @( | ||
| "https://github.my.salesforce.com/0010V00002Q8r78QAB" | ||
| ) | ||
| $urlList | ForEach-Object { | ||
| $result = Get-SfObjectTypeFromUrl $_ | ||
| Assert-IsNull -Object $result | ||
| } | ||
|
|
||
| } |
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,58 @@ | ||
|
|
||
| function Test_GetSfOpportunity{ | ||
|
|
||
| Reset-InvokeCommandMock | ||
| Mock_Database -ResetDatabase | ||
| Mock_Config | ||
|
|
||
| # Mock Sf call | ||
| $id = "0065c00001SFRbYAAX" | ||
| $cacheFileName = "sfDataQuery-opportunity-$id-5106802FEB193611777BC7DA26122EF5.json" | ||
| $url = "https://github.lightning.force.com/lightning/r/Opportunity/$id/view" | ||
| Mock_SfDataQuery_Opportunity_0065c00001SFRbYAAX | ||
|
|
||
| # Act with out cache | ||
| $result = Get-SfOpportunity -SfUrl $url | ||
|
|
||
| # Assert | ||
| Assert-AreEqual -Expected $id -Presented $result.Id | ||
| $path = Get-Mock_DatabaseStore | Join-Path -ChildPath $cacheFileName | ||
| Assert-ItemExist -Path $path | ||
|
|
||
| # Remove sf data | ||
| Reset-InvokeCommandMock | ||
| Mock_Database | ||
| Mock_Config | ||
|
|
||
| # Act with cache | ||
| $result = Get-SfOpportunity -SfUrl $url | ||
|
|
||
| # Assert | ||
| Assert-AreEqual -Expected $id -Presented $result.Id | ||
|
|
||
| } | ||
|
|
||
| function Test_GetSfOpportunity_Live{ | ||
| Assert-SkipTest "Test live connection to Salesforce" | ||
|
|
||
| Reset-InvokeCommandMock | ||
| Enable-InvokeCommandAliasModule | ||
|
|
||
| $result = Get-SfOpportunity https://github.lightning.force.com/lightning/r/Opportunity/0065c00001SFRbYAAX/view | ||
| Assert-notnull -Object $result | ||
|
|
||
| Assert-NotImplemented | ||
| } | ||
|
|
||
|
|
||
| function Mock_SfDataQuery_Opportunity_0065c00001SFRbYAAX{ | ||
| [CmdletBinding()] | ||
| param() | ||
|
|
||
| $attrib = "Id,Name,OwnerId" | ||
| $type = "Opportunity" | ||
| $id = "0065c00001SFRbYAAX" | ||
| $filename = "sf-data-query-opportunity_0065c00001SFRbYAAX.json" | ||
|
|
||
| Mock_SfDataQuery -attrib $attrib -type $type -id $id -filename $filename | ||
| } |
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,70 @@ | ||
| function Test_GetSfAccount{ | ||
|
|
||
| Reset-InvokeCommandMock | ||
|
|
||
| $mockAttrib = @{account_attributes = @("Potential_Seats_Manual__c","Website","PhotoUrl")} | ||
|
|
||
| # Mocks | ||
| Mock_Database -ResetDatabase | ||
| Mock_Config -Config $mockAttrib | ||
|
|
||
| # Mock Sf call | ||
| $id = "0010V00002KIWkaQAH" | ||
| $url = "https://github.lightning.force.com/lightning/r/Account/$id/view" | ||
| $filename = "sfDataQuery-Account-$id-01F5F2DFDE481D1146E8D504BB935E4D.json" | ||
| Mock_SfDataQuery_Account_0010V00002KIWkaQAH -AdditionalAttributes $mockAttrib.account_attributes | ||
|
|
||
| # Act with out cache | ||
| $result = Get-SfAccount -SfUrl $url | ||
|
|
||
| # Assert with cache | ||
| Assert-AreEqual -Expected $id -Presented $result.Id | ||
| $path = Get-Mock_DatabaseStore | Join-Path -ChildPath $filename | ||
| Assert-ItemExist -Path $path | ||
|
|
||
| # Reset Mock and skip Mock_SfDataQuery_Account_0010V00002KIWkaQAH | ||
| Reset-InvokeCommandMock | ||
| Mock_Database | ||
| Mock_Config -Config $mockAttrib | ||
|
|
||
| # Act with cache | ||
| $result = Get-SfAccount -SfUrl $url | ||
|
|
||
| # Assert | ||
| Assert-AreEqual -Expected "0010V00002KIWkaQAH" -Presented $result.Id | ||
| } | ||
|
|
||
| function Test_GetSfAccount_Transformations{ | ||
| Reset-InvokeCommandMock | ||
|
|
||
| # Mocks | ||
| Mock_Database -ResetDatabase | ||
| Mock_Config | ||
| Mock_SfDataQuery_Account_0010V00002KIWkaQAH | ||
|
|
||
| # Act with out cache | ||
| $result = Get-SfAccount https://github.lightning.force.com/lightning/r/Account/0010V00002KIWkaQAH/view | ||
|
|
||
| # Transformation Account_Owner__c -> OwnerName | ||
| Assert-AreEqual -Expected "Oana Dinca" -Presented $result.OwnerName | ||
| Assert-IsNull -Object $result.Account_Owner__c | ||
|
|
||
| } | ||
|
|
||
| function Mock_SfDataQuery_Account_0010V00002KIWkaQAH{ | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Position=0)][string[]]$AdditionalAttributes | ||
| ) | ||
|
|
||
| $attrib = "Id,Name,OwnerId,Industry,Account_Owner__c,Account_Segment__c,Account_Owner_Role__c,Account_Tier__c,Potential_Seats__c,Country_Name__c,Current_Seats__c,Current_ARR_10__c,Salesforce_Record_URL__c" | ||
| $type = "Account" | ||
| $id = "0010V00002KIWkaQAH" | ||
| $filename = "sf-data-query-account_0010V00002KIWkaQAH.json" | ||
|
|
||
| if ($AdditionalAttributes) { | ||
| $attrib += "," + ($AdditionalAttributes -join ",") | ||
| } | ||
|
|
||
| Mock_SfDataQuery -attrib $attrib -type $type -id $id -filename $filename | ||
| } |
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,43 @@ | ||
| function Test_AddSfConfigAttribute{ | ||
| Reset-InvokeCommandMock | ||
| Mock_Config | ||
|
|
||
| # Emput config | ||
| $result = Get-SfConfig | ||
| Assert-IsNull -Object $result | ||
|
|
||
| # Add acount | ||
| Add-SfConfigAttribute -objectType "Account" -Attribute "acountattribute" | ||
| $result = Get-SfConfig | ||
| Assert-Count -Expected 1 -Presented $result.account_attributes | ||
| Assert-Contains -Expected "acountattribute" -Presented $result.account_attributes | ||
| Add-SfConfigAttribute -objectType "Account" -Attribute "acountattribute2" | ||
| $result = Get-SfConfig | ||
| Assert-Count -Expected 2 -Presented $result.account_attributes | ||
| Assert-Contains -Expected "acountattribute" -Presented $result.account_attributes | ||
| Assert-Contains -Expected "acountattribute2" -Presented $result.account_attributes | ||
|
|
||
| # Add user | ||
| Add-SfConfigAttribute -objectType "User" -Attribute "userattribute" | ||
| $result = Get-SfConfig | ||
| Assert-Count -Expected 1 -Presented $result.user_attributes | ||
| Assert-Contains -Expected "userattribute" -Presented $result.user_attributes | ||
| Add-SfConfigAttribute -objectType "User" -Attribute "userattribute2" | ||
| $result = Get-SfConfig | ||
| Assert-Count -Expected 2 -Presented $result.user_attributes | ||
| Assert-Contains -Expected "userattribute" -Presented $result.user_attributes | ||
| Assert-Contains -Expected "userattribute2" -Presented $result.user_attributes | ||
|
|
||
| # Add Opportunity | ||
| Add-SfConfigAttribute -objectType "Opportunity" -Attribute "opportunityattribute" | ||
| $result = Get-SfConfig | ||
| Assert-Count -Expected 1 -Presented $result.opportunity_attributes | ||
| Assert-Contains -Expected "opportunityattribute" -Presented $result.opportunity_attributes | ||
| Add-SfConfigAttribute -objectType "Opportunity" -Attribute "opportunityattribute2" | ||
| $result = Get-SfConfig | ||
| Assert-Count -Expected 2 -Presented $result.opportunity_attributes | ||
| Assert-Contains -Expected "opportunityattribute" -Presented $result.opportunity_attributes | ||
| Assert-Contains -Expected "opportunityattribute2" -Presented $result.opportunity_attributes | ||
|
|
||
| } | ||
|
|
Oops, something went wrong.
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.
Check warning
Code scanning / PSScriptAnalyzer
The variable 'MODULE_INVOKATION_TAG' is assigned but never used. Warning