'use strict';

require('should');

var tesseract = require('../lib/');


var testTesseract = function(path, done) {
  var document = {
    metadatas: {
      path: "osef",
    }
  };

  tesseract(path, document, function(err, document) {
    if (err) {
      throw err;
    }

    document.should.have.property('document_type', "image");
    document.should.have.property('metadatas');
    document.metadatas.should.have.property('text', "Tesseract sample image. The quick brown fox jumps over the lazy dog.\n\n");

    done();
  });
};

describe('Test tesseract results', function() {
  it('returns the correct informations for png image', function(done) {
    testTesseract(__dirname + '/samples/sample.png', done);
  });

  it('returns the correct informations for gif image', function(done) {
    var initDocument = {
      metadatas: {
        path: "/samples/sample.gif",
      }
    };
    tesseract(__dirname + '/samples/sample.gif', initDocument, function(err, document){
      if(err) {
        throw err;
      }
      document.should.have.property("hydration_errored", true);
      document.should.have.property("hydration_error");

      done();

    });
  });

  it('returns the correct informations for gif content-type', function(done) {
    var initDocument = {
      metadatas: {
        path: "/samples/bugged",
        'content-type': 'image/gif'
      },
    };
    tesseract(__dirname + '/samples/bugged', initDocument, function(err, document){
      if(err) {
        throw err;
      }
      document.should.have.property("hydration_errored", true);
      document.should.have.property("hydration_error");

      done();

    });
  });

  it('returns the correct informations for jpg image', function(done) {
    testTesseract(__dirname + '/samples/sample.jpg', done);
  });

  it('returns the correct informations for tif image', function(done) {
    testTesseract(__dirname + '/samples/sample.tif', done);
  });

  it('returns an errored document for non image', function(done) {
    var document = {
      metadatas: {
        path: "osef",
      }
    };
    tesseract(__filename, document, function(err, document) {
      if(err) {
        throw err;
      }
      document.should.have.property("hydration_errored", true);
      document.should.have.property("hydration_error");

      done();
    });
  });

  it('should return an errored document', function(done) {
    var document = {
      metadatas: {
        path: "/samples/errored.psd",
      }
    };

    tesseract(__dirname + "/samples/errored.psd", document, function(err, document) {
      if(err) {
        throw err;
      }
      document.should.have.property("hydration_errored", true);
      document.should.have.property("hydration_error");
      done();
    });
  });

});

@@ -1043,103 +1043,27 @@
 uld.
-have.property(%22hydration_errored%22, true);%0A      document.should.have.property(%22hydration_error%22
+be.eql(initDocument
 );%0A%0A
@@ -1453,103 +1453,27 @@
 uld.
-have.property(%22hydration_errored%22, true);%0A      document.should.have.property(%22hydration_error%22
+be.eql(initDocument
 );%0A%0A

update test