From b0798d15cf3a726618a83c5bc7be508164a2b7b2 Mon Sep 17 00:00:00 2001 From: rulasg Date: Sun, 9 Mar 2025 05:56:11 +0100 Subject: [PATCH 1/3] feat: add mock configuration files for testing with detailed comments --- Test/include/config.mock.ps1 | 15 ++++++++++++++- Test/private/config.mock.variables.ps1 | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Test/private/config.mock.variables.ps1 diff --git a/Test/include/config.mock.ps1 b/Test/include/config.mock.ps1 index 4a131ef..3f0cc7c 100644 --- a/Test/include/config.mock.ps1 +++ b/Test/include/config.mock.ps1 @@ -1,5 +1,18 @@ -$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetConfigRootPath" +# CONFIG MOCK +# +# This file is used to mock the config path and the config file +# for the tests. It creates a mock config path and a mock config file +# and sets the config path to the mock config path. +# We need to define varaibles for this include to work +# $MOCK_CONFIG_PATH : The path use as the mock config folder +# $CONFIG_INVOKE_GET_ROOT_PATH_CMD : Invoke comand that is needed to be mocked +# +# Sample file +# # CONFIG MOCK VARIABLES +# # This file is required for CONFIF MOCK to work +# $CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetConfigRootPath" +# $MOCK_CONFIG_PATH = "test_config_path" function Mock_Config{ param( diff --git a/Test/private/config.mock.variables.ps1 b/Test/private/config.mock.variables.ps1 new file mode 100644 index 0000000..ffe2a65 --- /dev/null +++ b/Test/private/config.mock.variables.ps1 @@ -0,0 +1,5 @@ +# CONFIG MOCK VARIABLES +# This file is required for CONFIF MOCK to work + +$MOCK_CONFIG_PATH = "test_config_path" +$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetConfigRootPath" From e606a116c1b4e9e768cdcdc0adaa6fb604605f89 Mon Sep 17 00:00:00 2001 From: rulasg Date: Sun, 9 Mar 2025 23:12:12 +0100 Subject: [PATCH 2/3] feat: update module dependencies and add mock configuration files for database and config --- SfHelper.psd1 | 2 +- Test/include/database.mock.ps1 | 31 +++++++++++++++++-- ...riables.ps1 => include.config.mock.sf.ps1} | 0 Test/private/include.databasev2.mock.sf.ps1 | 7 +++++ Test/private/mock_variables.ps1 | 2 ++ ...nclude.mySetInvokeCommandAlias.sf.ps1.ps1} | 0 .../{sfconfig.ps1 => include.config.sf.ps1} | 0 public/include.databasev2.sf.ps1 | 15 +++++++++ public/sfDatabase.ps1 | 29 ----------------- 9 files changed, 54 insertions(+), 32 deletions(-) rename Test/private/{config.mock.variables.ps1 => include.config.mock.sf.ps1} (100%) create mode 100644 Test/private/include.databasev2.mock.sf.ps1 rename private/{mySetInvokeCommandAlias_Varaibles.ps1.ps1 => include.mySetInvokeCommandAlias.sf.ps1.ps1} (100%) rename public/{sfconfig.ps1 => include.config.sf.ps1} (100%) create mode 100644 public/include.databasev2.sf.ps1 delete mode 100644 public/sfDatabase.ps1 diff --git a/SfHelper.psd1 b/SfHelper.psd1 index eac73f6..452492c 100644 --- a/SfHelper.psd1 +++ b/SfHelper.psd1 @@ -51,7 +51,7 @@ Description = 'Powershell module to help query Salesforce' # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module -RequiredModules = @(@{ModuleName="InvokeHelper"; ModuleVersion="1.2.1"}) +RequiredModules = @(@{ModuleName="InvokeHelper"; ModuleVersion="1.2.2"}) # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() diff --git a/Test/include/database.mock.ps1 b/Test/include/database.mock.ps1 index b64721b..ab47937 100644 --- a/Test/include/database.mock.ps1 +++ b/Test/include/database.mock.ps1 @@ -1,5 +1,20 @@ - -$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath" +# DATABASE MOCK +# +# This file is used to mock the database path and the database file +# for the tests. It creates a mock database path and a mock database file +# and sets the database path to the mock database path. +# We need to define variables for this include to work +# $MOCK_DATABASE_PATH : The path used as the mock database folder +# $DB_INVOKE_GET_ROOT_PATH_CMD : Invoke command that is needed to be mocked +# $DB_INVOKE_GET_ROOT_PATH_ALIAS : Invoke function to retreive the root path of the database +# +# Sample file +# # DATABASE MOCK VARIABLES +# # This file is required for DATABASE MOCK to work +# $DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath" +# $DB_INVOKE_GET_ROOT_PATH_ALIAS = "SfGetDbRootPath" +# +# $MOCK_DATABASE_PATH = "test_database_path" function Mock_Database([switch]$ResetDatabase){ @@ -17,4 +32,16 @@ function Mock_Database([switch]$ResetDatabase){ function Get-Mock_DatabaseStore{ $dbstore = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_CMD return $dbstore +} + +function Reset-DatabaseStore{ + [CmdletBinding()] + param() + + $databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS + + Remove-Item -Path $databaseRoot -Recurse -Force -ErrorAction SilentlyContinue + + New-Item -Path $databaseRoot -ItemType Directory + } \ No newline at end of file diff --git a/Test/private/config.mock.variables.ps1 b/Test/private/include.config.mock.sf.ps1 similarity index 100% rename from Test/private/config.mock.variables.ps1 rename to Test/private/include.config.mock.sf.ps1 diff --git a/Test/private/include.databasev2.mock.sf.ps1 b/Test/private/include.databasev2.mock.sf.ps1 new file mode 100644 index 0000000..e50fe2b --- /dev/null +++ b/Test/private/include.databasev2.mock.sf.ps1 @@ -0,0 +1,7 @@ +# DATABASEV2 MOCK VARIABLES +# This file is required for DATABASEV2 MOCK to work + +$DB_INVOKE_GET_ROOT_PATH_ALIAS = "SfGetDbRootPath" +$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath" +$MOCK_DATABASE_PATH = "test_database_path" + diff --git a/Test/private/mock_variables.ps1 b/Test/private/mock_variables.ps1 index 972f028..a8bd9f9 100644 --- a/Test/private/mock_variables.ps1 +++ b/Test/private/mock_variables.ps1 @@ -3,4 +3,6 @@ $MODULE_INVOKATION_TAG = "SfHelperModule" $MODULE_INVOKATION_TAG_MOCK = "SfHelperModule-Mock" + +# SetMockPath $MOCK_PATH = $PSScriptRoot | Split-Path -Parent | Join-Path -ChildPath 'private' -AdditionalChildPath 'mocks' \ No newline at end of file diff --git a/private/mySetInvokeCommandAlias_Varaibles.ps1.ps1 b/private/include.mySetInvokeCommandAlias.sf.ps1.ps1 similarity index 100% rename from private/mySetInvokeCommandAlias_Varaibles.ps1.ps1 rename to private/include.mySetInvokeCommandAlias.sf.ps1.ps1 diff --git a/public/sfconfig.ps1 b/public/include.config.sf.ps1 similarity index 100% rename from public/sfconfig.ps1 rename to public/include.config.sf.ps1 diff --git a/public/include.databasev2.sf.ps1 b/public/include.databasev2.sf.ps1 new file mode 100644 index 0000000..215dc86 --- /dev/null +++ b/public/include.databasev2.sf.ps1 @@ -0,0 +1,15 @@ +# This file is required for INCLUDE DATABASE V2 + +$DB_INVOKE_GET_ROOT_PATH_ALIAS = "SfGetDbRootPath" +$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath" + +Set-MyInvokeCommandAlias -Alias $DB_INVOKE_GET_ROOT_PATH_ALIAS -Command $DB_INVOKE_GET_ROOT_PATH_CMD + +function Invoke-SfGetDbRootPath{ + [CmdletBinding()] + param() + + $databaseRoot = GetDatabaseRootPath + return $databaseRoot + +} Export-ModuleMember -Function Invoke-SfGetDbRootPath \ No newline at end of file diff --git a/public/sfDatabase.ps1 b/public/sfDatabase.ps1 deleted file mode 100644 index 19452f1..0000000 --- a/public/sfDatabase.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -# This file is required for INCLUDE DATABASE V2 - -$DB_INVOKE_GET_ROOT_PATH_ALIAS = "SfGetDbRootPath" -$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath" - -Set-MyInvokeCommandAlias -Alias $DB_INVOKE_GET_ROOT_PATH_ALIAS -Command $DB_INVOKE_GET_ROOT_PATH_CMD - -function Invoke-SfGetDbRootPath{ - [CmdletBinding()] - param() - - $databaseRoot = GetDatabaseRootPath - return $databaseRoot - -} Export-ModuleMember -Function Invoke-SfGetDbRootPath - -# Extra functions not needed by INCLUDE DATABASE V2 - -function Reset-DatabaseStore{ - [CmdletBinding()] - param() - - $databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS - - Remove-Item -Path $databaseRoot -Recurse -Force -ErrorAction SilentlyContinue - - New-Item -Path $databaseRoot -ItemType Directory - -} Export-ModuleMember -Function Reset-DatabaseStore \ No newline at end of file From d89df59480e7369814dcdc9d8c3467e9d16fe249 Mon Sep 17 00:00:00 2001 From: rulasg Date: Sun, 9 Mar 2025 23:16:11 +0100 Subject: [PATCH 3/3] refactor: clean up comments and remove unnecessary whitespace in mock configuration files --- Test/include/config.mock.ps1 | 4 ++-- Test/include/database.mock.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Test/include/config.mock.ps1 b/Test/include/config.mock.ps1 index 3f0cc7c..d450b7f 100644 --- a/Test/include/config.mock.ps1 +++ b/Test/include/config.mock.ps1 @@ -1,5 +1,5 @@ -# CONFIG MOCK +# CONFIG MOCK # # This file is used to mock the config path and the config file # for the tests. It creates a mock config path and a mock config file @@ -11,7 +11,7 @@ # Sample file # # CONFIG MOCK VARIABLES # # This file is required for CONFIF MOCK to work -# $CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetConfigRootPath" +# $CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetConfigRootPath" # $MOCK_CONFIG_PATH = "test_config_path" function Mock_Config{ diff --git a/Test/include/database.mock.ps1 b/Test/include/database.mock.ps1 index ab47937..8b18c98 100644 --- a/Test/include/database.mock.ps1 +++ b/Test/include/database.mock.ps1 @@ -1,4 +1,4 @@ -# DATABASE MOCK +# DATABASE MOCK # # This file is used to mock the database path and the database file # for the tests. It creates a mock database path and a mock database file @@ -39,7 +39,7 @@ function Reset-DatabaseStore{ param() $databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS - + Remove-Item -Path $databaseRoot -Recurse -Force -ErrorAction SilentlyContinue New-Item -Path $databaseRoot -ItemType Directory