diff --git a/.github/copilot-pull-request-description-instructions.md b/.github/copilot-pull-request-description-instructions.md new file mode 100644 index 0000000..31a8730 --- /dev/null +++ b/.github/copilot-pull-request-description-instructions.md @@ -0,0 +1,44 @@ +# Pull Request Code Instructions + +## PR TITLE + +Follow this guidelines to construct the title of your pull request. + +Format: `(): ` + +`` is optional + +## Example + +``` +feat: add hat wobble +^--^ ^------------^ +| | +| +-> Summary in present tense. +| ++-------> Type: chore, docs, feat, fix, refactor, style, or test. +``` + +More Examples: + +- `feat`: (new feature for the user, not a new feature for build script) +- `fix`: (bug fix for the user, not a fix to a build script) +- `docs`: (changes to the documentation) +- `style`: (formatting, missing semi colons, etc; no production code change) +- `refactor`: (refactoring production code, eg. renaming a variable) +- `test`: (adding missing tests, refactoring tests; no production code change) +- `chore`: (updating grunt tasks etc; no production code change) + +References: + +- https://www.conventionalcommits.org/ +- https://seesparkbox.com/foundry/semantic_commit_messages +- http://karma-runner.github.io/1.0/dev/git-commit-msg.html + +## Pull Reques description + +- Add a summery of the intention of the PR. Use the title and the messages of the commits to create a summary. +- Add a list with all the commit messages in the PR. + + + diff --git a/Test/include/parameter.test.helper.ps1 b/Test/include/parameter.test.helper.ps1 new file mode 100644 index 0000000..4d5b6da --- /dev/null +++ b/Test/include/parameter.test.helper.ps1 @@ -0,0 +1,40 @@ +# Variables used to the written output of the cmdlets +# +# This definition allows to trace output streams for testing purposes +# +# sample usage: +# +# function Get-SomeCommand { +# [CmdletBinding()] +# param() +# +# Write-Verbose "this is a verbose message" +# } +# +# $result = Get-SomeCommand @ VerboseParameters +# Assert-Contains -Expected "this is a verbose message" -Presented $verboseVar + +# Verbose parameters will now work.to capture the verbose outptut pipe 4>&1 and capture the output +# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Scope='function')] +# $VerboseParameters =@{ +# VerboseAction = 'SilentlyContinue' +# VerboseVariable = 'verboseVar' +# } + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Scope='function')] +$WarningParameters = @{ + WarningAction = 'SilentlyContinue' + WarningVariable = 'warningVar' +} + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Scope='function')] +$InfoParameters = @{ + InformationAction = 'SilentlyContinue' + InformationVariable = 'infoVar' +} + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Scope='function')] +$ErrorParameters = @{ + ErrorAction = 'SilentlyContinue' + ErrorVariable = 'errorVar' +} diff --git a/Test/include/transcriptHelp.ps1 b/Test/include/transcriptHelp.ps1 new file mode 100644 index 0000000..e9a9012 --- /dev/null +++ b/Test/include/transcriptHelp.ps1 @@ -0,0 +1,25 @@ +# Test Transcript helper functions +# These functions help manage the transcript file during tests +# and ensure it is cleaned up after use. + + +$TEST_TRANSCRIPT_FILE = "test_transcript.log" + +function Start-MyTranscript { + [CmdletBinding()] + param () + + if (Test-Path $TEST_TRANSCRIPT_FILE) { + Remove-Item -Path $TEST_TRANSCRIPT_FILE -Force + } + + Start-Transcript -Path $TEST_TRANSCRIPT_FILE +} + +function Stop-MyTranscript { + Stop-Transcript + $transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE + Remove-Item -Path $TEST_TRANSCRIPT_FILE + return $transcriptContent +} + diff --git a/Test/private/mocks/hubbers.json b/Test/private/mocks/hubbers.json index e0667b9..8145ead 100644 --- a/Test/private/mocks/hubbers.json +++ b/Test/private/mocks/hubbers.json @@ -4,7 +4,7 @@ "employment_type": "employee", "github_login": "user3", "msft_alias": "user3MSFT", - "name": "User Name 1", + "name": "Sarah Mitchell", "email": "user3@github.com", "title": "Chief Operating Officer", "cost_center": "Strategic Operations", @@ -16,7 +16,7 @@ "employment_type": "employee", "github_login": "user1", "msft_alias": "user1MSFT", - "name": "User Name 1", + "name": "Michael Johnson", "email": "user1@github.com", "title": "Chief Operating Officer", "cost_center": "Strategic Operations", @@ -28,7 +28,7 @@ "employment_type": "microsoft_employee", "github_login": "user2", "msft_alias": "user2MSFT", - "name": "User Name 2", + "name": "Jennifer Davis", "email": "user2@github.com", "title": "Chief Revenue Officer", "cost_center": "Office of the CEO", @@ -40,7 +40,7 @@ "employment_type": "microsoft_employee", "github_login": "user0", "msft_alias": "user0MSFT", - "name": "User Name 0", + "name": "Robert Thompson", "email": "user0@github.com", "title": "CEO", "cost_center": "Office of the CEO", @@ -52,7 +52,7 @@ "employment_type": "employee", "github_login": "user4", "msft_alias": "user4MSFT", - "name": "User Name 4", + "name": "Amanda Rodriguez", "email": "user4@github.com", "title": "Chief Product Officer", "cost_center": "Product Management", @@ -64,7 +64,7 @@ "employment_type": "microsoft_employee", "github_login": "user5", "msft_alias": "user5MSFT", - "name": "User Name 5", + "name": "David Wilson", "email": "user5@github.com", "title": "VP, Advisor to the CEO", "cost_center": "Office of the CEO", @@ -75,7 +75,7 @@ "employment_type": "employee", "github_login": "user6", "msft_alias": "user6MSFT", - "name": "User Name 6", + "name": "Lisa Anderson", "email": "user6@github.com", "title": "VP, COS to the CEO", "cost_center": "Office of the CEO", @@ -87,7 +87,7 @@ "employment_type": "microsoft_employee", "github_login": "user7", "msft_alias": "user7MSFT", - "name": "User Name 7", + "name": "Christopher Lee", "email": "user7@github.com", "title": "Chief Legal Officer", "cost_center": "Legal", @@ -98,7 +98,7 @@ "employment_type": "employee", "github_login": "user8", "msft_alias": "user8MSFT", - "name": "User Name 8", + "name": "Michelle Brown", "email": "user8@github.com", "title": "CISO", "cost_center": "Security", @@ -109,9 +109,9 @@ "manager": "user3", "employment_type": "microsoft_employee", "github_login": "user9", - "name": "Jay Parikh", + "name": "Daniel Martinez", "user9MSFT": "jayparikh@github.com", - "title": "User Name 9", + "title": "CFO", "cost_center": "user9 of the CEO", "country": "United States of America" }, @@ -120,7 +120,7 @@ "employment_type": "microsoft_employee", "github_login": "user10", "msft_alias": "user10MSFT", - "name": "User Name 10", + "name": "Ashley Taylor", "email": "user10@github.com", "title": "Chief People Officer", "cost_center": "Office of the CEO", @@ -131,7 +131,7 @@ "employment_type": "microsoft_employee", "github_login": "user11", "msft_alias": "user11MSFT", - "name": "User Name 11", + "name": "James Garcia", "email": "user11h@github.com", "title": "Chief Technology Officer", "cost_center": "Office of the CEO", @@ -142,7 +142,7 @@ "employment_type": "microsoft_employee", "github_login": "user12", "msft_alias": "user12MSFT", - "name": "User Name 12", + "name": "Emily White", "email": "user12@github.com", "title": "Chief Financial Officer", "cost_center": "Office of the CEO", diff --git a/Test/public/searchhubber.test.ps1 b/Test/public/searchhubber.test.ps1 new file mode 100644 index 0000000..e197810 --- /dev/null +++ b/Test/public/searchhubber.test.ps1 @@ -0,0 +1,56 @@ +function Test_searchHubber_Success_Name{ + + Reset-InvokeCommandMock + Mock_Database + $filePath = Get-MockFileFullPath -fileName "hubbers.json" + $result = Import-HubbersList -Path $filePath + + $result = search-Hubber -Name "Mich" + + $resultNames = $result.name + Assert-Count -Expected 2 -Presented $resultNames + Assert-Contains -Expected "Michael Johnson" -Presented $resultNames + Assert-Contains -Expected "Michelle Brown" -Presented $resultNames + +} + +function Test_searchHubber_Success_Handle{ + Reset-InvokeCommandMock + Mock_Database + $filePath = Get-MockFileFullPath -fileName "hubbers.json" + $result = Import-HubbersList -Path $filePath + + $result = search-Hubber -Handle "2" + + $resultHandles = $result.github_login + Assert-Count -Expected 2 -Presented $resultHandles + Assert-Contains -Expected "user2" -Presented $resultHandles + Assert-Contains -Expected "user12" -Presented $resultHandles + +} + +function Test_searchHubber_Success_Name_Handle{ + Reset-InvokeCommandMock + Mock_Database + $filePath = Get-MockFileFullPath -fileName "hubbers.json" + $result = Import-HubbersList -Path $filePath + + $result = search-Hubber -Handle "2" -Name "Davis" + + Assert-AreEqual -Expected "user2" -Presented $result.github_login + Assert-AreEqual -Expected "Jennifer Davis" -Presented $result.name +} + + + +function Test_searchHubber_Fail_NoParams{ + Reset-InvokeCommandMock + Mock_Database + + Start-MyTranscript + $result = search-Hubber @ErrorParameters + $transcriptContent = Stop-MyTranscript + + Assert-Contains -Expected "Error: Please specify either Name or Handle, or both." -Presented $transcriptContent + +} \ No newline at end of file diff --git a/public/getHubber.ps1 b/public/getHubber.ps1 index f1d12eb..727364e 100644 --- a/public/getHubber.ps1 +++ b/public/getHubber.ps1 @@ -2,7 +2,7 @@ function Get-Hubber{ [CmdletBinding()] param ( - [Parameter(Position=0)][string]$Handle, + [Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName,Position=0)][string]$Handle, [Parameter()][switch]$AsHashtable ) diff --git a/public/searchhubber.ps1 b/public/searchhubber.ps1 new file mode 100644 index 0000000..dc1d8c9 --- /dev/null +++ b/public/searchhubber.ps1 @@ -0,0 +1,29 @@ +function Search-Hubber { + [CmdletBinding()] + param ( + [Parameter(Position=0)][string]$Name, + [Parameter()][string]$Handle + ) + + $isName = -not [string]::IsNullOrEmpty($Name) + $isHandle = -not [string]::IsNullOrEmpty($Handle) + + if( ! $isName -and ! $isHandle ) { + Write-MyError -Message "Please specify either Name or Handle, or both." + return $null + } + + $hubbersList = Get-HubbersList + + $hubbers = $hubbersList.Values + + if ( $isHandle ) { + $hubbers = $hubbers | Where-Object { $_.github_login -like "*$Handle*" } + } + + if ( $isName ) { + $hubbers = $hubbers | Where-Object { $_.name -like "*$Name*" } + } + + return $hubbers +} Export-ModuleMember -Function Search-Hubber \ No newline at end of file