Collection status: Used variables | AssertionError: expected -1 to be above -1

This seems to be catching a few people out, so I’ll try and explain what is happening.

This is the test that is failing.

pm.expect(encodeURI(authObj.apikey.value).indexOf('%7B%7B')).to.be.above(-1)

authObj relates to the authentication.

The indexOf() method returns the position of the first occurrence of a value in a string.
The indexOf() method returns -1 if the value is not found.
The indexOf() method is case sensitive

%7B in an URL is converted to {
This is what the encodeURI is doing.

There should only be one apikey in the response and the value should be set to {{email_key}}

So the test is basically testing to see if the authObj.apikey.value contains {{

If it can’t find it, then the test will fail (as the indexof() method will return -1).

The apikey value is actually logged to the console during the test.

    let addresses = requestArr.filter(value => value.request.url.raw ? value.request.url.raw : value.request.url).map(value => value.request.url.raw ? value.request.url.raw : value.request.url);
    var addressVars = addresses.filter(p => encodeURI(p).indexOf('%7B%7B')>-1); 
    console.log(addressVars);

It should be the first value in the console logs.

image

The screenshots I’ve seen where its failing are showing more than one element in the logs.

image

This will break the test as the response is now an array.

authObj.apikey.value will fail
authObj.apikey[0].value would work

This is related to the authentication which is meant to be set at the collection level.

Everywhere else (all folders and requests) the authentication should be set to inherit auth from parent.