Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ module.exports = function(impl, info, options, logger, proxy) {
({info, options, logger} = defaults(info, options, logger));
let callApi = impl(info, options, logger);
proxy = proxy || {};
for (let i=0; i<info.api[options.version].length; i++) {
let methodName = camelCase(info.api[options.version][i]);
proxy[methodName] = (...args) => callApi(methodName, args);
if (info instanceof Object && 'api' in info && options.version in info.api) {
for (let i = 0; i < info.api[options.version].length; i++) {
let methodName = camelCase(info.api[options.version][i]);
proxy[methodName] = (...args) => callApi(methodName, args);
}
}

return proxy;
Expand Down
13 changes: 11 additions & 2 deletions test/async_test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const {async:coroutine} = require("merapi");
const asyncProxy = require("../async");

describe("Proxy Async Test", function() {

this.timeout(5000);

let container, proxy;
let lazyContainer, lazyProxy;
let lazyContainer, lazyProxy, unresolvedProxy;

before(coroutine(function* () {
container = merapi({
Expand Down Expand Up @@ -101,12 +103,19 @@ describe("Proxy Async Test", function() {
return new Promise(resolve => setTimeout(resolve, ms));
};
yield lazyContainer.start();
yield sleep(1500);
yield sleep(2500);
assert.equal(lazyProxy.isReady(), true);
let res = yield lazyProxy.get(10);
assert.deepEqual(res, 10);
}));

it("should create proxy when version is not defined", coroutine(function* () {
unresolvedProxy = yield asyncProxy("http://localhost:5010", {version: "5.0.0"}, console);
assert.notEqual(unresolvedProxy, null);
}));

it("should not have any function", coroutine(function*() {
assert.deepEqual(Object.keys(unresolvedProxy), []);
}));

});