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

@ -35,6 +35,11 @@ function Get-Asset()
function New-Asset() function New-Asset()
{ {
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$Name, [string]$Name,
@ -64,16 +69,27 @@ 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()
{ {
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[int]$id, [int]$id,
@ -105,16 +121,27 @@ 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()
{ {
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[int]$id, [int]$id,
@ -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,4 +1,4 @@
function Get-Categories() function Get-Category()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]

View file

@ -17,6 +17,11 @@ function Get-Component()
function New-Component() function New-Component()
{ {
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$name, [string]$name,
@ -42,16 +47,27 @@ 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()
{ {
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$id, [string]$id,
@ -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
} }

View file

@ -1,4 +1,4 @@
function Get-Manufacturers() function Get-Manufacturer()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
@ -17,6 +17,11 @@ function Get-Manufacturers()
function New-Manufacturer() function New-Manufacturer()
{ {
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$Name, [string]$Name,
@ -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,5 +1,5 @@
function Get-Models() function Get-Model()
{ {
Param( Param(
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
@ -19,6 +19,11 @@ 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,
@ -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

@ -15,7 +15,7 @@ Get-Users -url "https://assets.dip.co.uk" -token "token..."
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)]

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" {