import parse from '../lib/index.js';
import {expect} from 'chai';
import assert from 'assert';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));
var POM_PATH = __dirname + "/fixture/pom.xml";

describe('require("pom-parser")', function () {

  describe('loading from files', function() {
    var pomResponse = null;
    var pom = null;
    var xml = null;

    // Setup the tests using mocha's promise.
    // https://lostechies.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promises-and-winjs/
    before(function(done) {
      parse({filePath: POM_PATH}, function(err, response) {
        expect(err).to.be.null;
        expect(response).to.be.an("object");

	pomResponse = response;
	pom = pomResponse.pomObject;
	xml = pomResponse.pomXml;
	done();
      });
    });

    // Tear down the tests by printing the loaded xml and the parsed object.
    after(function(done) {
      console.log("\n\nThe XML loaded");
      console.log(xml);
      console.log("\n\nThe parsed XML");
      console.log(JSON.stringify(pom, null, 2));
      done();
    });
 
    it('can load any pom.xml properly', function(done) {
      expect(pomResponse.pomXml).to.be.an("string");
      expect(pomResponse.pomObject).to.be.an("object");
      done();
    });

    it('parses xml attributes as properties', function(done) {
      expect(pom.project.xmlns).to.equal("http://maven.apache.org/POM/4.0.0");
      expect(pom.project["xmlns:xsi"]).to.equal("http://www.w3.org/2001/XMLSchema-instance"); 
      done();
    });

    it('parses xml elements as properties', function(done) {
      expect(pom.project.parent).to.be.an("object");
      expect(pom.project.parent.artifactid).to.equal("tynamo-parent");
      done();
    });

  });

  describe('when opts is null', function(){
    it('parser should throw an error', function() {
      assert.throws(function(){
        parse(null, function(err, response){}, Error);
      });
    });
  });

  describe('when opts is empty', function(){
    it('parser should throw an error', function(){
      assert.throws(function(){
        parse(null, function(err, response){}, Error);
      });
    });
  });

});

@@ -2223,12 +2223,844 @@
 %0A  %7D);%0A%0A
+  describe('error scenarios', function() %7B%0A    it('should return error if file does not exist', function(done) %7B%0A      parse(%7B filePath: __dirname + 'incorrect-file-path' %7D, function(err, response) %7B%0A        expect(response).to.be.null;%0A        expect(err).to.not.be.null;%0A        done();%0A      %7D);%0A    %7D);%0A%0A    it('should return error if invalid xml file', function(done) %7B%0A      parse(%7B filePath: __dirname + '/fixture/pom2.xml' %7D, function(err, response) %7B%0A        expect(response).to.be.null;%0A        expect(err).to.not.be.null;%0A        done();%0A      %7D);%0A    %7D);%0A%0A    it('should return error if invalid xml content', function(done) %7B%0A      const invalidXml = '%3Cparent%3Ethis is invalid%3C/PARENT%3E';%0A      parse(%7B xmlContent: invalidXml %7D, function(err) %7B%0A        expect(err).to.not.be.null;%0A        done();%0A      %7D);%0A    %7D);%0A  %7D);%0A%0A
 %7D);%0A

add test cases which were removed while testing