Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it ('should resolve if authentication has been performed', function() {
var subscribeSpy = sinon.spy();
var host = {
_getFayeClient: sinon.stub().returns({
subscribe: subscribeSpy
}),
_getAuth: sinon.stub().returns({
isAuthenticated: sinon.stub().returns(Promise.resolve())
})
};
var options = {
timestamp: 1435054283,
expires_in: 21600,
channel: "/conversation/2256621",
signature: "7d2018df16bd7686063483c8960124bc0a1bb0e2"
};
var handler = new Function();
var subscription = pushLib.push.call(host, options).subscribe(handler);
subscription.then(function() {
// Assert that the Faye client is properly subscribed to
_callbacks.forEach((callback, i) => {
// Callback can return an obj, to resolve, or a promise, to chain.
// See waitFor() for why this might be useful.
Promise.resolve(callback(payload)).then(() => {
resolves[i](payload);
}, () => {
rejects[i](new Error('Dispatcher callback unsuccessful'));
});
});
},
if (jsonStats.errors.length > 0)
{
console.error('stats error', jsonStats.errors);
reject(err);
return;
}
if (jsonStats.warnings.length > 0)
{
console.warn('warn', jsonStats.warnings);
}
console.log('log', stats.toString());
resolve();
});
});
});
}, Promise.resolve());
function asyncApplyChange(change, file) {
const { editor } = change
return Promise.resolve(insertImage(change, file)).then(() => {
editor.onChange(change)
})
}
const promiseCreators = action[CHAIN_API].map((createCallApiAction) => {
return createRequestPromise({
timeout,
generateDefaultParams,
createCallApiAction,
getState,
dispatch,
errorInterceptor,
extractParams,
maxReplayTimes
})
})
const overall = promiseCreators.reduce((promise, createReqPromise) => {
return promise.then(createReqPromise)
}, Promise.resolve())
overall.finally(resolve).catch(reject)
})
}
function cmdArrived (cmd) {
if (wd.state !== STATES.RUNNING) return
logger.log('command received', JSON.stringify(cmd))
var handler = wd.handlers[cmd.name]
Promise.resolve(handler)
.then(function notFound (handler) {
if (handler) return handler
throw new UnknownCommand()
})
.then(function exec (handler) {
logger.log('applying endpoint handler...')
return handler.apply(cmd, cmd.args)
})
.then(function (result) {
logger.log(string.fromCmd(cmd).summary(), 'handler returned:', string(result).summary())
if (handler.halt) {
logger.log('halt set, skip sending...')
stop()
return
}
send('result/', cmd, result, handler.done)