3

Need to validate below xml response using frisby

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<server-auth enabled="true">
    <ldapAuth>false</ldapAuth>
    <emailAuth>true</emailAuth>
</server-auth>
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
user3121600
  • 131
  • 3
  • 8

1 Answers1

4

Simplest way is to use/install xml2js

In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.

npm install -g xml2js

    var frisby = require('frisby');
    var xml2js = require('xml2js');
    var apiEndpoint = 'http://localhost:3000/api/v1/';

    frisby.create('Parse xml')
    .get(apiEndpoint+'api.php?method=get_xml')
    .expectHeaderContains('content-type', 'text/xml')
    .after(function (err, res, body) {
        var parser = new xml2js.Parser();
        parser.parseString(body, function (err, result) {
            expect(result).toContainJson({
                "server-auth": {
                    "$": {
                        "enabled":"true"
                    },
                    "ldapAuth":["false"],
                    "emailAuth":["true"]
                }
            });
        });
    })  
    .toss();

Output

Finished in 0.041 seconds
1 test, 4 assertions, 0 failures, 0 skipped

To learn more on different usage, check this :

https://github.com/Leonidas-from-XIV/node-xml2js

RaviRokkam
  • 789
  • 9
  • 16