-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Readify/ticket-comments
Adds `Invoke-CommentRedaction` and other comment function updates
- Loading branch information
Showing
5 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,44 @@ | ||
|
||
function Invoke-CommentRedaction { | ||
|
||
[OutputType([PSCustomObject])] | ||
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] | ||
Param ( | ||
|
||
# Unique Id of the ticket the comment belongs to | ||
[Parameter(Mandatory = $true)] | ||
[ValidateRange(1, [Int64]::MaxValue)] | ||
[Int64] | ||
$TicketId, | ||
|
||
# Unique Id of the comment to redact text in | ||
[Parameter(Mandatory = $true)] | ||
[ValidateRange(1, [Int64]::MaxValue)] | ||
[Int64] | ||
$Id, | ||
|
||
# Text to redact | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[String] | ||
$Text, | ||
|
||
# Zendesk Connection Context from `Get-ZendeskConnection` | ||
[Parameter(Mandatory = $false)] | ||
[PSTypeName('ZendeskContext')] | ||
[PSCustomObject] | ||
$Context = $null | ||
) | ||
|
||
Assert-IsAgent -Context $Context | ||
|
||
$path = "/api/v2/tickets/$TicketId/comments/$Id/redact.json" | ||
$body = @{ | ||
text = $Text | ||
} | ||
|
||
if ($PSCmdlet.ShouldProcess($Id, 'Redact comment text')) { | ||
$result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Body $body -Verbose:$VerbosePreference | ||
$result | ||
} | ||
} |
This file contains 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,117 @@ | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] | ||
Param() | ||
|
||
Import-Module "$PSScriptRoot/../PwshZendesk.psm1" -Force | ||
|
||
Describe 'Groups Routes' { | ||
|
||
InModuleScope PwshZendesk { | ||
|
||
$IsInteractive = [Environment]::GetCommandLineArgs() -join ' ' -notmatch '-NonI' | ||
|
||
$context = @{ | ||
Organization = 'company' | ||
BaseUrl = 'https://company.testdesk.com' | ||
Credential = [System.Management.Automation.PSCredential]::New('email', ('api-key' | ConvertTo-SecureString -AsPlainText -Force)) | ||
User = [PSCustomObject]@{ role = '' } | ||
} | ||
$context | Add-Member -TypeName 'ZendeskContext' | ||
|
||
Mock -ModuleName PwshZendesk Invoke-RestMethod { [PSCustomObject]@{ comment = $null; comments = $null } } | ||
|
||
Context 'List Comments' { | ||
It 'Matches the endpoint' { | ||
if ($IsInteractive) { | ||
throw 'Please run test in non-interactive mode' | ||
} | ||
|
||
$context.User.role = 'admin' | ||
|
||
{ Get-Comment -Context $context -TicketId 1 } | Should -Not -Throw | ||
Assert-MockCalled Invoke-RestMethod -Exactly 1 -ParameterFilter { $Method -eq 'Get' -and $Uri -match '/api/v2/tickets/\d+/comments\.json' } -Scope It | ||
} | ||
|
||
It 'Does not allow end users to call' { | ||
$context.User.role = 'end-user' | ||
|
||
{ Get-Comment -Context $context -TicketId 1 } | Should -Throw 'Authenticated user must have role' | ||
} | ||
|
||
It 'Allows agents to call' { | ||
$context.User.role = 'agent' | ||
|
||
{ Get-Comment -Context $context -TicketId 1 } | Should -Not -Throw | ||
} | ||
|
||
It 'Allows admins to call' { | ||
$context.User.role = 'admin' | ||
|
||
{ Get-Comment -Context $context -TicketId 1 } | Should -Not -Throw | ||
} | ||
} | ||
|
||
Context 'Redact String in Comment' { | ||
It 'Matches the endpoint' { | ||
if ($IsInteractive) { | ||
throw 'Please run test in non-interactive mode' | ||
} | ||
|
||
$context.User.role = 'admin' | ||
|
||
{ Invoke-CommentRedaction -Context $context -TicketId 1 -Id 2 -Text 'p@ssword' -confirm:$false } | Should -Not -Throw | ||
Assert-MockCalled Invoke-RestMethod -Exactly 1 -ParameterFilter { $Method -eq 'Put' -and $Uri -match '/api/v2/tickets/\d+/comments/\d+/redact\.json' } -Scope It | ||
} | ||
|
||
It 'Does not allow end users to call' { | ||
$context.User.role = 'end-user' | ||
|
||
{ Invoke-CommentRedaction -Context $context -TicketId 1 -Id 2 -Text 'p@ssword' -confirm:$false } | Should -Throw 'Authenticated user must have role' | ||
} | ||
|
||
It 'Allows agents to call' { | ||
$context.User.role = 'agent' | ||
|
||
{ Invoke-CommentRedaction -Context $context -TicketId 1 -Id 2 -Text 'p@ssword' -confirm:$false } | Should -Not -Throw | ||
} | ||
|
||
It 'Allows admins to call' { | ||
$context.User.role = 'admin' | ||
|
||
{ Invoke-CommentRedaction -Context $context -TicketId 1 -Id 2 -Text 'p@ssword' -confirm:$false } | Should -Not -Throw | ||
} | ||
} | ||
|
||
Context 'Make Comment Private' { | ||
It 'Matches the endpoint' { | ||
if ($IsInteractive) { | ||
throw 'Please run test in non-interactive mode' | ||
} | ||
|
||
$context.User.role = 'admin' | ||
|
||
{ Hide-Comment -Context $context -TicketId 1 -Id 2 -Confirm:$false } | Should -Not -Throw | ||
Assert-MockCalled Invoke-RestMethod -Exactly 1 -ParameterFilter { $Method -eq 'Put' -and $Uri -match '/api/v2/tickets/\d+/comments/\d+/make_private.json' } -Scope It | ||
} | ||
|
||
It 'Does not allow end users to call' { | ||
$context.User.role = 'end-user' | ||
|
||
{ Hide-Comment -Context $context -TicketId 1 -Id 2 -Confirm:$false } | Should -Throw 'Authenticated user must have role' | ||
} | ||
|
||
It 'Allows agents to call' { | ||
$context.User.role = 'agent' | ||
|
||
{ Hide-Comment -Context $context -TicketId 1 -Id 2 -Confirm:$false } | Should -Not -Throw | ||
} | ||
|
||
It 'Allows admins to call' { | ||
$context.User.role = 'admin' | ||
|
||
{ Hide-Comment -Context $context -TicketId 1 -Id 2 -Confirm:$false } | Should -Not -Throw | ||
} | ||
} | ||
|
||
} | ||
|
||
} |