<commit_before>const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const fs = require('fs');

import microsofComputerVision from 'index'

chai.use(chaiAsPromised)
chai.use(require('chai-fs'))
const expect = chai.expect
const assert = chai.assert
const myKey = "<KEY>"

describe('#tagImage()', () => {
  it('Should return an array of tags by image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"
    const contentType = "application/json"

    const result = microsofComputerVision.tagImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": contentType, "url": imageUrl, "request-origin": "eastus2"})

    return expect(result).to.eventually.have.property("tags")
  })

  it('Should return an array of tags by image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.tagImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": contentType, "url": data, "request-origin": "eastus2"})

      return expect(result).to.eventually.have.property("tags")
    })

  })

})

describe('#analyzeImage()', () => {
  it('Should return an array of faces by image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.analyzeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/json", "url": imageUrl, "visual-features": "faces", "request-origin": "eastus2"})

    return expect(result).to.eventually.have.property("faces")
  })

  it('Should return an array of faces by image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.analyzeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/octet-stream", "body": data, "visual-features": "Faces", "request-origin": "eastus2"})

      return expect(result).to.eventually.have.property("faces")
    })

  })

})

describe('#describeImage()', () => {
  it('Should return a description of image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.describeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/json", "url": imageUrl, "max-candidates": "2", "request-origin": "eastus2"})

    return expect(result).to.eventually.have.property("description")
  })

  it('Should return a description of image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.describeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/octet-stream", "body": data, "max-candidates": "2", "request-origin": "eastus2"})

      return expect(result).to.eventually.have.property("description")
    })

  })

})

describe('#imageThumbnail()', () => {
  it('Should write the thumbnail of image URI to /tests/image/thumbnail.jpg', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.imageThumbnail({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "application/json",
      "url": imageUrl,
      "width": "100",
      "height": "100",
      "smart-cropping": true,
      "request-origin": "eastus2"
    })
    return expect(result).to.not.eventually.have.property("code")

  })

  it('Should write the thumbnail of image binary to /tests/image/thumbnail.jpg', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.imageThumbnail({
        "Ocp-Apim-Subscription-Key": myKey,
        "content-type": "application/octet-stream",
        "body": data,
        "width": "100",
        "height": "100",
        "smart-cropping": true,
        "request-origin": "eastus2"
      })

      return expect(result).to.not.eventually.have.property("code")
    })
  })
})

describe('#orcImage()', () => {
  it('Should return the Optical Character Recognition of image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.orcImage({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "application/json",
      "url": "http://cdn.quotesgram.com/img/81/49/660235022-Random-Funny-Quotes-.jpg",
      "language": "en",
      "detect-orientation": true,
      "request-origin": "eastus2"
    })
    return expect(result).to.eventually.have.property("regions")

  })

  it('Should return the Optical Character Recognition of image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/tests/image/orcTest.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.orcImage({
        "Ocp-Apim-Subscription-Key": myKey,
        "content-type": "application/octet-stream",
        "body": data,
        "language": "en",
        "detect-orientation": true,
        "request-origin": "eastus2"
      })

      return expect(result).to.eventually.have.property("regions")<commit_msg>Fix file path cause test failure<commit_after>const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const fs = require('fs');

import microsofComputerVision from 'index'

chai.use(chaiAsPromised)
chai.use(require('chai-fs'))
const expect = chai.expect
const assert = chai.assert
const myKey = "<KEY>"

describe('#tagImage()', () => {
  it('Should return an array of tags by image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"
    const contentType = "application/json"

    const result = microsofComputerVision.tagImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": contentType, "url": imageUrl, "request-origin": "eastus2"})

    return expect(result).to.eventually.have.property("tags")
  })

  it('Should return an array of tags by image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.tagImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": contentType, "url": data, "request-origin": "eastus2"})

      return expect(result).to.eventually.have.property("tags")
    })

  })

})

describe('#analyzeImage()', () => {
  it('Should return an array of faces by image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.analyzeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/json", "url": imageUrl, "visual-features": "faces", "request-origin": "eastus2"})

    return expect(result).to.eventually.have.property("faces")
  })

  it('Should return an array of faces by image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.analyzeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/octet-stream", "body": data, "visual-features": "Faces", "request-origin": "eastus2"})

      return expect(result).to.eventually.have.property("faces")
    })

  })

})

describe('#describeImage()', () => {
  it('Should return a description of image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.describeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/json", "url": imageUrl, "max-candidates": "2", "request-origin": "eastus2"})

    return expect(result).to.eventually.have.property("description")
  })

  it('Should return a description of image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.describeImage({"Ocp-Apim-Subscription-Key": myKey, "content-type": "application/octet-stream", "body": data, "max-candidates": "2", "request-origin": "eastus2"})

      return expect(result).to.eventually.have.property("description")
    })

  })

})

describe('#imageThumbnail()', () => {
  it('Should write the thumbnail of image URI to image/thumbnail.jpg', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.imageThumbnail({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "application/json",
      "url": imageUrl,
      "width": "100",
      "height": "100",
      "smart-cropping": true,
      "request-origin": "eastus2"
    })
    return expect(result).to.not.eventually.have.property("code")

  })

  it('Should write the thumbnail of image binary to image/thumbnail.jpg', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('/image/test.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.imageThumbnail({
        "Ocp-Apim-Subscription-Key": myKey,
        "content-type": "application/octet-stream",
        "body": data,
        "width": "100",
        "height": "100",
        "smart-cropping": true,
        "request-origin": "eastus2"
      })

      return expect(result).to.not.eventually.have.property("code")
    })
  })
})

describe('#orcImage()', () => {
  it('Should return the Optical Character Recognition of image URI', function() {

    const imageUrl = "https://azurecomcdn.azureedge.net/cvt-ada4056a687a0f024d478b2eba03524ad163dd9a6c0853326a5a71276dc4d3c6/images/shared/cognitive-services-demos/analyze-image/analyze-3-thumbnail.jpg"

    const result = microsofComputerVision.orcImage({
      "Ocp-Apim-Subscription-Key": myKey,
      "content-type": "application/json",
      "url": "http://cdn.quotesgram.com/img/81/49/660235022-Random-Funny-Quotes-.jpg",
      "language": "en",
      "detect-orientation": true,
      "request-origin": "eastus2"
    })
    return expect(result).to.eventually.have.property("regions")

  })

  it('Should return the Optical Character Recognition of image binary', function() {

    const fs = require('fs')
    const contentType = "application/octet-stream"
    return fs.readFile('image/orcTest.jpg', function(err, data) {
      if (err) {
        throw err
      }

      const result = microsofComputerVision.orcImage({
        "Ocp-Apim-Subscription-Key": myKey,
        "content-type": "application/octet-stream",
        "body": data,
        "language": "en",
        "detect-orientation": true,
        "request-origin": "eastus2"
      })

      return expect(result).to.eventually.have.property("regions")
{'fraction_non_alphanumeric': 0.15164385716532955, 'fraction_numerical': 0.03885480572597137, 'mean_word_length': 3.845655487804878, 'pattern_counts': {'":': 108, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4849332', 'n_tokens_mistral': 4560, 'n_tokens_neox': 4159, 'n_words': 734}