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
.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
}

View file

@ -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
)

View file

@ -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
}#>
}#>

View file

@ -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
}
}

View file

@ -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
}
}

View file

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

View file

@ -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
}
}

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
.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
)

Binary file not shown.

View file

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