<commit_before>var fs = require('fs');
var Fhir = require('../../fhir');
var assert = require('assert');

describe('DSTU2: Validation', function() {
    describe('ValidateXMLResource()', function() {
        it('should validate bundle-transaction successfully', function() {
            var bundleXml = fs.readFileSync('./test/data/dstu2/bundle-transaction.xml').toString('utf8');
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateXMLResource(bundleXml);

            assert(result);
            assert.equal(result.valid, true);
        });

        it('should return validation errors for bundle-transaction_bad', function() {
            var bundleXml = fs.readFileSync('./test/data/dstu2/bundle-transaction_bad.xml').toString('utf8');
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateXMLResource(bundleXml);

            assert(result);
            assert.equal(result.valid, false);
            assert(result.errors);
            assert.equal(result.errors.length, 1);
            assert.equal(result.errors[0], "Element '{http://hl7.org/fhir}fullUrl': This element is not expected. Expected is ( {http://hl7.org/fhir}response ).\n");
        });
    });

    describe('ValidateJSONResource()', function() {
        it('should validate bundle-transaction.json successfully', function() {
            var bundleJson = fs.readFileSync('./test/data/dstu2/bundle-transaction.json').toString('utf8');
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateJSONResource(bundleJson);

            assert(result);
            assert.equal(result.valid, true);

            assert(result.errors);
            assert.equal(result.errors.length, 0);
        });
    });

    describe('ValidateJSResource()', function() {
        it('should validate bundle-transaction.json successfully', function() {
            var bundleJson = JSON.parse(fs.readFileSync('./test/data/dstu2/bundle-transaction.json').toString('utf8'));
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateJSResource(bundleJson);

            assert(result);
            assert.equal(result.valid, true);

            assert(result.errors);
            assert.equal(result.errors.length, 0);
        });

        it('should validate with a differential profile sucessfully', function () {
          var profile = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest-diff-profile.json').toString('utf8'));
          var docManifest = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest.json').toString('utf8'));
          var fhir = new Fhir(Fhir.STU3);
          var result = fhir.ValidateJSResource(docManifest, profile);

          assert(result);
          assert.equal(result.valid, true);

          assert(result.errors);
          assert.equal(result.errors.length, 0);
        });

        it('should return errors when validating with a differential profile', function () {
          var profile = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest-diff-profile.json').toString('utf8'));
          var docManifest = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest_bad.json').toString('utf8'));
          var fhir = new Fhir(Fhir.STU3);
          var result = fhir.ValidateJSResource(docManifest, profile);

          assert(result);
          assert.equal(result.valid, false);

          assert(result.errors);
          assert.equal(result.errors.length, 1);<commit_msg>Update validationTests.js<commit_after>var fs = require('fs');
var Fhir = require('../../fhir');
var assert = require('assert');

describe('DSTU2: Validation', function() {
    describe('ValidateXMLResource()', function() {
        it('should validate bundle-transaction successfully', function() {
            var bundleXml = fs.readFileSync('./test/data/dstu2/bundle-transaction.xml').toString('utf8');
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateXMLResource(bundleXml);

            assert(result);
            assert.equal(result.valid, true);
        });

        it('should return validation errors for bundle-transaction_bad', function() {
            var bundleXml = fs.readFileSync('./test/data/dstu2/bundle-transaction_bad.xml').toString('utf8');
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateXMLResource(bundleXml);

            assert(result);
            assert.equal(result.valid, false);
            assert(result.errors);
            assert.equal(result.errors.length, 1);
            assert.equal(result.errors[0], "Element '{http://hl7.org/fhir}fullUrl': This element is not expected. Expected is ( {http://hl7.org/fhir}response ).\n");
        });
    });

    describe('ValidateJSONResource()', function() {
        it('should validate bundle-transaction.json successfully', function() {
            var bundleJson = fs.readFileSync('./test/data/dstu2/bundle-transaction.json').toString('utf8');
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateJSONResource(bundleJson);

            assert(result);
            assert.equal(result.valid, true);

            assert(result.errors);
            assert.equal(result.errors.length, 0);
        });
    });

    describe('ValidateJSResource()', function() {
        it('should validate bundle-transaction.json successfully', function() {
            var bundleJson = JSON.parse(fs.readFileSync('./test/data/dstu2/bundle-transaction.json').toString('utf8'));
            var fhir = new Fhir(Fhir.DSTU2);
            var result = fhir.ValidateJSResource(bundleJson);

            assert(result);
            assert.equal(result.valid, true);

            assert(result.errors);
            assert.equal(result.errors.length, 0);
        });

        it('should validate with a differential profile sucessfully', function () {
          var profile = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest-diff-profile.json').toString('utf8'));
          var docManifest = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest.json').toString('utf8'));
          var fhir = new Fhir(Fhir.DSTU2);
          var result = fhir.ValidateJSResource(docManifest, profile);

          assert(result);
          assert.equal(result.valid, true);

          assert(result.errors);
          assert.equal(result.errors.length, 0);
        });

        it('should return errors when validating with a differential profile', function () {
          var profile = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest-diff-profile.json').toString('utf8'));
          var docManifest = JSON.parse(fs.readFileSync('./test/data/dstu2/doc-manifest_bad.json').toString('utf8'));
          var fhir = new Fhir(Fhir.DSTU2);
          var result = fhir.ValidateJSResource(docManifest, profile);

          assert(result);
          assert.equal(result.valid, false);

          assert(result.errors);
          assert.equal(result.errors.length, 1);
{'fraction_non_alphanumeric': 0.14414029084687768, 'fraction_numerical': 0.008839463929284289, 'mean_word_length': 2.6066838046272496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5424074', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1940, 'n_words': 342}