marklogic-community / marklogic-unit-test

Automated testing for MarkLogic
https://marklogic-community.github.io/marklogic-unit-test/
Other
13 stars 25 forks source link

XDMP-TOOMANYARGS when passing more than two nodes to test:assert-exists() helper function #158

Closed antonymadonnaa closed 1 year ago

antonymadonnaa commented 1 year ago

Hi ,

when trying to check if more than two nodes are present in the unit test response, I'm passing multiple nodes to test:assert-exists() helper function.

But , it seems not more than 2 nodes can be passed to this but the API definition says it would accept multiple nodes. https://marklogic-community.github.io/marklogic-unit-test/docs/assertions/

Error: XDMP-TOOMANYARGS: (err:XPST0017) test:assert-exists($save-resp[2]/node()[text() eq "Record saved successfully"], $doc/envelope/book/book-meta/supplementary-material/alt-text[text() eq "text 1"], $doc/envelope/book/book-meta/supplementary-material/uri[@xlink:href eq "ftp://www.abc.com"], $doc/envelope/book/book-meta/supplementary-material[@xlink:href eq "one.png"]) -- Too many args, expected 2 but got 4

Could you please if this is an issue and resolve it ?

Thanks in advance!

rjrudin commented 1 year ago

Hi @antonymadonnaa - assert-exists allows a sequence, which it passes to fn:exists. It returns true if the sequence is not the empty sequence. To pass in multiple items as a sequence in XQuery, you surround them with parentheses:

test:assert-exists(($item1, $item2, $item3), "Assertion message is the second argument")

It sounds though that you would rather use assert-all-exist:

test:assert-all-exist(3, ($item1, $item2, $item3), "Optional assertion message goes here")

Those docs need updating to include the support for assertion messages as the last argument in each assertion function. We're planning a new release soon of marklogic-unit-test and will get those pages updated as part of it.

antonymadonnaa commented 1 year ago

Hi @rjrudin Yes, for test:assert-exists() I tried concatenating with parentheses but it returns true even if atleast one item in the sequence exists.

As you said, I think I need to use test:assert-all-exist(), thank you for the information and it would be helpful if the document gets updated during next planned release. Thanks!