Hi,
I have a pester test that run against a API - the first test ensures i can get a authentication token from the api. This token then needs to pass onto the next test to check accessing records etc.
It seems the the token doesn’t get passed onto the next test?
Describe 'Test API' {
Context 'Testing API'{
it 'Can generate a token'{
$Auth = @{}
$Auth.PresentedIdentifier = "asdbnefd"
$Auth.PresentedSecret= "qweerty"
$R = Invoke-WebRequest -Uri "https://theapiaddress.me" `
-Body ($Auth | ConvertTo-Json) `
-ContentType "application/json" `
-Method Post `
-UseBasicParsing
$Response = $R | ConvertFrom-Json
$Response.tokenString | Should Not BeNullOrEmpty
}
it 'Use token to access records' {
$Headers = $Response.TokenString
$T = Invoke-WebRequest -Uri "https://theapiaddress.me"`
-Method Get `
-Headers $Headers `
-UseBasicParsing
$Out = $T | ConvertFrom-Json
$Out.webUserId | Should Not BeNullOrEmpty
}
}
}
What is the best way to do it, i know it will work if i put all the tests under a single test, but i want to test each step, if you know what i mean.
Thanks
Tommy