var rewire = require('rewire');
var chai   = require('chai');
var expect = chai.expect;

// setup promise
chai.use(require('chai-as-promised'));

var google = rewire('../src/tts/google');
describe('tts.google', function() {

  before(function () {
    // mock console.log
    google.__set__({
      console: {
        log: function () {}
      }
    });
  });

  it('Hello', function () {
    var word = 'Hello';
    return expect(google(word)).to.eventually.match(/q=hello/);
    return expect(google(word)).to.eventually.match(/textlen=5/);
  });

  it('hello', function () {
    var word = 'hello';
    return expect(google(word)).to.eventually.match(/q=hello/);
    return expect(google(word)).to.eventually.match(/textlen=5/);
  });

  it('hello world', function () {
    var word = 'hello world';
    return expect(google(word)).to.eventually.match(/q=hello%20world/);
    return expect(google(word)).to.eventually.match(/textlen=11/);
  });

  it('Hello_World', function () {
    var word = 'Hello_World';
    return expect(google(word)).to.eventually.match(/q=hello%20world/);
    return expect(google(word)).to.eventually.match(/textlen=11/);
  });

  it('how_are_you', function () {
    var word = 'how_are_you';
    return expect(google(word)).to.eventually.match(/q=how%20are%20you/);
    return expect(google(word)).to.eventually.match(/textlen=11/);
  });

  it('123', function () {
    var word = '123';
    return expect(google(word)).to.eventually.match(/q=123/);
    return expect(google(word)).to.eventually.match(/textlen=3/);
  });

  it('(null)', function () {
    var word = null;
    return expect(google(word)).to.eventually.be.rejectedWith(TypeError);
  });

  it('123 (number)', function () {
    var word = 123;
    return expect(google(word)).to.eventually.be.rejectedWith(TypeError);
  });

  it('(Empty String)', function () {
    var word = '';
    return expect(google(word)).to.eventually.be.rejectedWith(TypeError);
  });

});

@@ -1,12 +1,48 @@
+var fetch  = require('node-fetch');%0A
 var rewire =
@@ -175,16 +175,36 @@
 ed'));%0A%0A
+// mock console.log%0A
 var goog
@@ -241,96 +241,8 @@
 ');%0A
-describe('tts.google', function() %7B%0A%0A  before(function () %7B%0A    // mock console.log%0A    
 goog
@@ -254,20 +254,16 @@
 set__(%7B%0A
-    
   consol
@@ -267,20 +267,16 @@
 sole: %7B%0A
-    
     log:
@@ -297,83 +297,49 @@
 %7D%0A  
-    %7D%0A    %7D);%0A  %7D);%0A%0A  it('Hello', function () %7B%0A    var word = 'Hello';%0A  
+%7D%0A%7D);%0A%0Afunction checkHttpStatus (word) %7B%0A
   re
@@ -342,32 +342,37 @@
   return expect(
+%0A    
 google(word)).to
@@ -371,121 +371,185 @@
 ord)
-).to.eventually.match(/q=hello/);%0A    return expect(google(word)).to.eventually.match(/textlen=5/);%0A  %7D);
+%0A      .then(function (url) %7B return fetch(url) %7D)%0A      .then(function (res) %7B return res.status %7D)%0A  ).to.eventually.equal(200);%0A%7D%0A%0Adescribe('tts.google', function() %7B
 %0A%0A  it('
 hell
@@ -540,25 +540,25 @@
 () %7B%0A%0A  it('
-h
+H
 ello', funct
@@ -578,25 +578,25 @@
 var word = '
-h
+H
 ello';%0A    r
@@ -605,59 +605,88 @@
 urn 
-expect(google(word)).to.eventually.match(/q=
+checkHttpStatus(word);%0A  %7D);%0A%0A  it('hello', function () %7B%0A    var word = '
 hello
-/)
+'
 ;%0A  
@@ -698,60 +698,28 @@
 urn 
-expect(google(word)).to.eventually.match(/textlen=5/
+checkHttpStatus(word
 );%0A 
@@ -803,738 +803,327 @@
 urn 
-expect(google(word)).to.eventually.match(/q=hello%2520world/);%0A    return expect(google(word)).to.eventually.match(/textlen=11/);%0A  %7D);%0A%0A  it('Hello_World', function () %7B%0A    var word = 'Hello_World';%0A    return expect(google(word)).to.eventually.match(/q=hello%2520world/);%0A    return expect(google(word)).to.eventually.match(/textlen=11/);%0A  %7D);%0A%0A  it('how_are_you', function () %7B%0A    var word = 'how_are_you';%0A    return expect(google(word)).to.eventually.match(/q=how%2520are%2520you/);%0A    return expect(google(word)).to.eventually.match(/textlen=11/);%0A  %7D);%0A%0A  it('123', function () %7B%0A    var word = '123';%0A    return expect(google(word)).to.eventually.match(/q=123/);%0A    return expect(google(word)).to.eventually.match(/textlen=3/
+checkHttpStatus(word);%0A  %7D);%0A%0A  it('Hello_World', function () %7B%0A    var word = 'Hello_World';%0A    return checkHttpStatus(word);%0A  %7D);%0A%0A  it('how_are_you', function () %7B%0A    var word = 'how_are_you';%0A    return checkHttpStatus(word);%0A  %7D);%0A%0A  it('123', function () %7B%0A    var word = '123';%0A    return checkHttpStatus(word
 );%0A 

update tts.google by checking http status