usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
26.26k stars 1.2k forks source link

Error saying tests are not defined on running request #3331

Open jonashilmersson opened 1 day ago

jonashilmersson commented 1 day ago

I have checked the following:

Describe the bug

I have downloaded the postman collection for commercetools and setup an environment. When I try to run the "Obtain an access token" I get the following error:

Error invoking remote method 'send-http-request': ReferenceError: tests is not defined

Looking in the Tests tab, there is code for tests. If I clear the test scripts tab, the request works.

The same environment/collection works fine in Postman.

.bru file to reproduce the bug

No response

Screenshots/Live demo link

image

helloanoop commented 1 day ago

@jonashilmersson It appears the test script needs to be updated to match Bruno's format of writing tests. We have some basic documentation here on the syntax of the test function - https://docs.usebruno.com/testing/introduction

If you could your share one of the sample tests, I should be able to share you how the Bruno equivalent looks like?

BTW, You can also checkout Bruno SDK of commercetools - https://docs.commercetools.com/sdk/bruno

jonashilmersson commented 1 day ago

It's the scripts that are included in the Postman collection from commercetools, for example this for the Obtain access token:

tests["Status code is 200"] = responseCode.code === 200;
var data = JSON.parse(responseBody);
if(data.access_token){
    pm.environment.set("ctp_access_token", data.access_token);
}
if (data.scope) {
    parts = data.scope.split(" ");
    parts = parts.filter(scope => scope.includes(":")).map(scope => scope.split(":"))
    if (parts.length > 0) {
        scopeParts = parts[0];
        pm.environment.set("project-key", scopeParts[1]);
        parts = parts.filter(scope => scope.length >= 3)
        if (parts.length > 0) {
            scopeParts = parts[0];
            pm.environment.set("store-key", scopeParts[2]);
        }
    }
}

But if there are Bruno-specific files I guess I can try these, thanks!

jonashilmersson commented 1 day ago

I cloned that repo and just tried to import the bru file at https://github.com/commercetools/commercetools-api-reference/blob/main/bruno/api/auth/clientCredentials.bru as a Bruno collection , but I get an error message saying the import failed.

I also created a new API client in commercetools and downloaded the keys as a Bruno collection, but can't import this either.