'use strict';
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');

chai.should();
chai.use(chaiAsPromised);

const uut = require('../../lib/filters/geocode');

describe('geocode', function() {
  this.timeout(10000);
  it('address in Paris', () => {
    let res = uut(
      {
        source: {
          provider: 'google',
          apiKey: process.env.GOOGLE_API_SERVER_KEY,
          address: '#{a}'
        },
        target: 'b'
      },
      {a: '29 champs elysée paris'}
    );

    return Promise.all([
      res.should.eventually.have
      .property('a', '29 champs elysée paris'),

      res.should.eventually.have
      .property('b')
      .include({
        'latitude': 48.869384,
        'longitude': 2.3071868
      })
    ]);
  });

  it('unable to geocode', () => {
    let res = uut(
      {
        source: {
          provider: 'google',
          apiKey: process.env.GOOGLE_API_SERVER_KEY,
          address: '#{a}'
        },
        target: 'b'
      },
      {a: 'gibberish'}
    );

    return Promise.all([
      res.should.eventually.deep
      .equal({
        a: 'gibberish',
        b: {
          error: 'Failed to geocode: \"gibberish\"'
        }
      })
    ]);
  });
});

@@ -1013,25 +1013,54 @@
    %7Ba: '
-gibberish
+some-kind-of-place-that-does-not-exist
 '%7D%0A    )
@@ -1147,25 +1147,54 @@
     a: '
-gibberish
+some-kind-of-place-that-does-not-exist
 ',%0A     
@@ -1244,17 +1244,46 @@
 : %5C%22
-gibberish
+some-kind-of-place-that-does-not-exist
 %5C%22'%0A

change input for failing geocode test since place we were hoping didn't exist, now does!