Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about behavior of >, >=, <, <= versus ==, != #798

Closed
danielbprice opened this issue Sep 1, 2022 · 2 comments · Fixed by #818
Closed

Confused about behavior of >, >=, <, <= versus ==, != #798

danielbprice opened this issue Sep 1, 2022 · 2 comments · Fixed by #818
Labels
enhancement New feature or request
Milestone

Comments

@danielbprice
Copy link

Let's say I have an API which returns a list of objects, and they are supposed to be sorted in order by their createdAt field in ascending order. Let us assume that createdAt is a timestamp string such as 2022-08-06T05:55:35Z.

So I would like to do this:

  GET {{url}}/api/widgets

  HTTP/* 200
  [Captures]
  zero_created: jsonpath "$[0].['createdAt']"
  [Asserts]
  jsonpath "$[1].['createdAt']" > {{zero_created}}

This results in:

error: Parsing predicate value
 34 | jsonpath "$[1].['createdAt']" > {{zero_created}}
    |                                 ^ invalid predicate value

However hurl will let me write an assertion using ==, like this:

  jsonpath "$[1].['createdAt']" == {{zero_created}}

(Of course, this assertion will fail unless the timestamps are the same, but the point is that it isn't illegal). Is the problem here that the <, <=, etc. comparisons are simply not implemented for string values? For what it's worth it also seems like it doesn't work when the value is clearly numeric, like this:

  GET {{url}}/api/all-widgets

  HTTP/* 200
  [Captures]
  all_widget_count: jsonpath "$" count
  [Asserts]
  jsonpath "$" count == {{all_widget_count}}   # <--- is fine
  jsonpath "$" count <= {{all_widget_count}}   # <--- is not fine, error: Parsing predicate value

Thanks!

@fabricereix
Copy link
Collaborator

fabricereix commented Sep 2, 2022

Hello,
Yes, the comparison predicate (<, <=, >, >=) are not supported for String, only for numbers values (Int and Float).
But it could also make sense to support String as well.

I could reproduce your bug with the count example.
The bug is not with the numeric value as such, but with the variables.

We can leave this issue as an enhancement for supporting String.
I've created another one #799 for tha variable bug.
Thanks a lot for spotting it

@fabricereix fabricereix added the enhancement New feature or request label Sep 2, 2022
@jcamiel jcamiel added this to the 1.7.0 milestone Sep 9, 2022
@jcamiel
Copy link
Collaborator

jcamiel commented Sep 9, 2022

Hi @danielbprice we've implemented the comparison on strings values. You can pull master to test it. Happy to have your feedback, and thanks for your suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants