Skip to content

Commit b08639e

Browse files
wing328michaelpro1
authored andcommitted
[PS][Experimental] Add tests for array of object in response (OpenAPITools#5814)
* debugging array response * fix find pet tests * better tests to ignore order
1 parent 0c5ae07 commit b08639e

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

samples/client/petstore/powershell-experimental/Test1.ps1

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ $Id = 38369
1717

1818
#$result = Update-PSPetWithForm
1919
try {
20+
$pet = Initialize-PSPet -Id $Id -Name 'foo' -Category (
21+
Initialize-PSCategory -Id $Id -Name 'bar'
22+
) -PhotoUrls @(
23+
'http://example.com/foo',
24+
'http://example.com/bar'
25+
) -Tags (
26+
Initialize-PSTag -Id 3 -Name 'baz'
27+
) -Status Available
28+
29+
#Write-Host $pet
30+
$Result = Add-PSPet -Pet $pet
2031
Set-PSConfigurationApiKey -Id "api_key" -ApiKey "zzZZZZZZZZZZZZZ"
2132
$result = Get-PSPetById -petId $Id -Verbose #-testHeader "testing only" -testQuery "testing something here"
2233
} catch {
@@ -29,17 +40,22 @@ try {
2940
#$result | Select-Object -Property "photoUrls" | ConvertTo-Json | Write-Host
3041
#Write-Host "result =" + $result.photoUrls
3142

32-
#$pet = Initialize-Pet -Id 10129 -Name 'foo' -Category (
33-
# Initialize-Category -Id 2 -Name 'bar'
34-
#) -PhotoUrls @(
35-
# 'http://example.com/foo',
36-
# 'http://example.com/bar'
37-
#) -Tags (
38-
# Initialize-Tag -Id 3 -Name 'baz'
39-
#) -Status Available
40-
#
43+
44+
$pet2 = Initialize-PSPet -Id 20129 -Name '2foo' -Category (
45+
Initialize-PSCategory -Id 20129 -Name '2bar'
46+
) -PhotoUrls @(
47+
'http://example.com/2foo',
48+
'http://example.com/2bar'
49+
) -Tags (
50+
Initialize-PSTag -Id 3 -Name 'baz'
51+
) -Status Available
52+
4153
#Write-Host $pet
42-
#$Result = Invoke-PetApiAddPet -Body $pet
54+
$Result = Add-PSPet -Pet $pet2
55+
56+
$Result = Find-PSPetsByTags 'baz'
57+
Write-Host $Result.GetType().Name
58+
Write-Host $Result
4359

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

samples/client/petstore/powershell-experimental/tests/Petstore.Tests.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Describe -tag 'PSOpenAPITools' -name 'Integration Tests' {
2626
$Result."id" | Should Be 38369
2727
$Result."name" | Should Be "PowerShell"
2828
$Result."status" | Should Be "Available"
29+
$Result."category"."id" | Should Be $Id
30+
$Result."category"."name" | Should Be 'PSCategory'
2931

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

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

6769
}
70+
71+
It 'Find pets test' {
72+
73+
# add 1st pet
74+
$pet = Initialize-PSPet -Id 10129 -Name 'foo' -Category (
75+
Initialize-PSCategory -Id 20129 -Name 'bar'
76+
) -PhotoUrls @(
77+
'http://example.com/foo',
78+
'http://example.com/bar'
79+
) -Tags (
80+
Initialize-PSTag -Id 10129 -Name 'bazbaz'
81+
) -Status Available
82+
83+
$Result = Add-PSPet -Pet $pet
84+
85+
# add 2nd pet
86+
$pet2 = Initialize-PSPet -Id 20129 -Name '2foo' -Category (
87+
Initialize-PSCategory -Id 20129 -Name '2bar'
88+
) -PhotoUrls @(
89+
'http://example.com/2foo',
90+
'http://example.com/2bar'
91+
) -Tags (
92+
Initialize-PSTag -Id 10129 -Name 'bazbaz'
93+
) -Status Available
94+
95+
$Result = Add-PSPet $pet2
96+
97+
# test find pets by tags
98+
$Results = Find-PSPetsByTags 'bazbaz'
99+
$Results.GetType().FullName| Should Be "System.Object[]"
100+
$Results.Count | Should Be 2
101+
102+
if ($Results[0]."id" -gt 10129) {
103+
$Results[0]."id" | Should Be 20129
104+
} else {
105+
$Results[0]."id" | Should Be 10129
106+
}
107+
108+
if ($Results[1]."id" -gt 10129) {
109+
$Results[1]."id" | Should Be 20129
110+
} else {
111+
$Results[1]."id" | Should Be 10129
112+
}
113+
114+
}
68115
}
69116

70117
Context 'Configuration' {

0 commit comments

Comments
 (0)