thunder-client-support icon indicating copy to clipboard operation
thunder-client-support copied to clipboard

Integer casting

Open LucaPaganin opened this issue 3 years ago • 2 comments

Hi,

I am testing a REST API which creates a resource, and I would like to check if the resource is correctly created. In order to do so, I am trying to check if the number of resources after creation is equal to the number of resources after creation.

I have a REST API call giving me the list of resources, together with their number, in a JSON response, like this

{
  "status": "completed",
  "code": 0,
  "data": {
    "resources": {
      "35565dba-83da-4f15-9fbb-8c052e0c3820": {
        "type": "flow",
        "name": "testRfl4143dfd8-e37b-419a-8789-965a61e7a75d",
        "isversioned": false,
        "islocked": false
      },
      "098761a9-7f1d-476d-a8cf-d8c1e035ab92": {
        "type": "flow",
        "name": "testRfla6308bab-96b1-42db-9e7b-dcd88af0cd04",
        "isversioned": false,
        "islocked": false
      },
      "709203d0-f99f-46ea-b106-c7dd68b7d456": {
        "type": "flow",
        "name": "testRfl43a8186c-7811-46ec-a967-2cf2c148239b",
        "isversioned": false,
        "islocked": false
      }
    },
    "n_resources": 3,
    "folder": {
      "id": "8b85583a-73d1-46b3-94d4-4aba4c553de3",
      "name": "rulex"
    },
    "path": {
      "id": [
        "c35a8e90-3cf6-49bd-9c04-e6e9eaa60842"
      ],
      "name": [
        "/"
      ]
    },
    "create": true
  },
  "desc": ""
}

In the test I grab the number n of resources with json.data.n_resources, and I would like to simply calculate n+1. I save the previous number of resources n in a variable that I have called nRfls. However, when I try to test if the new number is equal to nRfls+1 the test fails, because the result is not a sum between integers but a string concatenation. See below image

image

I tried to to various tests with int(...) or parseInt(...) without success. Is there any way to cast a variable to integer or float to do numeric testing?

Thanks for your help

LucaPaganin avatar May 27 '22 14:05 LucaPaganin

Hi @LucaPaganin Currently this operation is not possible. Will add to roadmap.

Alternatively you can use > operation

image

rangav avatar May 27 '22 14:05 rangav

I had noticed the possibility to test numeric comparison with > and <. I didn't know that integer operations were not possible. Thanks for your support

LucaPaganin avatar May 27 '22 14:05 LucaPaganin

This feature is now implemented and published to marketplace, please update to v2.0.0

See all features released https://github.com/rangav/thunder-client-support/releases/tag/v2.0.0

Please let me know your feedback.

You need to use add filter - {{nRfls | add(1)}} or {{nRfls | add("anotherVarName")}}

rangav avatar Nov 17 '22 12:11 rangav