Pester checks

This commit is contained in:
Stephen Maunder 2017-11-18 21:06:20 +00:00
parent d28139a5bc
commit 47b174dfa0
10 changed files with 182 additions and 105 deletions

View file

@ -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 Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE .EXAMPLE
Get-Asset -url "https://assets.dip.co.uk" -token "token..." Get-Asset -url "https://assets.dip.co.uk" -token "token..."
.EXAMPLE .EXAMPLE
Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } 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() function Get-Asset()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -35,20 +35,25 @@ function Get-Asset()
function New-Asset() function New-Asset()
{ {
Param( [CmdletBinding(
[parameter(mandatory=$true)] SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[string]$Name, [string]$Name,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$Status_id, [string]$Status_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$Model_id, [string]$Model_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey, [string]$apiKey,
[hashtable] $customfields [hashtable] $customfields
@ -64,33 +69,44 @@ function New-Asset()
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;
$result = Invoke-Method -URi "$url/api/v1/hardware" ` $Parameters = @{
-Method POST ` Uri = "$url/api/v1/hardware"
-Body $Body ` Method = 'Post'
-Token $apiKey Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result $result
} }
function Set-Asset() function Set-Asset()
{ {
Param( [CmdletBinding(
[parameter(mandatory=$true)] SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[int]$id, [int]$id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$Name, [string]$Name,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$Status_id, [string]$Status_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$Model_id, [string]$Model_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey, [string]$apiKey,
[hashtable] $customfields [hashtable] $customfields
@ -105,27 +121,38 @@ function Set-Asset()
$Values += $customfields $Values += $customfields
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;
$result = Invoke-Method -URi "$url/api/v1/hardware/$id" ` $Parameters = @{
-Method PUT ` Uri = "$url/api/v1/hardware/$id"
-Body $Body ` Method = 'Put'
-Token $apiKey Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result $result
} }
function Set-AssetOwner() function Set-AssetOwner()
{ {
Param( [CmdletBinding(
[parameter(mandatory=$true)] SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[int]$id, [int]$id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[int]$user_id, [int]$user_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -135,10 +162,16 @@ function Set-AssetOwner()
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;
$result = Invoke-Method -Uri "$url/api/v1/hardware/$id/checkout" ` $Parameters = @{
-Method POST ` Uri = "$url/api/v1/hardware/$id/checkout"
-Token $apiKey ` Method = 'POST'
-Body $Body Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
return $result return $result
} }

View file

@ -1,10 +1,10 @@
function Get-Categories() function Get-Category()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )

View file

@ -1,10 +1,10 @@
function Get-Component() function Get-Component()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -17,20 +17,25 @@ function Get-Component()
function New-Component() function New-Component()
{ {
Param( [CmdletBinding(
[parameter(mandatory=$true)] SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[string]$name, [string]$name,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$category_id, [string]$category_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$qty, [string]$qty,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -42,27 +47,38 @@ function New-Component()
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;
$result = Invoke-Method -URi "$url/api/v1/components" ` $Parameters = @{
-Method POST ` Uri = "$url/api/v1/components"
-Body $Body ` Method = 'POST'
-Token $apiKey Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result $result
} }
function Update-Component() function Set-Component()
{ {
Param( [CmdletBinding(
[parameter(mandatory=$true)] SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[string]$id, [string]$id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$qty, [string]$qty,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -72,10 +88,16 @@ function Update-Component()
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;
$result = Invoke-Method -URi "$url/api/v1/components/$component_id" ` $Parameters = @{
-Method Patch ` Uri = "$url/api/v1/components/$component_id"
-Body $Body ` Method = 'Patch'
-Token $apiKey Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result $result
} }
@ -99,4 +121,4 @@ function Checkout-Component($component_id, $asset_id = "")
-UserAgent "DI Script/0.1" -UserAgent "DI Script/0.1"
return $Manufacturers return $Manufacturers
}#> }#>

View file

@ -1,10 +1,10 @@
function Get-Manufacturers() function Get-Manufacturer()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -17,14 +17,19 @@ function Get-Manufacturers()
function New-Manufacturer() function New-Manufacturer()
{ {
Param( [CmdletBinding(
[parameter(mandatory=$true)] SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[string]$Name, [string]$Name,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -36,10 +41,16 @@ function New-Manufacturer()
#Convert Values to JSON format #Convert Values to JSON format
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;
$result = Invoke-Method -URi "$url/api/v1/manufacturers" ` $Parameters = @{
-Method POST ` Uri = "$url/api/v1/manufacturers"
-Body $Body ` Method = 'post'
-Token $apiKey Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result $result
} }

View file

@ -1,11 +1,11 @@
function Get-Models() function Get-Model()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -19,23 +19,28 @@ function Get-Models()
function New-Model() function New-Model()
{ {
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$name, [string]$name,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[int]$category_id, [int]$category_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[int]$manufacturer_id, [int]$manufacturer_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[int]$fieldset_id, [int]$fieldset_id,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -48,10 +53,16 @@ function New-Model()
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;
$result = Invoke-Method -URi "$url/api/v1/models" ` $Parameters = @{
-Method POST ` Uri = "$url/api/v1/models"
-Body $Body ` Method = 'post'
-Token $apiKey Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result $result
} }

View file

@ -47,4 +47,4 @@ function Set-Info {
} }
} }
} }
} }

View file

@ -1,10 +1,10 @@
function Get-Status() function Get-Status()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )
@ -13,4 +13,4 @@ function Get-Status()
-Token $apiKey -Token $apiKey
$result $result
} }

View file

@ -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 Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE .EXAMPLE
Get-Users -url "https://assets.dip.co.uk" -token "token..." Get-Users -url "https://assets.dip.co.uk" -token "token..."
.EXAMPLE .EXAMPLE
Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" } Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" }
#> #>
function Get-Users() function Get-User()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$apiKey [string]$apiKey
) )

Binary file not shown.

View file

@ -63,7 +63,7 @@ Describe "SnipeitPS" {
$script:manifest = Invoke-Expression (Get-Content $script:manifestFile -Raw) $script:manifest = Invoke-Expression (Get-Content $script:manifestFile -Raw)
It "Manifest file includes the correct root module" { 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" { It "Manifest file includes the correct guid" {