/* eslint no-undef: "off" */

const SRC = '../src';
const Beans = require('qnode-beans');
const ApiServer = require(`${SRC}/ApiServer`);

function buildApiServer(mockMethod, mockExecute, mockDescription, mockPath) {
    const beans = new Beans();

    if (mockMethod || mockExecute) {
        beans.create = function() {
            return {
                _module: {
                    method: mockMethod,
                    description: mockDescription,
                    path: mockPath
                },
                execute: mockExecute
            };
        };
    }

    const r = new ApiServer({ rootDir: 'src/api' });
    beans.render(r);
    r.init();
    return r;
}

describe("ApiServer test suite 1: ", function() {

    it("_loadAllApi(): raise error when duplicated path", function() {
        try {
            const s = buildApiServer('get', () => {}, '', '/where');
            const apiFileList = ['dup'];
            s._loadAllApi(apiFileList);
            //failhere();
        } catch (e) {
            expect(e.message.indexOf('duplicated path') >= 0).toBeTruthy();
        }
    });

    it("_loadAllApi(): raise error when duplicated bean", function() {
        try {
            const s = buildApiServer();
            const apiFileList = ['Where'];
            s._loadAllApi(apiFileList);
        } catch (e) {
            expect(e.message.indexOf('duplicated bean') >= 0).toBeTruthy();
        }
    });

    it("_loadApi(): raise error when API.execute function is not defined", function() {
        try {
            s = buildApiServer('post', null, 'desc');
            failhere();
        } catch (e) {
            expect(e.message.indexOf('execute() not defined') >= 0).toBeTruthy();
        }
    });

    it("_loadApi(): load an API", function() {
        const s = buildApiServer('get', () => {}, 'description');
        const mod = s._loadApi('beanName');

        expect(mod.instance).not.toBeNull();
        expect(mod.method).toBe('get');
        expect(mod.path).toBe('/beanname');
        expect(mod.description).toBe('description');
    });

    it("_loadApi(): method should be 'get' by default", function() {
        const s = buildApiServer(undefined, function() {}, 'description');
        const mod = s._loadApi('beanName');
        expect(mod.method).toBe('get');
    });

    it("_loadApi(): method should be lowercased", function() {
        const s = buildApiServer('POST', () => {}, 'description');
        const mod = s._loadApi('beanName');
        expect(mod.method).toBe('post');
    });

});
@@ -881,13 +881,18 @@
 , '/
-where
+duplicated
 ');%0A
@@ -925,19 +925,28 @@
 ist = %5B'
-dup
+api1', 'api2
 '%5D;%0A    
@@ -997,10 +997,8 @@
     
-//
 fail
@@ -1072,24 +1072,28 @@
 'duplicated 
+api 
 path') %3E= 0)

Add unit test that covers duplicated-path case