Skip to content

Commit

Permalink
[PS][Experimental] Add tests for array of object in response (OpenAPI…
Browse files Browse the repository at this point in the history
…Tools#5814)

* debugging array response

* fix find pet tests

* better tests to ignore order
  • Loading branch information
wing328 authored and michaelpro1 committed May 7, 2020
1 parent 0c5ae07 commit b08639e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
36 changes: 26 additions & 10 deletions samples/client/petstore/powershell-experimental/Test1.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ $Id = 38369

#$result = Update-PSPetWithForm
try {
$pet = Initialize-PSPet -Id $Id -Name 'foo' -Category (
Initialize-PSCategory -Id $Id -Name 'bar'
) -PhotoUrls @(
'http://example.com/foo',
'http://example.com/bar'
) -Tags (
Initialize-PSTag -Id 3 -Name 'baz'
) -Status Available

#Write-Host $pet
$Result = Add-PSPet -Pet $pet
Set-PSConfigurationApiKey -Id "api_key" -ApiKey "zzZZZZZZZZZZZZZ"
$result = Get-PSPetById -petId $Id -Verbose #-testHeader "testing only" -testQuery "testing something here"
} catch {
Expand All @@ -29,17 +40,22 @@ try {
#$result | Select-Object -Property "photoUrls" | ConvertTo-Json | Write-Host
#Write-Host "result =" + $result.photoUrls

#$pet = Initialize-Pet -Id 10129 -Name 'foo' -Category (
# Initialize-Category -Id 2 -Name 'bar'
#) -PhotoUrls @(
# 'http://example.com/foo',
# 'http://example.com/bar'
#) -Tags (
# Initialize-Tag -Id 3 -Name 'baz'
#) -Status Available
#

$pet2 = Initialize-PSPet -Id 20129 -Name '2foo' -Category (
Initialize-PSCategory -Id 20129 -Name '2bar'
) -PhotoUrls @(
'http://example.com/2foo',
'http://example.com/2bar'
) -Tags (
Initialize-PSTag -Id 3 -Name 'baz'
) -Status Available

#Write-Host $pet
#$Result = Invoke-PetApiAddPet -Body $pet
$Result = Add-PSPet -Pet $pet2

$Result = Find-PSPetsByTags 'baz'
Write-Host $Result.GetType().Name
Write-Host $Result

#$Result = Invoke-PetApiUpdatePetWithForm -petId $Id -Name "PowerShell Update" -Status "Pending"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {
$Result."id" | Should Be 38369
$Result."name" | Should Be "PowerShell"
$Result."status" | Should Be "Available"
$Result."category"."id" | Should Be $Id
$Result."category"."name" | Should Be 'PSCategory'

$Result.GetType().fullname | Should Be "System.Management.Automation.PSCustomObject"

Expand Down Expand Up @@ -65,6 +67,51 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {
$Result = Remove-Pet -petId $Id

}

It 'Find pets test' {

# add 1st pet
$pet = Initialize-PSPet -Id 10129 -Name 'foo' -Category (
Initialize-PSCategory -Id 20129 -Name 'bar'
) -PhotoUrls @(
'http://example.com/foo',
'http://example.com/bar'
) -Tags (
Initialize-PSTag -Id 10129 -Name 'bazbaz'
) -Status Available

$Result = Add-PSPet -Pet $pet

# add 2nd pet
$pet2 = Initialize-PSPet -Id 20129 -Name '2foo' -Category (
Initialize-PSCategory -Id 20129 -Name '2bar'
) -PhotoUrls @(
'http://example.com/2foo',
'http://example.com/2bar'
) -Tags (
Initialize-PSTag -Id 10129 -Name 'bazbaz'
) -Status Available

$Result = Add-PSPet $pet2

# test find pets by tags
$Results = Find-PSPetsByTags 'bazbaz'
$Results.GetType().FullName| Should Be "System.Object[]"
$Results.Count | Should Be 2

if ($Results[0]."id" -gt 10129) {
$Results[0]."id" | Should Be 20129
} else {
$Results[0]."id" | Should Be 10129
}

if ($Results[1]."id" -gt 10129) {
$Results[1]."id" | Should Be 20129
} else {
$Results[1]."id" | Should Be 10129
}

}
}

Context 'Configuration' {
Expand Down

0 comments on commit b08639e

Please sign in to comment.