From 47b174dfa0f063d3500c850e152b09ef48715635 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 21:06:20 +0000 Subject: [PATCH] Pester checks --- SnipeitPS/Public/Assets.psm1 | 107 ++++++++++++++++++---------- SnipeitPS/Public/Categories.psm1 | 8 +-- SnipeitPS/Public/Components.psm1 | 70 +++++++++++------- SnipeitPS/Public/Manufacturers.psm1 | 39 ++++++---- SnipeitPS/Public/Models.psm1 | 41 +++++++---- SnipeitPS/Public/Set-Info.psm1 | 2 +- SnipeitPS/Public/Status.psm1 | 8 +-- SnipeitPS/Public/Users.psm1 | 10 +-- SnipeitPS/SnipeItPS.psd1 | Bin 7874 -> 8482 bytes Tests/SnipeItPS.Tests.ps1 | 2 +- 10 files changed, 182 insertions(+), 105 deletions(-) diff --git a/SnipeitPS/Public/Assets.psm1 b/SnipeitPS/Public/Assets.psm1 index 8b695f6..e8d0e75 100644 --- a/SnipeitPS/Public/Assets.psm1 +++ b/SnipeitPS/Public/Assets.psm1 @@ -9,7 +9,7 @@ URL of Snipeit system, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." +Get-Asset -url "https://assets.dip.co.uk" -token "token..." .EXAMPLE Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } @@ -18,11 +18,11 @@ Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.n function Get-Asset() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -35,20 +35,25 @@ function Get-Asset() function New-Asset() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$Name, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$Status_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Model_id, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey, [hashtable] $customfields @@ -64,33 +69,44 @@ function New-Asset() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/hardware" ` - -Method POST ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/hardware" + Method = 'Post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } function Set-Asset() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [int]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Status_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Model_id, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey, [hashtable] $customfields @@ -105,27 +121,38 @@ function Set-Asset() $Values += $customfields $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/hardware/$id" ` - -Method PUT ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } function Set-AssetOwner() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [int]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$user_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -135,10 +162,16 @@ function Set-AssetOwner() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -Uri "$url/api/v1/hardware/$id/checkout" ` - -Method POST ` - -Token $apiKey ` - -Body $Body + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id/checkout" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } return $result } diff --git a/SnipeitPS/Public/Categories.psm1 b/SnipeitPS/Public/Categories.psm1 index 31fc78a..c80cb3d 100644 --- a/SnipeitPS/Public/Categories.psm1 +++ b/SnipeitPS/Public/Categories.psm1 @@ -1,10 +1,10 @@ -function Get-Categories() +function Get-Category() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) diff --git a/SnipeitPS/Public/Components.psm1 b/SnipeitPS/Public/Components.psm1 index 1b2e785..28fe70f 100644 --- a/SnipeitPS/Public/Components.psm1 +++ b/SnipeitPS/Public/Components.psm1 @@ -1,10 +1,10 @@ function Get-Component() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -17,20 +17,25 @@ function Get-Component() function New-Component() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$category_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$qty, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -42,27 +47,38 @@ function New-Component() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/components" ` - -Method POST ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/components" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } -function Update-Component() +function Set-Component() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$qty, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -72,10 +88,16 @@ function Update-Component() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/components/$component_id" ` - -Method Patch ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/components/$component_id" + Method = 'Patch' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } @@ -99,4 +121,4 @@ function Checkout-Component($component_id, $asset_id = "") -UserAgent "DI Script/0.1" return $Manufacturers -}#> \ No newline at end of file +}#> diff --git a/SnipeitPS/Public/Manufacturers.psm1 b/SnipeitPS/Public/Manufacturers.psm1 index 410c5bd..0fa234d 100644 --- a/SnipeitPS/Public/Manufacturers.psm1 +++ b/SnipeitPS/Public/Manufacturers.psm1 @@ -1,10 +1,10 @@ -function Get-Manufacturers() +function Get-Manufacturer() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -17,14 +17,19 @@ function Get-Manufacturers() function New-Manufacturer() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$Name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -36,10 +41,16 @@ function New-Manufacturer() #Convert Values to JSON format $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/manufacturers" ` - -Method POST ` - -Body $Body ` - -Token $apiKey - + $Parameters = @{ + Uri = "$url/api/v1/manufacturers" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } + $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Models.psm1 b/SnipeitPS/Public/Models.psm1 index b7e39b7..caa093e 100644 --- a/SnipeitPS/Public/Models.psm1 +++ b/SnipeitPS/Public/Models.psm1 @@ -1,11 +1,11 @@ -function Get-Models() +function Get-Model() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -19,23 +19,28 @@ function Get-Models() function New-Model() { + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + Param( - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$category_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$manufacturer_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$fieldset_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -48,10 +53,16 @@ function New-Model() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/models" ` - -Method POST ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/models" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Set-Info.psm1 b/SnipeitPS/Public/Set-Info.psm1 index 3307a01..a0ef88e 100644 --- a/SnipeitPS/Public/Set-Info.psm1 +++ b/SnipeitPS/Public/Set-Info.psm1 @@ -47,4 +47,4 @@ function Set-Info { } } } -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Status.psm1 b/SnipeitPS/Public/Status.psm1 index 3a4887a..95141f3 100644 --- a/SnipeitPS/Public/Status.psm1 +++ b/SnipeitPS/Public/Status.psm1 @@ -1,10 +1,10 @@ function Get-Status() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -13,4 +13,4 @@ function Get-Status() -Token $apiKey $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Users.psm1 b/SnipeitPS/Public/Users.psm1 index c2b3cee..e1017d3 100644 --- a/SnipeitPS/Public/Users.psm1 +++ b/SnipeitPS/Public/Users.psm1 @@ -9,19 +9,19 @@ URL of Snipeit system, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE -Get-Users -url "https://assets.dip.co.uk" -token "token..." +Get-Users -url "https://assets.dip.co.uk" -token "token..." .EXAMPLE Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" } #> -function Get-Users() +function Get-User() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index c4b382c6c74e6d954799e430b31233f0eca57e09..76d510ddf8c2c61d91dd66af56b8bc3b92fbf3ae 100644 GIT binary patch delta 630 zcmX?PyU1xnj8MG;g9ZaH0~dn=6sj}0Go&( zmEltiQVa7HF=}DX^#wXNkD-(y4M-;golpvNG}MFjI06=r7Bn3QOY#{~fX3!v2@RMB zeSscCRg;N`cbLySfo@F$D#VO+m{q|*KY${j6qr76s|p3D9#Axb(wFAuM4?0;00bIW A9RL6T delta 16 XcmZ4FbjWr?jL>8U38BsBL_&A~IFSYP diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index f3c7f28..b5a77b3 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -63,7 +63,7 @@ Describe "SnipeitPS" { $script:manifest = Invoke-Expression (Get-Content $script:manifestFile -Raw) It "Manifest file includes the correct root module" { - $script:manifest.RootModule | Should Be 'SnipeitPS.psm1' + $script:manifest.RootModule | Should Be 'SnipeitPS' } It "Manifest file includes the correct guid" {