How to use callCallback method in sinon

Best JavaScript code snippet using sinon

core.js

Source:core.js Github

copy

Full Screen

...233 * @param callbackName String callback which should be called234 * @param element some arguments to the callback235 * @param eventData236 */237 function callCallback( callbackName, element, eventData ) {238 eventData.settings = settings;239 eventData.current = current;240 eventData.container = container;241 eventData.parents = element ? getStepParents(element) : null;242 eventData.current = current;243 eventData.jmpress = this;244 var result = {};245 $.each( settings[callbackName], function(idx, callback) {246 result.value = callback.call( jmpress, element, eventData ) || result.value;247 });248 return result.value;249 }250 /**251 *...

Full Screen

Full Screen

websocket.js

Source:websocket.js Github

copy

Full Screen

...97 $('table.username-password', loginBox).show();98 $('table.twofactor', loginBox).hide();99 Structr.refreshUi((command === 'LOGIN'));100 }101 StructrModel.callCallback(data.callback, data.data[data.data['key']]);102 } else if (command === 'GET_LOCAL_STORAGE') {103 if (data.data.localStorageString && data.data.localStorageString.length) {104 LSWrapper.setAsJSON(data.data.localStorageString);105 }106 StructrModel.callCallback(data.callback, data.data);107 } else if (command === 'CONSOLE') {108 StructrModel.callCallback(data.callback, data);109 } else if (command === 'STATUS') {110 if (code === 403) {111 StructrWS.user = null;112 StructrWS.userId = null;113 if (data.data.reason === 'sessionLimitExceeded') {114 Structr.login('Max. number of sessions exceeded.');115 } else {116 Structr.login('Wrong username or password!');117 }118 } else if (code === 401) {119 StructrWS.user = null;120 StructrWS.userId = null;121 if (data.data.reason === 'twofactortoken') {122 Structr.clearLoginForm();123 $('table.username-password', loginBox).show();124 $('table.twofactor', loginBox).hide();125 }126 Structr.login((msg !== null) ? msg : '');127 } else if (code === 202) {128 StructrWS.user = null;129 StructrWS.userId = null;130 Structr.login('');131 Structr.toggle2FALoginBox(data.data);132 } else {133 let codeStr = code ? code.toString() : '';134 if (codeStr === '422') {135 try {136 StructrModel.callCallback(data.callback, null, null, true);137 } catch (e) {}138 }139 let msgClass;140 let requiresConfirmation = false;141 if (codeStr.startsWith('2')) {142 msgClass = 'success';143 } else if (codeStr.startsWith('3')) {144 msgClass = 'info';145 } else if (codeStr.startsWith('4')) {146 msgClass = 'warning';147 requiresConfirmation = true;148 } else {149 msgClass = 'error';150 requiresConfirmation = true;151 }152 if (data.data.requiresConfirmation) {153 requiresConfirmation = data.data.requiresConfirmation;154 }155 if (msg && msg.startsWith('{')) {156 let msgObj = JSON.parse(msg);157 if (dialogBox.is(':visible')) {158 Structr.showAndHideInfoBoxMessage(msgObj.size + ' bytes saved to ' + msgObj.name, msgClass, 2000, 200);159 } else {160 let node = Structr.node(msgObj.id);161 if (node) {162 let progr = node.find('.progress');163 progr.show();164 let size = parseInt(node.find('.size').text());165 let part = msgObj.size;166 node.find('.part').text(part);167 let pw = node.find('.progress').width();168 let w = pw / size * part;169 node.find('.bar').css({width: w + 'px'});170 if (part >= size) {171 blinkGreen(progr);172 window.setTimeout(function () {173 progr.fadeOut('fast');174 _Files.resize();175 }, 1000);176 }177 }178 }179 } else {180 if (codeStr === "404") {181 let msgBuilder = new MessageBuilder().className(msgClass);182 if (requiresConfirmation) {183 msgBuilder.requiresConfirmation();184 }185 if (data.message) {186 msgBuilder.title('Object not found.').text(data.message);187 } else {188 msgBuilder.text('Object not found.');189 }190 msgBuilder.show();191 } else if (data.error && data.error.errors) {192 Structr.errorFromResponse(data.error, null, { requiresConfirmation: true });193 } else {194 let msgBuilder = new MessageBuilder().className(msgClass).text(msg);195 if (requiresConfirmation) {196 msgBuilder.requiresConfirmation();197 }198 msgBuilder.show();199 }200 }201 }202 } else if (command === 'GET_PROPERTY') {203 StructrModel.updateKey(data.id, data.data['key'], data.data[data.data['key']]);204 StructrModel.callCallback(data.callback, data.data[data.data['key']]);205 } else if (command === 'UPDATE' || command === 'SET_PERMISSION') {206 let modelObj = StructrModel.obj(data.id);207 if (!modelObj) {208 data.data.id = data.id;209 modelObj = StructrModel.create(data.data, null, false);210 } else {211 if (modelObj.updatedModel && (typeof modelObj.updatedModel === 'function')) {212 for (let [key, value] of Object.entries(data.data)) {213 modelObj[key] = value;214 }215 modelObj.updatedModel();216 }217 }218 StructrModel.update(data);219 } else if (command === 'GET' || command === 'GET_RELATIONSHIP' || command === 'GET_PROPERTIES') {220 StructrModel.callCallback(data.callback, result[0]);221 } else if (command.startsWith('GET') || command === 'GET_BY_TYPE' || command === 'GET_SCHEMA_INFO' || command === 'CREATE_RELATIONSHIP') {222 StructrModel.callCallback(data.callback, result);223 } else if (command === 'CHILDREN') {224 if (result.length > 0 && result[0].name) {225 result.sort(function (a, b) {226 return a.name.localeCompare(b.name);227 });228 }229 let refObject = StructrModel.obj(data.id);230 if (refObject && refObject.constructor.name === 'StructrGroup') {231 // let security handle this232 } else {233 for (let entity of result) {234 StructrModel.create(entity);235 }236 }237 StructrModel.callCallback(data.callback, result);238 } else if (command.endsWith('CHILDREN')) {239 for (let entity of result) {240 StructrModel.create(entity);241 }242 StructrModel.callCallback(data.callback, result);243 } else if (command.startsWith('SEARCH')) {244 if (type) {245 $('.pageCount', $('.pager' + type)).val(_Pager.pageCount[type]);246 }247 StructrModel.callCallback(data.callback, result, data.rawResultCount);248 } else if (command.startsWith('LIST_UNATTACHED_NODES')) {249 StructrModel.callCallback(data.callback, result);250 } else if (command.startsWith('LIST_SCHEMA_PROPERTIES')) {251 // send full result in a single callback252 StructrModel.callCallback(data.callback, result);253 } else if (command.startsWith('LIST_COMPONENTS')) {254 StructrModel.callCallback(data.callback, result);255 } else if (command.startsWith('LIST_SYNCABLES')) {256 StructrModel.callCallback(data.callback, result);257 } else if (command.startsWith('LIST_ACTIVE_ELEMENTS')) {258 StructrModel.callCallback(data.callback, result);259 } else if (command.startsWith('LIST_LOCALIZATIONS')) {260 StructrModel.callCallback(data.callback, result);261 } else if (command.startsWith('SNAPSHOTS')) {262 StructrModel.callCallback(data.callback, result);263 } else if (command.startsWith('LIST')) {264 StructrModel.callCallback(data.callback, result, data.rawResultCount);265 } else if (command.startsWith('QUERY')) {266 StructrModel.callCallback(data.callback, result, data.rawResultCount);267 } else if (command.startsWith('CLONE') || command === 'REPLACE_TEMPLATE') {268 StructrModel.callCallback(data.callback, result, data.rawResultCount);269 } else if (command === 'DELETE') {270 StructrModel.del(data.id);271 StructrModel.callCallback(data.callback, [], 0);272 } else if (command === 'INSERT_BEFORE' || command === 'APPEND_CHILD' || command === 'APPEND_MEMBER') {273 StructrModel.create(result[0], data.data.refId);274 StructrModel.callCallback(data.callback, result[0]);275 } else if (command.startsWith('APPEND_FILE')) {276 //StructrModel.create(result[0], data.data.refId);277 } else if (command === 'REMOVE') {278 let obj = StructrModel.obj(data.id);279 if (obj) {280 obj.remove();281 }282 StructrModel.callCallback(data.callback);283 } else if (command === 'REMOVE_CHILD') {284 let obj = StructrModel.obj(data.id);285 if (obj) {286 obj.remove(data.data.parentId);287 }288 StructrModel.callCallback(data.callback);289 } else if (command === 'CREATE' || command === 'ADD' || command === 'IMPORT') {290 for (let entity of result) {291 if (command === 'CREATE' && (entity.isPage || entity.isFolder || entity.isFile || entity.isImage || entity.isVideo || entity.isUser || entity.isGroup || entity.isWidget || entity.isResourceAccess)) {292 StructrModel.create(entity);293 } else {294 if (!entity.parent && _Pages.shadowPage && entity.pageId === _Pages.shadowPage.id) {295 entity = StructrModel.create(entity, null, false);296 let el = (entity.isContent || entity.type === 'Template') ? _Elements.appendContentElement(entity, _Pages.components, true) : _Pages.appendElementElement(entity, _Pages.components, true);297 if (Structr.isExpanded(entity.id)) {298 _Entities.ensureExpanded(el);299 }300 let synced = entity.syncedNodesIds;301 if (synced && synced.length) {302 // Change icon303 for (let syncedId of synced) {304 let syncedEl = Structr.node(syncedId);305 if (syncedEl && syncedEl.length) {306 let icon = entity.isContent ? _Elements.getContentIcon(entity) : _Elements.getElementIcon(entity);307 syncedEl.children('.typeIcon').attr('class', 'typeIcon ' + _Icons.getFullSpriteClass(icon));308 _Entities.removeExpandIcon(syncedEl);309 }310 }311 }312 }313 }314 if (command === 'CREATE' && entity.isPage && Structr.lastMenuEntry === _Pages._moduleName) {315 if (entity.createdBy === StructrWS.userId) {316 setTimeout(function () {317 _Pages.previews.showPreviewInIframeIfVisible(entity.id);318 }, 1000);319 }320 } else if (entity.pageId) {321 if (entity.id) {322 _Pages.previews.showPreviewInIframeIfVisible(entity.pageId, entity.id);323 } else {324 _Pages.previews.showPreviewInIframeIfVisible(entity.pageId);325 }326 }327 StructrModel.callCallback(data.callback, entity);328 }329 } else if (command === 'PROGRESS') {330 if (dialogMsg.is(':visible')) {331 let msgObj = JSON.parse(data.message);332 dialogMsg.html('<div class="infoBox info">' + msgObj.message + '</div>');333 }334 } else if (command === 'FINISHED') {335 StructrModel.callCallback(data.callback, data.data);336 } else if (command === 'AUTOCOMPLETE') {337 StructrModel.callCallback(data.callback, result);338 } else if (command === 'FIND_DUPLICATES') {339 StructrModel.callCallback(data.callback, result);340 } else if (command === 'SCHEMA_COMPILED') {341 _Schema.processSchemaRecompileNotification();342 } else if (command === 'GENERIC_MESSAGE') {343 Structr.handleGenericMessage(data.data);344 } else if (command === 'FILE_IMPORT') {345 StructrModel.callCallback(data.callback, result);346 } else if (command === 'GET_SUGGESTIONS') {347 StructrModel.callCallback(data.callback, result);348 } else if (command === 'SERVER_LOG') {349 StructrModel.callCallback(data.callback, result);350 } else if (command === 'SAVE_LOCAL_STORAGE') {351 StructrModel.callCallback(data.callback, result);352 } else if (command === 'APPEND_WIDGET') {353 StructrModel.callCallback(data.callback, result);354 } else {355 console.log('Received unknown command: ' + command);356 if (sessionValid === false) {357 StructrWS.user = null;358 StructrWS.userId = null;359 clearMain();360 Structr.login();361 }362 }363 };364 } catch (exception) {365 if (StructrWS.ws) {366 StructrWS.ws.close();367 StructrWS.ws.length = 0;...

Full Screen

Full Screen

graphCompiler.js

Source:graphCompiler.js Github

copy

Full Screen

...38import getJsCode from './graphOutputs/getJsCode'39import getInteractionMetrics from './graphOutputs/getInteractionMetrics'40export function compile(ast, header, callbacks) {41 // A function to properly call each callback correctly42 function callCallback(element, data) {43 graph.clean(); // Also it cleans the graph44 if (_.isUndefined(callbacks[element]))  {45 return true; // No callback for this stage ? We continue compiling;46 } else {47 let ret = callbacks[element](graph, (_.isObject(data)) ? (_.assign({48 stage: element49 }, data)) : (_.isUndefined(data) ? {50 stage: element51 } : data));52 if (_.isBoolean(ret)) {53 return ret;54 } else {55 throw new Error('Compilation stage callbacks should return a boolean (true to continue compilation, false to stop it), the callback for ' + element + ' returned ' + ret);56 }57 }58 }59 // We add the ad hoc callbacks to the callback stack60 var newCallbacks = _.assign(61 _.clone(callbacks), {62 instantiateInterfaces: (graph, data) => {63 callCallback('getExpandedLidlCode', getExpandedLidl(graph, rootDefinitionNode));64 return callCallback('instantiateInterfaces', data);65 },66 referentialTransparencyInstances: (graph, data) => {67 callCallback('getInteractionMetrics', getInteractionMetrics(graph));68 return callCallback('referentialTransparencyInstances', data);69 },70 orderGraph: (graph, data) => {71 callCallback('getJsCode', getJsCode(graph, header));72 return callCallback('orderGraph', data);73 }74 }75 );76 // Create a graph77 let graph = new Graph();78 // Add the AST to it79 let rootDefinitionNode =80 addDefinitionToGraph(graph, ast);81 // Apply transformations to it82 graphTransformationPipeline(graph, rootDefinitionNode, newCallbacks);83 return graph;84}85export function graphTransformationPipeline(graph, rootDefinitionNode, callbacks) {86 var step = 0;87 var callBackIterationCounter = {};88 // A function to properly call each callback correctly89 function callCallback(element, data) {90 graph.clean(); // Also it cleans the graph91 step = step + 1;92 if (callBackIterationCounter[element] === undefined) callBackIterationCounter[element] = 0;93 callBackIterationCounter[element] = callBackIterationCounter[element] + 1;94 if (_.isUndefined(callbacks[element]))  {95 return true; // No callback for this stage ? We continue compiling;96 } else {97 // try {98 let additionalInfo = {99 stage: element,100 step: step,101 iteration: callBackIterationCounter[element]102 };103 let ret = callbacks[element](graph, (_.isObject(data)) ? (_.assign(additionalInfo, data)) : (_.isUndefined(data) ? additionalInfo : data));104 if (_.isBoolean(ret)) {105 return ret;106 } else {107 throw new Error('Compilation stage callbacks should return a boolean (true to continue compilation, false to stop it), the callback for ' + element + ' returned ' + ret);108 }109 // } catch (e) {110 // return true;111 // }112 }113 }114 try {115 if (false === callCallback('addDefinitionToGraph')) return graph;116 //117 // linkInterfacesToDefinitions(graph);118 // if(false===callCallback('linkInterfacesToDefinitions')) return graph;119 //120 // expandInterfaces(graph);121 // if(false===callCallback('expandInterfaces')) return graph;122 addOperatorTypeAnnotation(graph);123 if (false === callCallback('addOperatorTypeAnnotation')) return graph;124 referentialTransparency(graph);125 if (false === callCallback('referentialTransparency')) return graph;126 linkInteractionsToDefinitions(graph);127 if (false === callCallback('linkInteractionsToDefinitions')) return graph;128 addInterfaceInformationToInteractions(graph);129 if (false === callCallback('addInterfaceInformationToInteractions')) return graph;130 expandDefinitions(graph);131 if (false === callCallback('expandDefinitions')) return graph;132 removeNonRootDefinitions(graph, rootDefinitionNode);133 if (false === callCallback('removeNonRootDefinitions')) return graph;134 clearSubInformation(graph);135 if (false === callCallback('clearSubInformation')) return graph;136 instantiateInterfaces(graph, rootDefinitionNode);137 if (false === callCallback('instantiateInterfaces')) return graph;138 linkArguments(graph, rootDefinitionNode);139 if (false === callCallback('linkArguments')) return graph;140 linkInterface(graph, rootDefinitionNode);141 if (false === callCallback('linkInterface')) return graph;142 keepOnlyInteractions(graph);143 if (false === callCallback('keepOnlyInteractions')) return graph;144 referentialTransparencyInstances(graph);145 if (false === callCallback('referentialTransparencyInstances')) return graph;146 createDataFlowDirection(graph);147 if (false === callCallback('createDataFlowDirection')) return graph;148 voidInteractionCreation(graph);149 if (false === callCallback('voidInteractionCreation')) return graph;150 behaviourSeparation(graph);151 if (false === callCallback('behaviourSeparation')) return graph;152 createDataFlowDirection(graph);153 if (false === callCallback('createDataFlowDirection')) return graph;154 functionLiteralLinking(graph);155 if (false === callCallback('functionLiteralLinking')) return graph;156 createDataFlowDirection(graph);157 if (false === callCallback('createDataFlowDirection')) return graph;158 dataLiteralLinking(graph);159 if (false === callCallback('dataLiteralLinking')) return graph;160 createDataFlowDirection(graph);161 if (false === callCallback('createDataFlowDirection')) return graph;162 functionApplicationLinking(graph);163 if (false === callCallback('functionApplicationLinking')) return graph;164 createDataFlowDirection(graph);165 if (false === callCallback('createDataFlowDirection')) return graph;166 previousNextLinking(graph);167 if (false === callCallback('previousNextLinking')) return graph;168 createDataFlowDirection(graph);169 if (false === callCallback('createDataFlowDirection')) return graph;170 tagCompositionElementEdges(graph);171 if (false === callCallback('tagCompositionElementEdges')) return graph;172 matchingCompositionReduction(graph);173 if (false === callCallback('matchingCompositionReduction')) return graph;174 createDataFlowDirection(graph);175 if (false === callCallback('createDataFlowDirection')) return graph;176 matchingCompositionReduction(graph);177 if (false === callCallback('matchingCompositionReduction')) return graph;178 createDataFlowDirection(graph);179 if (false === callCallback('createDataFlowDirection')) return graph;180 matchingCompositionReduction(graph);181 if (false === callCallback('matchingCompositionReduction')) return graph;182 createDataFlowDirection(graph);183 if (false === callCallback('createDataFlowDirection')) return graph;184 //TODO Should loop that, either in the method or here ... until fixed point185 linkIdentifiers(graph);186 if (false === callCallback('linkIdentifiers')) return graph;187 createDataFlowDirection(graph);188 if (false === callCallback('createDataFlowDirection')) return graph;189 matchingCompositionReduction(graph);190 if (false === callCallback('matchingCompositionReduction')) return graph;191 createDataFlowDirection(graph);192 if (false === callCallback('createDataFlowDirection')) return graph;193 matchingCompositionReduction(graph);194 if (false === callCallback('matchingCompositionReduction')) return graph;195 createDataFlowDirection(graph);196 if (false === callCallback('createDataFlowDirection')) return graph;197 matchingCompositionReduction(graph);198 if (false === callCallback('matchingCompositionReduction')) return graph;199 createDataFlowDirection(graph);200 if (false === callCallback('createDataFlowDirection')) return graph;201 //TODO Should loop that, either in the method or here ... until fixed point202 removeOneSidedAffectation(graph);203 if (false === callCallback('removeOneSidedAffectation')) return graph;204 createDataFlowDirection(graph);205 if (false === callCallback('createDataFlowDirection')) return graph;206 nonMatchingCompositionCompilation(graph);207 if (false === callCallback('nonMatchingCompositionCompilation')) return graph;208 affectationLinking(graph);209 if (false === callCallback('affectationLinking')) return graph;210 createDataFlowDirection(graph);211 if (false === callCallback('createDataFlowDirection')) return graph;212 nonMatchingCompositionCompilation(graph);213 if (false === callCallback('nonMatchingCompositionCompilation')) return graph;214 affectationLinking(graph);215 if (false === callCallback('affectationLinking')) return graph;216 createDataFlowDirection(graph);217 if (false === callCallback('createDataFlowDirection')) return graph;218 nonMatchingCompositionCompilation(graph);219 if (false === callCallback('nonMatchingCompositionCompilation')) return graph;220 affectationLinking(graph);221 if (false === callCallback('affectationLinking')) return graph;222 //TODO Should loop that too ... until fixed point ... but always end with another:223 createDataFlowDirection(graph);224 if (false === callCallback('createDataFlowDirection')) return graph;225 removeDuplicateEdge(graph);226 if (false === callCallback('removeDuplicateEdge')) return graph;227 resolveMultiplePorts(graph);228 if (false === callCallback('resolveMultiplePorts')) return graph;229 createDataFlowDirection(graph);230 if (false === callCallback('createDataFlowDirection')) return graph;231 instantiateTemplates(graph);232 if (false === callCallback('instantiateTemplates')) return graph;233 orderGraph(graph);234 if (false === callCallback('orderGraph')) return graph;235 keepOnlyOrdering(graph);236 if (false === callCallback('keepOnlyOrdering')) return graph;237 if (false === callCallback('graphTransformationPipeline')) return graph;238 return graph;239 } catch (e) {240 callCallback('error', {241 error: e,242 iteration: 1243 });244 throw (e);245 }...

Full Screen

Full Screen

redis-driver.js

Source:redis-driver.js Github

copy

Full Screen

...38 this.getUsers(function (users) {39 this.users = users || []40 this.getRoles(function (roles) {41 this.roles = roles || []42 this.callCallback(callback, null)43 }.bind(this))44 }.bind(this))45}46RedisDriver.prototype.setPrefix = function ( prefix ) {47 this.options.prefix = prefix48}49RedisDriver.prototype.createUser = function (userId, roles, callback) {50 var client = this.generateClient()51 var keyName = this.getKeyName( 'users' )52 client.hset(keyName, userId, JSON.stringify(roles), function (err, value) {53 54 client.quit()55 this.users.push({56 id: userId,57 roles: roles58 })59 this.callCallback(callback, null)60 }.bind(this))61}62RedisDriver.prototype.removeUserById = function (userId, callback) {63 var client = this.generateClient()64 var index = this.getUserIndexById(userId)65 if (index > -1) {66 this.users.splice(index, 1)67 }68 var keyName = this.getKeyName( 'users' )69 client.hdel(keyName, userId, function (err, value) {70 71 keyName = this.getKeyName( 'rules_user_' + userId )72 client.del(keyName, function (err, value) {73 client.quit()74 this.callCallback(callback, null)75 }.bind(this))76 }.bind(this))77}78RedisDriver.prototype.getUserById = function (userId, callback) {79 this.getUserIndexById(userId, function (index) {80 if (index < 0) {81 this.callCallback(callback, null)82 return83 }84 this.callCallback(callback, this.users[index])85 }.bind(this))86}87RedisDriver.prototype.getUserIndexById = function (userId, callback) {88 for (var u=0; u<this.users.length; u++) {89 var user = this.users[u]90 if (user.id == userId) {91 this.callCallback(callback, u)92 return93 }94 }95 this.callCallback(callback, -1)96}97RedisDriver.prototype.getUsers = function (callback) {98 var client = this.generateClient()99 var keyName = this.getKeyName( 'users' )100 client.hgetall(keyName, function (err, users) {101 client.quit()102 if (err) {103 console.log(err)104 this.callCallback(callback, null)105 return106 }107 if (!users) {108 this.callCallback(callback, null)109 return110 }111 var results = []112 for (var user in users) {113 if (users.hasOwnProperty(user)) {114 results.push({115 id: user,116 roles: JSON.parse(users[user])117 })118 }119 }120 this.callCallback(callback, results)121 }.bind(this))122}123RedisDriver.prototype.createRole = function (role, callback) {124 var client = this.generateClient()125 var keyName = this.getKeyName( 'roles' )126 var data = {}127 if (role.inherits) {128 data.inherits = role.inherits129 }130 if (role.permissions) {131 data.permissions = role.permissions132 }133 client.hset(keyName, role.name, JSON.stringify(data), function (err, value) {134 135 client.quit()136 this.callCallback(callback, null)137 }.bind(this))138}139RedisDriver.prototype.setRoles = function (roles, callback) {140 141 this.removeAllRoles(function (err) {142 async.eachSeries(roles, function (role, cb) {143 this.createRole( role, function (err) {144 cb(null)145 })146 147 }.bind(this),148 function done () {149 this.roles = roles150 this.callCallback(callback, null)151 }.bind(this)152 )153 }.bind(this))154}155RedisDriver.prototype.removeRoleByName = function (name, callback) {156 var client = this.generateClient()157 var index = this.getRoleIndexByName(name)158 if (index > -1) {159 this.roles.splice(index, 1)160 }161 var keyName = ''162 async.series(163 [164 function (cb) {165 // Get all role rules166 keyName = this.getKeyName( 'rules_role_' + name )167 client.smembers(keyName, function (err, rules) {168 // Remove all role rules169 keyName = this.getKeyName( 'rules' )170 async.eachSeries(rules, function (rule, cb2) {171 // Remove role rule172 client.srem(keyName, rule, function (err, value) {173 cb2(null)174 })175 },176 function done () {177 cb(null)178 }179 )180 }.bind(this))181 }.bind(this),182 function (cb) {183 // Remove role184 keyName = this.getKeyName( 'roles' )185 client.hdel(keyName, name, function (err, value) {186 187 // Remove role rule index188 keyName = this.getKeyName( 'rules_role_' + name )189 client.del(keyName, function (err, value) {190 cb(null)191 })192 }.bind(this))193 }.bind(this)194 ],195 function (err, results) {196 client.quit()197 this.callCallback(callback, null)198 }.bind(this)199 )200}201RedisDriver.prototype.removeAllRoles = function (callback) {202 var client = this.generateClient()203 var keyName = this.getKeyName( 'roles' )204 client.del(keyName, function (err) {205 206 client.quit()207 this.callCallback(callback, null)208 }.bind(this))209}210RedisDriver.prototype.getRoles = function (callback) {211 var client = this.generateClient()212 var keyName = this.getKeyName( 'roles' )213 client.hgetall(keyName, function (err, roles) {214 client.quit()215 if (err) {216 console.log(err)217 this.callCallback(callback, null)218 return219 }220 if (!roles) {221 this.callCallback(callback, null)222 return223 }224 var results = []225 for (var role in roles) {226 if (roles.hasOwnProperty(role)) {227 var data = JSON.parse(roles[role])228 data.name = role229 results.push(data)230 }231 }232 this.callCallback(callback, results)233 }.bind(this))234}235RedisDriver.prototype.getRoleByName = function (name, callback) {236 this.getRoleIndexByName(name, function (index) {237 if (index < 0) {238 this.callCallback(callback, null)239 return240 }241 this.callCallback(callback, this.roles[index])242 }.bind(this)) 243}244RedisDriver.prototype.getRoleIndexByName = function (name, callback) {245 for (var r=0; r<this.roles.length; r++) {246 var role = this.roles[r]247 if (role.name == name) {248 this.callCallback(callback, r)249 return250 }251 }252 this.callCallback(callback, -1)253}254RedisDriver.prototype.getRolePermissions = function (name, callback) {255 this.getRoleByName(name, function (uRole) {256 if (!uRole) {257 this.callCallback(callback, [])258 return 259 }260 var permissions = uRole.permissions || []261 if (uRole.inherits) {262 var roles = uRole.inherits.split(' ')263 async.eachSeries(roles, function (role, cb) {264 this.getRolePermissions( roles, function (result) {265 if (!result) {266 cb(null)267 return268 }269 permissions = permissions.concat( result )270 cb(null)271 })272 273 }.bind(this),274 function done () {275 this.callCallback(callback, _.uniq( permissions ))276 }.bind(this)277 )278 }279 else {280 this.callCallback(callback, _.uniq( permissions ))281 }282 }.bind(this))283}284RedisDriver.prototype.getInheritRoleNames = function (name, callback) {285 this.getRoleByName(name, function (role) {286 if (!role) {287 this.callCallback(callback, [])288 return 289 }290 var names = [name]291 if (role.inherits) {292 var inherits = role.inherits.split(' ')293 async.eachSeries(inherits, function (inherit, cb) {294 this.getInheritRoleNames( inherit, function (result) {295 if (!result) {296 cb(null)297 return298 }299 names = names.concat( result )300 cb(null)301 })302 303 }.bind(this),304 function done () {305 this.callCallback(callback, _.uniq( names ))306 }.bind(this)307 )308 }309 else {310 this.callCallback(callback, names)311 }312 }.bind(this))313}314RedisDriver.prototype.getUserRoles = function (user, callback) {315 var roles = []316 var names = []317 async.series(318 [319 function (cb) {320 async.eachSeries(user.roles, function (role, cb2) {321 this.getInheritRoleNames( role, function (result) {322 names = names.concat( result )323 cb2(null)324 })325 326 }.bind(this),327 function done () {328 cb(null)329 }.bind(this)330 )331 }.bind(this),332 function (cb) {333 names = _.uniq( names )334 async.eachSeries(names, function (name, cb2) {335 this.getRoleByName(name, function (role) {336 roles.push( role )337 cb2(null)338 })339 }.bind(this),340 function done () {341 cb(null)342 }.bind(this)343 )344 }.bind(this)345 ],346 function (err, results) {347 this.callCallback(callback, roles)348 }.bind(this)349 )350}351RedisDriver.prototype.createUserRule = function (userId, rule, callback) {352 var client = this.generateClient()353 var keyName = this.getKeyName( 'rules' )354 client.sadd(keyName, rule, function (err, value) {355 356 keyName = this.getKeyName( 'rules_user_' + userId )357 client.sadd(keyName, rule, function (err, value) {358 client.quit()359 this.callCallback(callback, null)360 }.bind(this))361 }.bind(this))362}363RedisDriver.prototype.removeUserRule = function (userId, rule, callback) {364 var client = this.generateClient()365 366 var keyName = this.getKeyName( 'rules' )367 client.srem(keyName, rule, function (err, value) {368 369 keyName = this.getKeyName( 'rules_user_' + userId )370 client.srem(keyName, rule, function (err, value) {371 372 client.quit()373 this.callCallback(callback, null)374 }.bind(this))375 }.bind(this))376}377RedisDriver.prototype.createRoleRule = function (name, rule, callback) {378 var client = this.generateClient()379 var keyName = this.getKeyName( 'rules' )380 client.sadd(keyName, rule, function (err, value) {381 382 keyName = this.getKeyName( 'rules_role_' + name )383 client.sadd(keyName, rule, function (err, value) {384 client.quit()385 this.callCallback(callback, null)386 }.bind(this))387 }.bind(this))388}389RedisDriver.prototype.removeRoleRule = function (name, rule, callback) {390 var client = this.generateClient()391 392 var keyName = this.getKeyName( 'rules' )393 client.srem(keyName, rule, function (err, value) {394 395 keyName = this.getKeyName( 'rules_role_' + name )396 client.srem(keyName, rule, function (err, value) {397 398 client.quit()399 this.callCallback(callback, null)400 }.bind(this))401 }.bind(this))402}403RedisDriver.prototype.removeAllRules = function (callback) {404 var client = this.generateClient()405 var keyName = this.getKeyName( 'rules' )406 client.del(keyName, function (err) {407 408 client.quit()409 this.callCallback(callback, null)410 }.bind(this))411}412RedisDriver.prototype.isRuleExists = function (rule, callback) {413 var client = this.generateClient()414 var keyName = this.getKeyName( 'rules' )415 client.sismember(keyName, rule, function (err, value) {416 417 client.quit()418 this.callCallback(callback, value)419 }.bind(this))420}421RedisDriver.prototype.getAllUserRules = function (userId, callback) {422 var rules = []423 this.getUserById(userId, function (user) {424 if (!user) {425 this.callCallback(callback, rules)426 return427 }428 this.getCustomUserRules(user.id, function (user_rules) {429 rules = rules.concat(user_rules)430 this.getUserRoles(user, function (roles) {431 async.eachSeries(roles, function (role, cb) {432 this.getRoleRules(role.name, function (role_rules) {433 rules = rules.concat(role_rules)434 cb(null)435 })436 }.bind(this),437 function done () {438 this.callCallback(callback, rules)439 }.bind(this)440 )441 }.bind(this))442 }.bind(this)) 443 }.bind(this))444}445RedisDriver.prototype.getCustomUserRules = function (userId, callback) {446 var client = this.generateClient()447 var keyName = this.getKeyName( 'rules_user_' + userId )448 client.smembers(keyName, function (err, rules) {449 450 client.quit()451 this.callCallback(callback, rules)452 }.bind(this))453}454RedisDriver.prototype.getRoleRules = function (name, callback) {455 var client = this.generateClient()456 var keyName = this.getKeyName( 'rules_role_' + name )457 client.smembers(keyName, function (err, rules) {458 459 client.quit()460 this.callCallback(callback, rules)461 }.bind(this))462}463RedisDriver.prototype.getRules = function (callback) {464 var client = this.generateClient()465 var keyName = this.getKeyName( 'rules' )466 client.smembers(keyName, function (err, rules) {467 468 client.quit()469 this.callCallback(callback, rules)470 }.bind(this))471}...

Full Screen

Full Screen

memory-driver.js

Source:memory-driver.js Github

copy

Full Screen

...18MemoryDriver.prototype.init = function (callback) {19 this.users = []20 this.roles = []21 this.rules = {}22 this.callCallback(callback, null)23}24MemoryDriver.prototype.createUser = function (userId, roles, callback) {25 this.users.push({26 id: userId,27 roles: roles28 })29 this.callCallback(callback, null)30}31MemoryDriver.prototype.getUsers = function (callback) {32 this.callCallback(callback, this.users)33}34MemoryDriver.prototype.getUserById = function (userId, callback) {35 for (var u=0; u<this.users.length; u++) {36 var user = this.users[u]37 if (user.id == userId) {38 this.callCallback(callback, user)39 return40 }41 }42 this.callCallback(callback, null)43}44MemoryDriver.prototype.createRole = function (role, callback) {45 this.roles.push( role )46 this.callCallback(callback, null)47}48MemoryDriver.prototype.removeRoleByName = function (name, callback) {49 var index = this.getRoleIndexByName(name)50 if (index > -1) {51 this.roles.splice(index, 1)52 }53 this.callCallback(callback, null)54}55MemoryDriver.prototype.removeAllRoles = function (callback) {56 this.roles = []57 this.callCallback(callback, null)58}59MemoryDriver.prototype.setRoles = function (roles, callback) {60 this.roles = roles61 this.callCallback(callback, null)62}63MemoryDriver.prototype.getRoles = function (callback) {64 this.callCallback(callback, this.roles)65}66MemoryDriver.prototype.getRoleByName = function (name, callback) {67 this.getRoleIndexByName(name, function (index) {68 if (index < 0) {69 this.callCallback(callback, null)70 return71 }72 this.callCallback(callback, this.roles[index])73 }.bind(this)) 74}75MemoryDriver.prototype.getRoleIndexByName = function (name, callback) {76 for (var r=0; r<this.roles.length; r++) {77 var role = this.roles[r]78 if (role.name == name) {79 this.callCallback(callback, r)80 return81 }82 }83 this.callCallback(callback, -1)84}85MemoryDriver.prototype.getRolePermissions = function (name, callback) {86 this.getRoleByName(name, function (uRole) {87 if (!uRole) {88 this.callCallback(callback, [])89 return 90 }91 var permissions = uRole.permissions || []92 if (uRole.inherits) {93 var roles = uRole.inherits.split(' ')94 async.eachSeries(roles, function (role, cb) {95 this.getRolePermissions( roles, function (result) {96 if (!result) {97 cb(null)98 return99 }100 permissions = permissions.concat( result )101 cb(null)102 })103 104 }.bind(this),105 function done () {106 this.callCallback(callback, _.uniq( permissions ))107 }.bind(this)108 )109 }110 else {111 this.callCallback(callback, _.uniq( permissions ))112 }113 }.bind(this))114}115MemoryDriver.prototype.getInheritRoleNames = function (name, callback) {116 this.getRoleByName(name, function (role) {117 if (!role) {118 this.callCallback(callback, [])119 return 120 }121 var names = [name]122 if (role.inherits) {123 var inherits = role.inherits.split(' ')124 async.eachSeries(inherits, function (inherit, cb) {125 this.getInheritRoleNames( inherit, function (result) {126 if (!result) {127 cb(null)128 return129 }130 names = names.concat( result )131 cb(null)132 })133 134 }.bind(this),135 function done () {136 this.callCallback(callback, _.uniq( names ))137 }.bind(this)138 )139 }140 else {141 this.callCallback(callback, names)142 }143 }.bind(this))144}145MemoryDriver.prototype.getUserRoles = function (user, callback) {146 var roles = []147 var names = []148 async.series(149 [150 function (cb) {151 async.eachSeries(user.roles, function (role, cb2) {152 this.getInheritRoleNames( role, function (result) {153 names = names.concat( result )154 cb2(null)155 })156 157 }.bind(this),158 function done () {159 cb(null)160 }.bind(this)161 )162 }.bind(this),163 function (cb) {164 names = _.uniq( names )165 async.eachSeries(names, function (name, cb2) {166 this.getRoleByName(name, function (role) {167 roles.push( role )168 cb2(null)169 })170 }.bind(this),171 function done () {172 cb(null)173 }.bind(this)174 )175 }.bind(this)176 ],177 function (err, results) {178 this.callCallback(callback, roles)179 }.bind(this)180 )181}182MemoryDriver.prototype.createRule = function (rule, callback) {183 this.rules[rule] = 1184 this.callCallback(callback, null)185}186MemoryDriver.prototype.createRoleRule = function (role, rule, callback) {187 this.createRule(rule, callback)188}189MemoryDriver.prototype.createUserRule = function (userId, rule, callback) {190 this.createRule(rule, callback)191}192MemoryDriver.prototype.removeRule = function (rule, callback) {193 delete this.rules[rule]194 this.callCallback(callback, null)195}196MemoryDriver.prototype.removeAllRules = function (callback) {197 this.rules = {}198 this.callCallback(callback, null)199}200MemoryDriver.prototype.setRules = function (rules, callback) {201 this.rules = rules202 this.callCallback(callback, null)203}204MemoryDriver.prototype.isRuleExists = function (rule, callback) {205 this.callCallback(callback, typeof this.rules[rule] !== 'undefined')206}207MemoryDriver.prototype.getRules = function (callback) {208 var r = []209 for (var name in this.rules) {210 if (this.rules.hasOwnProperty(name)) {211 r.push(name)212 }213 }214 this.callCallback(callback, r)215}...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...15 }16}17Driver.prototype.init = function (callback) {18 console.log('init - not implemented yet.')19 this.callCallback(callback, null)20}21Driver.prototype.createUser = function (userId, roles, callback) {22 console.log('createUser - not implemented yet.')23 this.callCallback(callback, null)24}25Driver.prototype.removeUserById = function (userId, callback) {26 console.log('removeUserById - not implemented yet.')27 this.callCallback(callback, null)28}29Driver.prototype.getUserById = function (userId, callback) {30 console.log('getUserById - not implemented yet.')31 this.callCallback(callback, null)32}33Driver.prototype.getUserIndexById = function (userId, callback) {34 console.log('getUserIndexById - not implemented yet.')35 this.callCallback(callback, null)36}37Driver.prototype.getUsers = function (callback) {38 console.log('getUsers - not implemented yet.')39 this.callCallback(callback, null)40}41Driver.prototype.createRole = function (role, callback) {42 console.log('createRole - not implemented yet.')43 this.callCallback(callback, null)44}45Driver.prototype.setRoles = function (roles, callback) {46 console.log('setRoles - not implemented yet.')47 this.callCallback(callback, null)48}49Driver.prototype.removeRoleByName = function (name, callback) {50 console.log('removeRoleByName - not implemented yet.')51 this.callCallback(callback, null)52}53Driver.prototype.removeAllRoles = function (callback) {54 console.log('removeAllRoles - not implemented yet.')55 this.callCallback(callback, null)56}57Driver.prototype.getRoles = function (callback) {58 console.log('getRoles - not implemented yet.')59 this.callCallback(callback, null)60}61Driver.prototype.getRoleByName = function (name, callback) {62 console.log('getRoleByName - not implemented yet.')63 this.callCallback(callback, null)64}65Driver.prototype.getRoleIndexByName = function (name, callback) {66 console.log('getRoleIndexByName - not implemented yet.')67 this.callCallback(callback, -1)68}69Driver.prototype.getRolePermissions = function (name, callback) {70 console.log('getRolePermissions - not implemented yet.')71 this.callCallback(callback, null)72}73Driver.prototype.getInheritRoleNames = function (name, callback) {74 console.log('getInheritRoleNames - not implemented yet.')75 this.callCallback(callback, null)76}77Driver.prototype.getUserRoles = function (user, callback) {78 console.log('getUserRoles - not implemented yet.')79 this.callCallback(callback, null)80}81Driver.prototype.createUserRule = function (userId, rule, callback) {82 console.log('createUserRule - not implemented yet.')83 this.callCallback(callback, null)84}85Driver.prototype.removeUserRule = function (userId, rule, callback) {86 console.log('removeUserRule - not implemented yet.')87 this.callCallback(callback, null)88}89Driver.prototype.createRoleRule = function (name, rule, callback) {90 console.log('createRoleRule - not implemented yet.')91 this.callCallback(callback, null)92}93Driver.prototype.removeRoleRule = function (name, rule, callback) {94 console.log('removeRoleRule - not implemented yet.')95 this.callCallback(callback, null)96}97Driver.prototype.removeAllRules = function (callback) {98 console.log('removeAllRules - not implemented yet.')99 this.callCallback(callback, null)100}101Driver.prototype.isRuleExists = function (rule, callback) {102 console.log('isRuleExists - not implemented yet.')103 this.callCallback(callback, null)104}105Driver.prototype.getGlobalRules = function (userId, callback) {106 console.log('getGlobalRules - not implemented yet.')107 this.callCallback(callback, null)108}109Driver.prototype.getUserRules = function (userId, callback) {110 console.log('getUserRules - not implemented yet.')111 this.callCallback(callback, null)112}113Driver.prototype.getRoleRules = function (name, callback) {114 console.log('getRoleRules - not implemented yet.')115 this.callCallback(callback, null)116}117Driver.prototype.getRules = function (callback) {118 console.log('getRules - not implemented yet.')119 this.callCallback(callback, null)120}121Driver.prototype.showRules = function (callback) {122 console.log()123 console.log('[Rules]')124 this.getRules(function (rules) {125 if (rules &&126 rules.length > 0) {127 for (var r=0; r<rules.length; r++) {128 console.log('rule: ' + rules[r])129 }130 }131 else {132 console.log('No rules.')133 }134 this.callCallback(callback, null)135 }.bind(this))136}137Driver.prototype.showUsers = function (callback) {138 console.log()139 console.log('[Users]')140 this.getUsers(function (users) {141 if (users &&142 users.length > 0) {143 for (var u=0; u<users.length; u++) {144 console.log('user: ', users[u])145 }146 }147 else {148 console.log('No users.')149 }150 this.callCallback(callback, null)151 }.bind(this))152}153Driver.prototype.showRoles = function (callback) {154 console.log()155 console.log('[Roles]')156 this.getRoles(function (roles) {157 if (roles &&158 roles.length > 0) {159 for (var r=0; r<roles.length; r++) {160 console.log('role: ', roles[r])161 }162 }163 else {164 console.log('No roles.')165 }166 this.callCallback(callback, null)167 }.bind(this))168}...

Full Screen

Full Screen

ReceiveNotificationsJob.js

Source:ReceiveNotificationsJob.js Github

copy

Full Screen

...14 while (response = await this.webhookServiceApi.receiveNotification()) {15 let webhookBody = response.body;16 if (webhookBody.typeWebhook === this.webhookServiceApi.noteTypes.incomingMessageReceived) {17 if (webhookBody.messageData.typeMessage == "imageMessage") {18 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageImage, webhookBody)19 } else if (webhookBody.messageData.typeMessage == "videoMessage") {20 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageVideo, webhookBody)21 } else if (webhookBody.messageData.typeMessage == "documentMessage") {22 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageDocument, webhookBody)23 } else if (webhookBody.messageData.typeMessage == "audioMessage") {24 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageAudio, webhookBody)25 } else if (webhookBody.messageData.typeMessage == "documentMessage") {26 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageDocument, webhookBody)27 } else if (webhookBody.messageData.typeMessage == "textMessage") {28 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageText, webhookBody)29 } else if (webhookBody.messageData.typeMessage == "extendedTextMessage") {30 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageTextURL, webhookBody)31 } else if (webhookBody.messageData.typeMessage == "contactMessage") {32 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageContact, webhookBody)33 } else if (webhookBody.messageData.typeMessage == "locationMessage") {34 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingMessageLocation, webhookBody)35 }36 } else if (webhookBody.typeWebhook === this.webhookServiceApi.noteTypes.stateInstanceChanged) { 37 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingAccountStatus, webhookBody)38 } else if (webhookBody.typeWebhook === this.webhookServiceApi.noteTypes.outgoingMessageStatus) { 39 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingOutboundMessageStatus, webhookBody)40 } else if (webhookBody.typeWebhook === this.webhookServiceApi.noteTypes.deviceInfo) { 41 this.callCallback(this.webhookServiceApi.callbackTypes.onReceivingDeviceStatus, webhookBody)42 }43 await this.webhookServiceApi.deleteNotification(response.receiptId);44 }45 } catch (ex) {46 console.error(ex.toString());47 }48 if (!this.needInterrupt) {49 this.timerId = setInterval(this.run, this.intervalSec * 1000);50 }51 }52 callCallback(webhookType, body) {53 const callback = this.webhookServiceApi._callbacks.get(webhookType)54 if (callback) {55 // Found webhook callback;56 callback.call(this, body);57 // Callback invoked successfully;58 } else {59 // Callback not found;60 };61 }62 63}...

Full Screen

Full Screen

others.simu.class.js

Source:others.simu.class.js Github

copy

Full Screen

...16 }.bind(this), parseInt(ms/5));17 }.bind(this));18 };19 Others.prototype.fermerStabilisateur = function(callback) {20 this.callCallback(callback, 200);21 };22 Others.prototype.ouvrirStabilisateurMoyen = function(callback) {23 this.callCallback(callback, 200);24 };25 26 Others.prototype.ouvrirStabilisateurGrand = function(callback) {27 this.callCallback(callback, 200);28 };29 Others.prototype.fermerBloqueur = function(callback) {30 this.callCallback(callback, 200);31 };32 Others.prototype.ouvrirBloqueurMoyen = function(callback) {33 this.callCallback(callback, 200);34 };35 Others.prototype.ouvrirBloqueurGrand = function(callback) {36 this.callCallback(callback, 200);37 };38 Others.prototype.sortirClap = function(callback) {39 this.callCallback(callback, 200);40 };41 Others.prototype.rangerClap = function(callback) {42 this.callCallback(callback, 200);43 };44 Others.prototype.prendreGobelet = function(callback) {45 this.callCallback(callback, 200);46 };47 Others.prototype.lacherGobelet = function(callback) {48 this.callCallback(callback, 200);49 };50 Others.prototype.monterAscenseur = function(callback) {51 this.callCallback(callback, 1000);52 };53 Others.prototype.monterUnPeuAscenseur = function(callback) {54 this.callCallback(callback, 300);55 };56 Others.prototype.descendreUnPeuAscenseur = function(callback) {57 this.callCallback(callback, 300);58 };59 Others.prototype.monterMoyenAscenseur = function(callback) {60 this.callCallback(callback, 500);61 };62 Others.prototype.descendreMoyenAscenseur = function(callback) {63 this.callCallback(callback, 500);64 };65 Others.prototype.descendreAscenseur = function(callback) {66 this.callCallback(callback, 1000);67 };68 69 return Others;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var myObj = {3 myMethod: function (callback) {4 callback();5 }6};7var spy = sinon.spy();8myObj.myMethod(spy);9sinon.assert.called(spy);10var sinon = require('sinon');11var myObj = {12 myMethod: function (callback) {13 callback();14 }15};16var spy = sinon.spy();17myObj.myMethod(spy);18sinon.assert.called(spy);19it('should call the method when the button is clicked', () => {20 const wrapper = shallow(<Component />);21 const instance = wrapper.instance();22 const spy = jest.spyOn(instance, 'myMethod');23 wrapper.find('button').simulate('click');24 expect(spy).toHaveBeenCalled();25});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myModule = require('./myModule.js');4var callback = sinon.spy();5myModule.callCallback(callback);6assert(callback.called);7assert(callback.calledOnce);8assert(callback.calledWith('hello', 'world'));9exports.callCallback = function(callback) {10 callback('hello', 'world');11};12callback.calledWith('hello', 'world')13callback.calledWithExactly('hello', 'world')14callback.calledWithMatch('hello', 'world')15callback.calledOn()16callback.calledOn()17callback.threw()18callback.alwaysCalledWith()19callback.alwaysCalledWithExactly()20callback.alwaysCalledWithMatch()21callback.alwaysCalledOn()22callback.alwaysThrew()23callback.neverCalledWith()24callback.neverCalledWithExactly()25callback.neverCalledWithMatch()26callback.neverCalledOn()27callback.neverThrew()28callback.firstCall.calledBefore(callback.secondCall)29callback.firstCall.calledAfter(callback.secondCall)30callback.firstCall.calledImmediatelyBefore(callback.secondCall)31callback.firstCall.calledImmediatelyAfter(callback.secondCall)32callback.firstCall.calledOn()33callback.firstCall.calledWith()34callback.firstCall.calledWithExactly()35callback.firstCall.calledWithMatch()36callback.firstCall.threw()37callback.firstCall.returned()38callback.firstCall.callArg()39callback.firstCall.callArgWith()40callback.firstCall.callArgOn()41callback.firstCall.callArgOnWith()42callback.firstCall.yield()43callback.firstCall.yieldOn()

Full Screen

Using AI Code Generation

copy

Full Screen

1var callCallback = sinon.spy();2callCallback("hello", "world");3var callback = sinon.spy();4callback("hello", "world");5var callback = sinon.spy();6callback("hello", "world");7var callback = sinon.spy();8callback("hello", "world");

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var callback = sinon.spy();3var obj = {4 callCallback: function (callback) {5 callback();6 }7};8obj.callCallback(callback);9var sinon = require('sinon');10var callback = sinon.spy();11var obj = {12 callCallback: function (callback) {13 callback();14 }15};16obj.callCallback(callback);17var sinon = require('sinon');18var callback = sinon.spy();19var obj = {20 callCallback: function (callback) {21 callback();22 }23};24obj.callCallback(callback);25var sinon = require('sinon');26var callback = sinon.spy();27var obj = {28 callCallback: function (callback) {29 callback();30 }31};32obj.callCallback(callback);33var sinon = require('sinon');34var callback = sinon.spy();35var obj = {36 callCallback: function (callback) {37 callback();38 }39};40obj.callCallback(callback);41var sinon = require('sinon');42var callback = sinon.spy();43var obj = {44 callCallback: function (callback) {45 callback();46 }47};48obj.callCallback(callback);49var sinon = require('sinon');50var callback = sinon.spy();51var obj = {52 callCallback: function (callback) {53 callback();54 }55};56obj.callCallback(callback);57var sinon = require('sinon');58var callback = sinon.spy();59var obj = {60 callCallback: function (callback) {61 callback();62 }63};64obj.callCallback(callback);

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myObj = {4 myMethod: function (callback) {5 callback();6 }7};8describe('myMethod', function () {9 it('should call callback', function () {10 var spy = sinon.spy();11 myObj.myMethod(spy);12 assert(spy.called);13 });14});15var sinon = require('sinon');16var assert = require('assert');17var myObj = {18 myMethod: function (callback) {19 callback();20 }21};22describe('myMethod', function () {23 it('should call callback', function () {24 var mock = sinon.mock();25 myObj.myMethod(mock);26 mock.expects("called");27 });28});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var myObject = require('./myObject');3var myObjectStub = sinon.stub(myObject, 'callCallback');4myObjectStub.yields('arg1', 'arg2');5myObject.callCallback(function (arg1, arg2) {6 console.log('arg1: ' + arg1);7 console.log('arg2: ' + arg2);8});9myObjectStub.restore();10exports.callCallback = function (callback) {11 callback('arg1', 'arg2');12}13var sinon = require('sinon');14var myObject = require('./myObject');15var myObjectStub = sinon.stub(myObject, 'callCallback');16myObjectStub.yields('arg1', 'arg2');17myObject.callCallback(function (arg1, arg2) {18 console.log('arg1: ' + arg1);19 console.log('arg2: ' + arg2);20});21myObject.callCallback(function (arg1, arg2) {22 console.log('arg1: ' + arg1);23 console.log('arg2: ' + arg2);24});25myObjectStub.restore();26var sinon = require('sinon');27var myObject = require('./myObject');28var myObjectStub = sinon.stub(myObject, 'callCallback');29myObjectStub.yields('arg1', 'arg2');30myObject.callCallback(function (arg1, arg2) {31 console.log('arg1: ' + arg1);32 console.log('arg2: ' + arg2);33});34myObject.callCallback(function (arg1, arg2) {35 console.log('arg1: ' + arg1);36 console.log('arg2: ' + arg2);37});38myObjectStub.restore();

Full Screen

Using AI Code Generation

copy

Full Screen

1var obj = {2 foo: function (cb) {3 cb();4 }5};6var spy = sinon.spy(obj, 'foo');7obj.foo(function () {8 console.log('callback called');9});10spy.restore();11var obj = {12 foo: function (cb) {13 cb();14 }15};16var spy = sinon.spy(obj, 'foo');17obj.foo(function () {18 console.log('callback called');19});20spy.callArg(0);21spy.restore();22var obj = {23 foo: function (cb) {24 cb();25 }26};27var spy = sinon.spy(obj, 'foo');28obj.foo(function () {29 console.log('callback called');30});31spy.callArgWith(0, 1, 2);32spy.restore();33var obj = {34 foo: function (cb) {35 cb();36 }37};38var spy = sinon.spy(obj, 'foo');39obj.foo(function () {40 console.log('callback called');41});42spy.callArgOn(0, { x: 42 });43spy.restore();44var obj = {45 foo: function (cb) {46 cb();47 }48};49var spy = sinon.spy(obj, 'foo');50obj.foo(function () {51 console.log('callback called');52 });53spy.callArgOnWith(0, { x: 42 }, 1, 2);54spy.restore();55var obj = {56 foo: function (cb) {57 cb();58 }59};60var spy = sinon.spy(obj, 'foo');61obj.foo(function () {62 console.log('callback called');63 });64spy.callArgOnWith(0, { x: 42 }, 1, 2);65console.log(spy.callCount

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var myClass = require('./myClass');5var myClassInstance = new myClass();6describe('MyClass', function() {7 it('should call the callback', function() {8 var callback = sinon.spy();9 myClassInstance.callCallback(callback);10 expect(callback.called).to.be.true;11 });12});13function MyClass() {}14MyClass.prototype.callCallback = function(callback) {15 callback();16};17module.exports = MyClass;

Full Screen

Using AI Code Generation

copy

Full Screen

1var callCallback = sinon.spy();2callCallback();3assert(callCallback.calledOnce);4assert(callCallback.calledWithExactly());5assert(callCallback.calledWithExactly('foo', 'bar'));6var callCallback = sinon.spy();7callCallback();8assert(callCallback.calledOnce);9assert(callCallback.calledWithExactly());10assert(callCallback.calledWithExactly('foo', 'bar'));11var callCallback = sinon.spy();12callCallback();13assert(callCallback.calledOnce);14assert(callCallback.calledWithExactly());15assert(callCallback.calledWithExactly('foo', 'bar'));16var callCallback = sinon.spy();17callCallback();18assert(callCallback.calledOnce);19assert(callCallback.calledWithExactly());20assert(callCallback.calledWithExactly('foo', 'bar'));21var callCallback = sinon.spy();22callCallback();23assert(callCallback.calledOnce);24assert(callCallback.calledWithExactly());25assert(callCallback.calledWithExactly('foo', 'bar'));26var callCallback = sinon.spy();27callCallback();28assert(callCallback.calledOnce);29assert(callCallback.calledWithExactly());30assert(callCallback.calledWithExactly('foo', 'bar'));31var callCallback = sinon.spy();32callCallback();33assert(callCallback.calledOnce);34assert(callCallback.calledWithExactly());35assert(callCallback.calledWithExactly('foo', 'bar'));36var callCallback = sinon.spy();37callCallback();38assert(callCallback.calledOnce);39assert(callCallback.calledWithExactly());40assert(callCallback.calledWithExactly('foo', 'bar'));41var callCallback = sinon.spy();42callCallback();43assert(callCallback.calledOnce);44assert(callCallback.calledWithExactly());45assert(callCallback.calledWithExactly('foo', 'bar'));46var callCallback = sinon.spy();47callCallback();48assert(callCallback.calledOnce);49assert(callCallback.calledWithExactly());50assert(callCallback.calledWithExactly('foo', 'bar'));

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run sinon automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful