You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've searched existing issues and found nothing related to my issue.
Describe the feature you want to add
Keys specified in the Headers tab should be overridable in Tests. This would enable the asserts and most tests to run with the "standard" header, and specific tests to run with a different header.
Note: For the scenario I'm currently working with, the Header tab is relevant, but this could also apply to Query, Body and Auth.
Mockups or Images of the feature
I will explain my scenario using the simple API Gitlab version.
Request: GET{{GITLAB_API_V4_URL}}/version
Headers: PRIVATE-TOKEN: {{GITLAB_TOKEN}}
(where {{GITLAB_API_V4_URL}} and {{GITLAB_TOKEN}} are defined as environment variables)
Now I define a few Asserts:
res.statusequals200
res.body.versionnotEquals""
req.body.enterpriseequalstrue
Then I write a test:
test("content-type should be application/json",function(){consttoken=res.getHeader("content-type");expect(token).to.equal("application/json");})
So far, it's going great. Now ...
Problem scenario:
[Update: Please see the note at the end.]
I want to now write a test to ensure that the API is not accessible with an invalid token, so I do:
test("cannot access with invalid token",function(){req.setHeader("PRIVATE-TOKEN","invalid-token");expect(res.status).to.equal(401);})
But this doesn't work:
✘ cannot access with invalid token
expected 200 to equal 401
It appears the PRIVATE-TOKEN defined under Headers tab takes precedence over the req.setHeader() in the Tests. Hence this test fails.
What I have tried that does not work:
Remove PRIVATE-TOKEN from Headers, then set it explicitly in the tests. This is problematic because (1) Assert cannot work any more and (2) it is unintuitive for the user.
Use bru.setEnvVar() in the test to change the value. This is problematic as it updates the environment variable globally, and not only in the scope of the current test.
Proposed/requested solution:
req.setHeader(key, value) should override the respective value defined under Headers (if any) within the scope of the current test.
By reading through the docs (and reading the past issues and discussions here), I couldn't figure out any other approach to write these tests. If I have overlooked something or there's another solution already available, please point me to it.
Screenshots:
For convenient reference, below are some screenshots of what has been textually described above.
Note
I had initially misunderstood the Tests tab. I thought it was a place to write a "test suite" of multiple tests, akin to unit tests. Now I realize that those are not separate tests that trigger multiple mutually independent invocations of the API.
However, I do believe that would be a useful feature that lets us write "parametrized" tests for the API. I will update this enhancement request to describe this, but I thought I'd post an interim update here to reduce confusion.
The text was updated successfully, but these errors were encountered:
I have checked the following:
Describe the feature you want to add
Keys specified in the
Headers
tab should be overridable inTests
. This would enable the asserts and most tests to run with the "standard" header, and specific tests to run with a different header.Note: For the scenario I'm currently working with, the
Header
tab is relevant, but this could also apply toQuery
,Body
andAuth
.Mockups or Images of the feature
I will explain my scenario using the simple API Gitlab version.
Request:
GET
{{GITLAB_API_V4_URL}}/version
Headers:
PRIVATE-TOKEN
:{{GITLAB_TOKEN}}
(where
{{GITLAB_API_V4_URL}}
and{{GITLAB_TOKEN}}
are defined as environment variables)Now I define a few
Assert
s:res.status
equals
200
res.body.version
notEquals
""
req.body.enterprise
equals
true
Then I write a test:
So far, it's going great. Now ...
Problem scenario:
[Update: Please see the note at the end.]
I want to now write a test to ensure that the API is not accessible with an invalid token, so I do:
But this doesn't work:
It appears the
PRIVATE-TOKEN
defined underHeaders
tab takes precedence over thereq.setHeader()
in theTests
. Hence this test fails.What I have tried that does not work:
PRIVATE-TOKEN
fromHeaders
, then set it explicitly in the tests. This is problematic because (1)Assert
cannot work any more and (2) it is unintuitive for the user.bru.setEnvVar()
in the test to change the value. This is problematic as it updates the environment variable globally, and not only in the scope of the current test.Proposed/requested solution:
req.setHeader(key, value)
should override the respective value defined underHeaders
(if any) within the scope of the current test.By reading through the docs (and reading the past issues and discussions here), I couldn't figure out any other approach to write these tests. If I have overlooked something or there's another solution already available, please point me to it.
Screenshots:
For convenient reference, below are some screenshots of what has been textually described above.
Note
I had initially misunderstood the
Tests
tab. I thought it was a place to write a "test suite" of multiple tests, akin to unit tests. Now I realize that those are not separate tests that trigger multiple mutually independent invocations of the API.However, I do believe that would be a useful feature that lets us write "parametrized" tests for the API. I will update this enhancement request to describe this, but I thought I'd post an interim update here to reduce confusion.
The text was updated successfully, but these errors were encountered: