Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds parameter sets to web cmdlets to allow for standard and non-stan… #3142

Merged
merged 6 commits into from Mar 6, 2017
Expand Up @@ -400,21 +400,33 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
$result.Error | Should BeNullOrEmpty
}

It "Validate StandardMethod and CustomMethod parameter sets" {
It "Validate Invoke-WebRequest StandardMethod and CustomMethod parameter sets" {

#Validate that parameter sets are functioning correctly
$command = "Invoke-RestMethod -Uri 'http://sandbox.lee.io/method.php' -Method GET -CustomMethod 'TEST'"
$result = ExecuteWebCommand -command $command
$result.Error | Should Not BeNullOrEmpty
$errorId = "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
{ Invoke-WebRequest -Uri 'http://http.lee.io/method' -Method GET -CustomMethod TEST } | ShouldBeErrorId $errorId
}

It "Validate CustomMethod parameter set method is passed" {
It "Validate Invoke-WebRequest CustomMethod method is used" {

#Validate that custom method is used
$command = "Invoke-RestMethod -Uri 'http://http.lee.io/method' -CustomMethod 'TEST'"
$command = "Invoke-WebRequest -Uri 'http://http.lee.io/method' -CustomMethod TEST"
$result = ExecuteWebCommand -command $command
$result.Error | Should BeNullOrEmpty
$result.output.method | Should Be "TEST"
($result.Output.Content | ConvertFrom-Json).output.method | Should Be "TEST"
}

It "Validate Invoke-WebRequest default ContentType for CustomMethod POST" {

$command = "Invoke-WebRequest -Uri 'http://httpbin.org/post' -CustomMethod POST -Body 'testparam=testvalue'"
$result = ExecuteWebCommand -command $command
($result.Output.Content | ConvertFrom-Json).headers.'Content-Type' | Should Be "application/x-www-form-urlencoded"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you're sending a specific body, seems like you should just check it was returned correctly in the response:

$result.Output.form.testvalue | Should Be "testvalue"

}

It "Validate Invoke-WebRequest body is converted to query params for CustomMethod GET" {

$command = "Invoke-WebRequest -Uri 'http://httpbin.org/get' -Method GET -Body @{'testparam'='testvalue'}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be -custommethod?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely missed that! Fixed

$result = ExecuteWebCommand -command $command
($result.Output.Content | ConvertFrom-Json).args.testparam | Should Be "testvalue"
}

It "Validate Invoke-WebRequest returns HTTP errors in exception" {
Expand Down Expand Up @@ -666,6 +678,34 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
$result.Error | Should BeNullOrEmpty
}

It "Validate Invoke-RestMethod StandardMethod and CustomMethod parameter sets" {

$errorId = "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
{ Invoke-RestMethod -Uri 'http://http.lee.io/method' -Method GET -CustomMethod TEST } | ShouldBeErrorId $errorId
}

It "Validate CustomMethod method is used" {

$command = "Invoke-RestMethod -Uri 'http://http.lee.io/method' -CustomMethod TEST"
$result = ExecuteWebCommand -command $command
$result.Error | Should BeNullOrEmpty
$result.Output.output.method | Should Be "TEST"
}

It "Validate Invoke-RestMethod default ContentType for CustomMethod POST" {

$command = "Invoke-RestMethod -Uri 'http://httpbin.org/post' -CustomMethod POST -Body 'testparam=testvalue'"
$result = ExecuteWebCommand -command $command
$result.Output.headers.'Content-Type' | Should Be "application/x-www-form-urlencoded"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you're sending a specific body, seems like you should just check it was returned correctly in the response:

$result.Output.form.testvalue | Should Be "testvalue"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now refactored the tests for this

}

It "Validate Invoke-RestMethod body is converted to query params for CustomMethod GET" {

$command = "Invoke-RestMethod -Uri 'http://httpbin.org/get' -Method GET -Body @{'testparam'='testvalue'}"
$result = ExecuteWebCommand -command $command
$result.Output.args.testparam | Should Be "testvalue"
}

It "Invoke-RestMethod supports request that returns plain text response." {

$command = "Invoke-RestMethod -Uri 'http://httpbin.org/encoding/utf8'"
Expand Down