-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(searchHubber): implement search functionality for hubbers by Name or Handle #4
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
Changes from all commits
6743482
08d053e
aabe1f8
f14be3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Pull Request Code Instructions | ||
|
|
||
| ## PR TITLE | ||
|
|
||
| Follow this guidelines to construct the title of your pull request. | ||
|
|
||
| Format: `<type>(<scope>): <subject>` | ||
|
|
||
| `<scope>` 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. | ||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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' | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
Check warningCode scanning / PSScriptAnalyzer Function 'Start-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning
Function 'Start-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
|
||
| [CmdletBinding()] | ||
| param () | ||
|
|
||
| if (Test-Path $TEST_TRANSCRIPT_FILE) { | ||
| Remove-Item -Path $TEST_TRANSCRIPT_FILE -Force | ||
| } | ||
|
|
||
| Start-Transcript -Path $TEST_TRANSCRIPT_FILE | ||
| } | ||
|
|
||
| function Stop-MyTranscript { | ||
Check warningCode scanning / PSScriptAnalyzer Function 'Stop-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning
Function 'Stop-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
|
||
| Stop-Transcript | ||
| $transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE | ||
| Remove-Item -Path $TEST_TRANSCRIPT_FILE | ||
| return $transcriptContent | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
Check warningCode scanning / PSScriptAnalyzer The variable 'result' is assigned but never used. Warning
The variable 'result' is assigned but never used.
|
||
| $transcriptContent = Stop-MyTranscript | ||
|
|
||
| Assert-Contains -Expected "Error: Please specify either Name or Handle, or both." -Presented $transcriptContent | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| function Search-Hubber { | ||
Check noticeCode scanning / PSScriptAnalyzer The cmdlet 'Search-Hubber' does not have a help comment. Note
The cmdlet 'Search-Hubber' does not have a help comment.
|
||
| [CmdletBinding()] | ||
| param ( | ||
| [Parameter(Position=0)][string]$Name, | ||
| [Parameter()][string]$Handle | ||
| ) | ||
|
|
||
| $isName = -not [string]::IsNullOrEmpty($Name) | ||
| $isHandle = -not [string]::IsNullOrEmpty($Handle) | ||
|
|
||
Check noticeCode scanning / PSScriptAnalyzer Line has trailing whitespace Note
Line has trailing whitespace
|
||
| if( ! $isName -and ! $isHandle ) { | ||
| Write-MyError -Message "Please specify either Name or Handle, or both." | ||
| return $null | ||
| } | ||
|
|
||
Check noticeCode scanning / PSScriptAnalyzer Line has trailing whitespace Note
Line has trailing whitespace
|
||
| $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 | ||
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note