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

Make it possible to flexibly compare XML bodies #134

Open
sckott opened this issue Oct 14, 2024 · 1 comment
Open

Make it possible to flexibly compare XML bodies #134

sckott opened this issue Oct 14, 2024 · 1 comment
Milestone

Comments

@sckott
Copy link
Collaborator

sckott commented Oct 14, 2024

Right now a user has to give an xml class item to stub_request to match to an xml request body because for request bodies if we detect xml we just use xml2::read_xml which gives a xml_document class, which appears we can not compare to even another xml_doc probably because they have different pointers

x = read_xml("<foo> <bar> text <baz/> </bar> </foo>")
y = read_xml("<foo> <bar> text <baz/> </bar> </foo>")
identical(x, y)
#> [1] FALSE

What we're aiming for is to be able to do the following

stub_request(:post, "www.example.com").
  with(body: {data: {a: '1', b: 'five'}})

RestClient.post('www.example.com', "data[a]=1&data[b]=five",
  content_type: 'application/x-www-form-urlencoded')    # ===> Success

RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
  content_type: 'application/json')    # ===> Success

RestClient.post('www.example.com', '<data a="1" b="five" />',
  content_type: 'application/xml')    # ===> Success

In which the stub can just have an R list while the request body has XML (or JSON or a list itself), but we can still compare them

@sckott sckott added this to the v1.2 milestone Oct 14, 2024
sckott added a commit that referenced this issue Oct 15, 2024
- convert the stub body pattern from json to a list if it seems like json
- in body_as_hash change fromJSON to not use FALSE as second param
- #134 in body_as_hash change xml approach to try catch converting xml to a list or return xml as character on error
- in matches method for bodypattern add handling of pattern or request body being NA or NULL and returning false if so
@sckott
Copy link
Collaborator Author

sckott commented Oct 15, 2024

some work done in commit above - not totally sure this is done yet, to do at least:

  • new warning in xml handling section of body_as_hash seems to get supressed, not sure why yet

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

No branches or pull requests

1 participant