/* global describe before context it */
const chai = require('chai');
const dirtyChai = require('dirty-chai');
const functionHelper = require('../../src/functionHelper');

const expect = chai.expect;
chai.use(dirtyChai);

describe('functionHelper', () => {
  describe('#getFunctionOptions', () => {

    const funName = 'testFunction';
    const servicePath = 'src';

    let result;
    before(() => {
      const fun = {
        handler: 'handler.hello',
      };
      result = functionHelper.getFunctionOptions(fun, funName, servicePath);
    });

    it('should have the correct funName', () => {
      expect(result.funName).to.eq(funName);
    });

    it('should have the correct handler name', () => {
      expect(result.handlerName).to.eq('hello');
    });

    it('should have the correct handler path', () => {
      expect(result.handlerPath).to.eq('src/handler');
    });

    it('should have the default timeout', () => {
      expect(result.funTimeout).to.eql(30000);
    });

    it('should have babelOptions undefined', () => {
      expect(result.babelOptions).to.be.undefined();
    });

    it('nested folders for handlers', () => {
      const fun = {
        handler: './somefolder/.handlers/handler.run',
      };
      const result = functionHelper.getFunctionOptions(fun, funName, servicePath);
      expect(result.handlerName).to.eq('run');
      expect(result.handlerPath).to.eq('src/somefolder/.handlers/handler');
    });

    context('with a timeout', () => {
      before(() => {
        const fun = {
          handler: 'handler.hello',
          timeout: 7,
        };
        result = functionHelper.getFunctionOptions(fun, funName, servicePath);
      });

      it('should have the correct timeout', () => {
        expect(result.funTimeout).to.eql(7000);
      });
    });
  });
});

@@ -100,24 +100,54 @@
 rty-chai');%0A
+const path = require('path');%0A
 const functi
@@ -886,21 +886,34 @@
 ).to.eq(
-'src/
+path.join('src', '
 handler'
@@ -905,32 +905,33 @@
 src', 'handler')
+)
 ;%0A    %7D);%0A%0A    i
@@ -1449,13 +1449,26 @@
 .eq(
-'src/
+path.join('src', '
 some
@@ -1465,33 +1465,36 @@
 rc', 'somefolder
-/
+', '
 .handlers/handle
@@ -1482,25 +1482,28 @@
 , '.handlers
-/
+', '
 handler');%0A 
@@ -1499,16 +1499,17 @@
 andler')
+)
 ;%0A    %7D)

Update string path use node path lib