Upgraded to Pester 5 - now broken :(

Hi,

I have been using a previous version of Pesterto test a load of https APIs. Each API requires a set of headers passed into each request. Previously I was just adding these as a function before and passing the values into the pester test. but now these all fail to run and I’m not sure I understand why.

I’ve added the beforeEach{ and added my function within that script block, but it still fails.

BeforeEach{
    function Get.WebRequest.Headers { 
     [cmdletbinding()]
        param(
    $AccessKey = "##################################",
    $uri = "https://############identity##########/oauth2/default/v1/token",
    $endPoints = (Get-Content .\Pester.Test.Apis.WebRequest\Api.Endpoints.json | ConvertFrom-Json -AsHashtable)
    )
    $Headers = @{}
    $Headers.Authorization = "####################################################"
    $headers.'Content-Type' = "#######################"
    $headers.Cookie = "####################################################"
    $Body = "##############################################"
$R = Invoke-WebRequest -uri $Uri `
                       -Body $body `
                       -Headers $headers `
                       -Method POST 
    $Token = $R.Content | ConvertFrom-Json
    $Token = "Bearer $($token.Access_Token)"
}

}
Describe ‘Testing all environment endpoints’ {
Context ‘API Test against #############’{
foreach ($endpoint in $endPoints.endpoints.#########.Values){
$date = Get-Date
it “$date Testing $endpoint”{
$headers = @{}
$headers.Authorization = “$Token”
$headers.“################” = “$AccessKey”
$R = Invoke-WebRequest -Uri $endPoint -Headers $Headers
-Method GET
$R.StatusCode | should be 200
$R
}
}
}

I've cut off the rest of the script cause it does a lot of other stuff, but these tests fail as well as the others.

Any help would be great.

Thanks

 

Pester v5 has couple of breaking changes and below link should help you.

https://dsccommunity.org/blog/converting-tests-to-pester5/