Best JavaScript code snippet using devicefarmer-stf
groups.js
Source:groups.js
...95 )96 ])97 })98 }99 function doUpdateDevicesCurrentGroup(group, devices) {100 return Promise.map(devices, function(serial) {101 return dbapi.updateDeviceCurrentGroup(serial, group)102 })103 }104 function doUpdateDevicesCurrentGroupFromOrigin(devices) {105 return Promise.map(devices, function(serial) {106 return dbapi.updateDeviceCurrentGroupFromOrigin(serial)107 })108 }109 function doUpdateDevicesCurrentGroupDates(group) {110 if (apiutil.isOriginGroup(group.class)) {111 return Promise.map(group.devices, function(serial) {112 return dbapi.loadDeviceBySerial(serial).then(function(device) {113 return device.group.id === group.id ?114 doUpdateDevicesCurrentGroup(group, [serial]) :115 false116 })117 })118 }119 else {120 return Promise.map(group.devices, function(serial) {121 return doUpdateDevicesCurrentGroup(group, [serial])122 })123 }124 }125 function treatGroupUsersChange(group, users, isActive, isAddedUser) {126 if (isActive) {127 return Promise.map(users, function(email) {128 return Promise.map(group.devices, function(serial) {129 return dbapi.loadDeviceBySerial(serial).then(function(device) {130 if (device && device.group.id === group.id) {131 if (!isAddedUser && device.owner && device.owner.email === email) {132 return new Promise(function(resolve) {133 let messageListener134 const responseTimer = setTimeout(function() {135 channelRouter.removeListener(wireutil.global, messageListener)136 resolve(serial)137 }, 5000)138 messageListener = wirerouter()139 .on(wire.LeaveGroupMessage, function(channel, message) {140 if (message.serial === serial &&141 message.owner.email === email) {142 clearTimeout(responseTimer)143 channelRouter.removeListener(wireutil.global, messageListener)144 resolve(serial)145 }146 })147 .handler()148 channelRouter.on(wireutil.global, messageListener)149 sendReleaseDeviceControl(serial, device.channel)150 })151 }152 return serial153 }154 return false155 })156 })157 .then(function(devices) {158 sendGroupUsersChange(159 group, [email], _.without(devices, false), isAddedUser, 'GroupUser(s)Updated')160 })161 })162 }163 else {164 return sendGroupUsersChange(group, users, [], isAddedUser, 'GroupUser(s)Updated')165 }166 }167 function treatGroupDevicesChange(oldGroup, group, devices, isAddedDevice) {168 if (isAddedDevice) {169 return doUpdateDevicesCurrentGroup(group, devices)170 }171 else {172 return doUpdateDevicesCurrentGroupFromOrigin(devices)173 .then(function() {174 if (group === null) {175 sendGroupUsersChange(oldGroup, oldGroup.users, [], false, 'GroupDeletedLater')176 }177 })178 }179 }180 function treatGroupDeletion(group) {181 if (apiutil.isOriginGroup(group.class)) {182 return dbapi.getRootGroup().then(function(rootGroup) {183 return Promise.map(group.devices, function(serial) {184 return dbapi.updateDeviceOriginGroup(serial, rootGroup)185 })186 .then(function() {187 sendGroupUsersChange(group, group.users, [], false, 'GroupDeletedLater')188 })189 })190 }191 else {192 return sendGroupUsersChange(group, group.users, [], false, 'GroupDeleted')193 }194 }195 db.run(r196 .table('groups')197 .pluck(198 'id'199 , 'name'200 , 'class'201 , 'privilege'202 , 'owner'203 , 'dates'204 , 'duration'205 , 'repetitions'206 , 'devices'207 , 'users'208 , 'state'209 , 'isActive'210 , 'ticket'211 )212 .changes(), function(err, cursor) {213 if (err) {214 throw err215 }216 return cursor217 })218 .then(function(cursor) {219 cursor.each(function(err, data) {220 let users, devices, isBecomeActive, isBecomeUnactive, isActive221 , isAddedUser, isAddedDevice, isUpdatedDeviceOriginGroup, isChangedDates222 if (err) {223 throw err224 }225 if (data.old_val === null) {226 sendGroupChange(227 data.new_val228 , data.new_val.users229 , false230 , false231 , false232 , []233 , false234 , []235 , 'created'236 )237 return sendGroupUsersChange(238 data.new_val239 , data.new_val.users240 , data.new_val.devices241 , true242 , 'GroupCreated'243 )244 }245 if (data.new_val === null) {246 sendGroupChange(247 data.old_val248 , data.old_val.users249 , false250 , false251 , false252 , []253 , false254 , []255 , 'deleted'256 )257 users = data.old_val.users258 devices = data.old_val.devices259 isChangedDates = false260 isActive = data.old_val.isActive261 isBecomeActive = isBecomeUnactive = false262 isAddedUser = isAddedDevice = false263 isUpdatedDeviceOriginGroup = false264 }265 else {266 users = _.xor(data.new_val.users, data.old_val.users)267 devices = _.xor(data.new_val.devices, data.old_val.devices)268 isChangedDates =269 data.old_val.dates.length !== data.new_val.dates.length ||270 data.old_val.dates[0].start.getTime() !==271 data.new_val.dates[0].start.getTime() ||272 data.old_val.dates[0].stop.getTime() !==273 data.new_val.dates[0].stop.getTime()274 isActive = data.new_val.isActive275 isBecomeActive = !data.old_val.isActive && data.new_val.isActive276 isBecomeUnactive = data.old_val.isActive && !data.new_val.isActive277 isAddedUser = data.new_val.users.length > data.old_val.users.length278 isAddedDevice = data.new_val.devices.length > data.old_val.devices.length279 isUpdatedDeviceOriginGroup =280 data.new_val.ticket !== null &&281 (data.old_val.ticket === null ||282 data.new_val.ticket.signature !== data.old_val.ticket.signature)283 if (!isUpdatedDeviceOriginGroup) {284 sendGroupChange(285 data.new_val286 , _.union(data.old_val.users, data.new_val.users)287 , isChangedDates288 , data.old_val.class !== data.new_val.class289 , isAddedUser290 , users291 , isAddedDevice292 , devices293 , 'updated'294 )295 }296 }297 if (isUpdatedDeviceOriginGroup) {298 return doUpdateDeviceOriginGroup(data.new_val)299 }300 else if (isBecomeActive && data.new_val.devices.length) {301 return doUpdateDevicesCurrentGroup(data.new_val, data.new_val.devices)302 }303 else if (isBecomeUnactive && data.new_val.devices.length) {304 return doUpdateDevicesCurrentGroupFromOrigin(data.new_val.devices)305 }306 else if (devices.length && isActive && !apiutil.isOriginGroup(data.old_val.class)) {307 return treatGroupDevicesChange(data.old_val, data.new_val, devices, isAddedDevice)308 }309 else if (data.new_val === null) {310 return treatGroupDeletion(data.old_val)311 }312 else if (isChangedDates && isActive) {313 return doUpdateDevicesCurrentGroupDates(data.new_val)314 }315 else if (users.length) {...
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf');2var devices = [1,2,3,4,5];3deviceFarmer.doUpdateDevicesCurrentGroup(devices, 2).then(function (res) {4 console.log(res);5}).catch(function (err) {6 console.log(err);7});8var request = require('request');9var util = require('util');10var Promise = require('bluebird');11function DeviceFarmer(baseUrl) {12 this.baseUrl = baseUrl;13}14DeviceFarmer.prototype.doUpdateDevicesCurrentGroup = function (devices, groupId) {15 var url = this.baseUrl + '/devices/updateDevicesCurrentGroup';16 return new Promise(function (resolve, reject) {17 request.post({18 body: {19 }20 }, function (err, res, body) {21 if (err) {22 reject(err);23 } else {24 resolve(body);25 }26 });27 });28};29module.exports = DeviceFarmer;30{ success: true,31 message: 'Device(s) updated successfully',32 data: null }
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2var devices = stf.getDevices();3devices.then(function(devices){4 console.log(devices);5 for(var i=0; i<devices.length; i++){6 stf.doUpdateDevicesCurrentGroup(devices[i].serial, 'newGroup');7 }8});9var devicefarmer = require('devicefarmer-stf');10var devices = stf.getDevices();11devices.then(function(devices){12 console.log(devices);13 for(var i=0; i<devices.length; i++){14 stf.doUpdateDevicesCurrentGroup(devices[i].serial, 'newGroup');15 }16});17var devicefarmer = require('devicefarmer-stf');18var devices = stf.getDevices();19devices.then(function(devices){20 console.log(devices);21 for(var i=0; i<devices.length; i++){22 stf.doUpdateDevicesCurrentGroup(devices[i].serial, 'newGroup');23 }24});25var devicefarmer = require('devicefarmer-stf');26var devices = stf.getDevices();27devices.then(function(devices){28 console.log(devices);29 for(var i=0; i<devices.length; i++){30 stf.doUpdateDevicesCurrentGroup(devices[i].serial, 'newGroup');31 }32});33var devicefarmer = require('devicefarmer-stf');34var devices = stf.getDevices();35devices.then(function(devices){36 console.log(devices);37 for(var i=0; i<devices.length; i++){38 stf.doUpdateDevicesCurrentGroup(devices[i].serial, 'newGroup');39 }40});
Using AI Code Generation
1const Client = require('devicefarmer-stf-client');2const client = new Client();3client.doUpdateDevicesCurrentGroup('group-name', 'device-serial', (err, res) => {4 if (err) {5 console.log(err);6 } else {7 console.log(res);8 }9});10const Client = require('devicefarmer-stf-client');11const client = new Client();12client.doUpdateDevicesCurrentGroup('group-name', 'device-serial', (err, res) => {13 if (err) {14 console.log(err);15 } else {16 console.log(res);17 }18});19const Client = require('devicefarmer-stf-client');20const client = new Client();21client.doUpdateDevicesCurrentGroup('group-name', 'device-serial', (err, res) => {22 if (err) {23 console.log(err);24 } else {25 console.log(res);26 }27});28const Client = require('devicefarmer-stf-client');29const client = new Client();30client.doUpdateDevicesCurrentGroup('group-name', 'device-serial', (err, res) => {31 if (err) {32 console.log(err);33 } else {34 console.log(res);35 }36});37const Client = require('devicefarmer-stf-client');38const client = new Client();39client.doUpdateDevicesCurrentGroup('group-name', 'device-serial', (err, res) => {40 if (err) {41 console.log(err);42 } else {43 console.log(res);44 }45});46const Client = require('devicefarmer-stf-client');47const client = new Client();48client.doUpdateDevicesCurrentGroup('group-name', 'device-serial', (err, res) => {49 if (err) {50 console.log(err);51 } else {52 console.log(res);53 }
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf-api');2var deviceFarmer = new DeviceFarmer({3});4var deviceId = 'device id';5var groupId = 'group id';6deviceFarmer.doUpdateDevicesCurrentGroup(deviceId, groupId, function (err, data) {7 if (err) {8 console.log('Error: ', err);9 } else {10 console.log('Data: ', data);11 }12});13var DeviceFarmer = require('devicefarmer-stf-api');14var deviceFarmer = new DeviceFarmer({15});16var deviceId = 'device id';17var groupId = 'group id';18deviceFarmer.doUpdateDevicesCurrentGroup(deviceId, groupId, function (err, data) {19 if (err) {20 console.log('Error: ', err);21 } else {22 console.log('Data: ', data);23 }24});25var DeviceFarmer = require('devicefarmer-stf-api');26var deviceFarmer = new DeviceFarmer({27});28var deviceId = 'device id';
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!