How to use extractStandardizableDevices method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

devices.js

Source:devices.js Github

copy

Full Screen

...45 })46 })47 })48}49function extractStandardizableDevices(devices) {50 return dbapi.getTransientGroups().then(function(groups) {51 return Promise.map(devices, function(device) {52 return Promise.map(groups, function(group) {53 if (group.devices.indexOf(device.serial) > -1) {54 return Promise.reject('booked')55 }56 return true57 })58 .then(function() {59 return device60 })61 .catch(function(err) {62 if (err !== 'booked') {63 throw err64 }65 return err66 })67 })68 .then(function(devices) {69 return _.without(devices, 'booked')70 })71 })72}73function getStandardizableDevices(req, res) {74 dbapi.loadDevicesByOrigin(req.user.groups.subscribed).then(function(devices) {75 extractStandardizableDevices(devices).then(function(devices) {76 filterGenericDevices(req, res, devices)77 })78 })79 .catch(function(err) {80 apiutil.internalError(res, 'Failed to load device list: ', err.stack)81 })82}83function removeDevice(serial, req, res) {84 const presentState = req.swagger.params.present.value85 const bookingState = req.swagger.params.booked.value86 const notesState = req.swagger.params.annotated.value87 const controllingState = req.swagger.params.controlled.value88 const anyPresentState = typeof presentState === 'undefined'89 const anyBookingState = typeof bookingState === 'undefined'90 const anyNotesState = typeof notesState === 'undefined'91 const anyControllingState = typeof controllingState === 'undefined'92 const lock = {}93 function deleteGroupDevice(email, id) {94 const lock = {}95 return dbapi.lockGroupByOwner(email, id).then(function(stats) {96 if (!stats.replaced) {97 return apiutil.lightComputeStats(res, stats)98 }99 const group = lock.group = stats.changes[0].new_val100 if (group.devices.indexOf(serial) > -1) {101 return apiutil.isOriginGroup(group.class) ?102 dbapi.removeOriginGroupDevice(group, serial) :103 dbapi.removeGroupDevices(group, [serial])104 }105 return group106 })107 .finally(function() {108 lockutil.unlockGroup(lock)109 })110 }111 function deleteDeviceInDatabase() {112 function wrappedDeleteDeviceInDatabase() {113 const result = {114 status: false115 , data: 'not deleted'116 }117 return dbapi.loadDeviceBySerial(serial).then(function(device) {118 if (device && device.group.id === device.group.origin) {119 return deleteGroupDevice(device.group.owner.email, device.group.id)120 .then(function(group) {121 if (group !== 'not found') {122 return dbapi.deleteDevice(serial).then(function() {123 result.status = true124 result.data = 'deleted'125 })126 }127 return false128 })129 }130 return false131 })132 .then(function() {133 return result134 })135 }136 return apiutil.setIntervalWrapper(137 wrappedDeleteDeviceInDatabase138 , 10139 , Math.random() * 500 + 50)140 }141 return dbapi.lockDeviceByOrigin(req.user.groups.subscribed, serial).then(function(stats) {142 if (!stats.replaced) {143 return apiutil.lightComputeStats(res, stats)144 }145 const device = lock.device = stats.changes[0].new_val146 if (!anyPresentState && device.present !== presentState ||147 !anyControllingState && (device.owner === null) === controllingState ||148 !anyNotesState &&149 (typeof device.notes !== 'undefined' && device.notes !== '') !== notesState ||150 !anyBookingState && (device.group.id !== device.group.origin && !bookingState ||151 device.group.class === apiutil.STANDARD && bookingState)) {152 return 'unchanged'153 }154 if (device.group.class === apiutil.STANDARD) {155 return deleteDeviceInDatabase()156 }157 return dbapi.getDeviceTransientGroups(serial).then(function(groups) {158 if (groups.length && !anyBookingState && !bookingState) {159 return 'unchanged'160 }161 return Promise.each(groups, function(group) {162 return deleteGroupDevice(group.owner.email, group.id)163 })164 .then(function() {165 if (!groups.length && !anyBookingState && bookingState) {166 return 'unchanged'167 }168 return deleteDeviceInDatabase()169 })170 })171 })172 .finally(function() {173 lockutil.unlockDevice(lock)174 })175}176/* ------------------------------------ PUBLIC FUNCTIONS ------------------------------- */177function getDevices(req, res) {178 const target = req.swagger.params.target.value179 switch(target) {180 case apiutil.BOOKABLE:181 getGenericDevices(req, res, dbapi.loadBookableDevices)182 break183 case apiutil.ORIGIN:184 getGenericDevices(req, res, dbapi.loadDevicesByOrigin)185 break186 case apiutil.STANDARD:187 getGenericDevices(req, res, dbapi.loadStandardDevices)188 break189 case apiutil.STANDARDIZABLE:190 getStandardizableDevices(req, res)191 break192 default:193 getGenericDevices(req, res, dbapi.loadDevices)194 }195}196function getDeviceBySerial(req, res) {197 var serial = req.swagger.params.serial.value198 var fields = req.swagger.params.fields.value199 dbapi.loadDevice(req.user.groups.subscribed, serial)200 .then(function(cursor) {201 cursor.next(function(err, device) {202 if (err) {203 return res.status(404).json({204 success: false205 , description: 'Device not found'206 })207 }208 let responseDevice = apiutil.publishDevice(device, req.user)209 if (fields) {210 responseDevice = _.pick(device, fields.split(','))211 }212 res.json({213 success: true214 , device: responseDevice215 })216 })217 })218 .catch(function(err) {219 log.error('Failed to load device "%s": ', serial, err.stack)220 res.status(500).json({221 success: false222 })223 })224}225function getDeviceGroups(req, res) {226 const serial = req.swagger.params.serial.value227 const fields = req.swagger.params.fields.value228 dbapi.loadDevice(req.user.groups.subscribed, serial).then(function(cursor) {229 return cursor.toArray()230 })231 .then(function(devices) {232 if (!devices.length) {233 apiutil.respond(res, 404, 'Not Found (device)')234 }235 else {236 getDeviceFilteredGroups(serial, fields, false)237 .then(function(groups) {238 return apiutil.respond(res, 200, 'Groups Information', {groups: groups})239 })240 }241 })242 .catch(function(err) {243 apiutil.internalError(res, 'Failed to get device groups: ', err.stack)244 })245}246function getDeviceBookings(req, res) {247 const serial = req.swagger.params.serial.value248 const fields = req.swagger.params.fields.value249 dbapi.loadDevice(req.user.groups.subscribed, serial).then(function(cursor) {250 return cursor.toArray()251 })252 .then(function(devices) {253 if (!devices.length) {254 apiutil.respond(res, 404, 'Not Found (device)')255 }256 else {257 getDeviceFilteredGroups(serial, fields, true)258 .then(function(bookings) {259 apiutil.respond(res, 200, 'Bookings Information', {bookings: bookings})260 })261 }262 })263 .catch(function(err) {264 apiutil.internalError(res, 'Failed to get device bookings: ', err.stack)265 })266}267function addOriginGroupDevices(req, res) {268 const serials = apiutil.getBodyParameter(req.body, 'serials')269 const fields = apiutil.getQueryParameter(req.swagger.params.fields)270 const target = apiutil.getQueryParameter(req.swagger.params.redirected) ? 'device' : 'devices'271 const lock = {}272 function askUpdateDeviceOriginGroup(group, serial) {273 return new Promise(function(resolve, reject) {274 const signature = util.format('%s', uuid.v4()).replace(/-/g, '')275 let messageListener276 const responseTimer = setTimeout(function() {277 req.options.channelRouter.removeListener(wireutil.global, messageListener)278 apiutil.respond(res, 504, 'Gateway Time-out')279 reject('timeout')280 }, 5000)281 messageListener = wirerouter()282 .on(wire.DeviceOriginGroupMessage, function(channel, message) {283 if (message.signature === signature) {284 clearTimeout(responseTimer)285 req.options.channelRouter.removeListener(wireutil.global, messageListener)286 dbapi.loadDeviceBySerial(serial).then(function(device) {287 if (fields) {288 resolve(_.pick(apiutil.publishDevice(device, req.user), fields.split(',')))289 }290 else {291 resolve(apiutil.publishDevice(device, req.user))292 }293 })294 }295 })296 .handler()297 req.options.channelRouter.on(wireutil.global, messageListener)298 return dbapi.askUpdateDeviceOriginGroup(serial, group, signature)299 })300 }301 function updateDeviceOriginGroup(group, serial) {302 const lock = {}303 return dbapi.lockDeviceByOrigin(req.user.groups.subscribed, serial).then(function(stats) {304 if (!stats.replaced) {305 return apiutil.lightComputeStats(res, stats)306 }307 lock.device = stats.changes[0].new_val308 return dbapi.isUpdateDeviceOriginGroupAllowed(serial, group)309 .then(function(updatingAllowed) {310 if (!updatingAllowed) {311 apiutil.respond(res, 403, 'Forbidden (device is currently booked)')312 return Promise.reject('booked')313 }314 return askUpdateDeviceOriginGroup(group, serial)315 })316 })317 .finally(function() {318 lockutil.unlockDevice(lock)319 })320 }321 function updateDevicesOriginGroup(group, serials) {322 let results = []323 return Promise.each(serials, function(serial) {324 return updateDeviceOriginGroup(group, serial).then(function(result) {325 results.push(result)326 })327 })328 .then(function() {329 const result = target === 'device' ? {device: {}} : {devices: []}330 results = _.without(results, 'unchanged')331 if (!results.length) {332 return apiutil.respond(res, 200, `Unchanged (${target})`, result)333 }334 results = _.without(results, 'not found')335 if (!results.length) {336 return apiutil.respond(res, 404, `Not Found (${target})`)337 }338 if (target === 'device') {339 result.device = results[0]340 }341 else {342 result.devices = results343 }344 return apiutil.respond(res, 200, `Updated (${target})`, result)345 })346 .catch(function(err) {347 if (err !== 'booked' && err !== 'timeout' && err !== 'busy') {348 throw err349 }350 })351 }352 return lockutil.lockGroup(req, res, lock).then(function(lockingSuccessed) {353 if (lockingSuccessed) {354 const group = lock.group355 if (!apiutil.isOriginGroup(group.class)) {356 return apiutil.respond(res, 400, 'Bad Request (this group cannot act as an origin one)')357 }358 if (typeof serials !== 'undefined') {359 return updateDevicesOriginGroup(360 group361 , _.without(serials.split(','), '').filter(function(serial) {362 return group.devices.indexOf(serial) < 0363 })364 )365 }366 return dbapi.loadDevicesByOrigin(req.user.groups.subscribed).then(function(devices) {367 if (group.class === apiutil.BOOKABLE) {368 return devices369 }370 return extractStandardizableDevices(devices)371 })372 .then(function(devices) {373 const serials = []374 devices.forEach(function(device) {375 if (group.devices.indexOf(device.serial) < 0) {376 serials.push(device.serial)377 }378 })379 return updateDevicesOriginGroup(group, serials)380 })381 }382 return false383 })384 .catch(function(err) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const stf = require('devicefarmer-stf');2const path = require('path');3const fs = require('fs');4const inputFile = path.join(__dirname, 'devices.json');5const outputFile = path.join(__dirname, 'devices_standardized.json');6const inputDevices = JSON.parse(fs.readFileSync(inputFile, 'utf8'));7const outputDevices = stf.extractStandardizableDevices(inputDevices);8fs.writeFileSync(outputFile, JSON.stringify(outputDevices, null, 2));9console.log('done');10 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var deviceFarmer = require('./index.js');2var deviceFarmerClient = new deviceFarmer.DeviceFarmerClient();3var devices = deviceFarmerClient.extractStandardizableDevices();4console.log(devices);5var deviceFarmer = require('./index.js');6var deviceFarmerClient = new deviceFarmer.DeviceFarmerClient();7var devices = deviceFarmerClient.extractStandardizableDevices();8console.log(devices);9var deviceFarmer = require('./index.js');10var deviceFarmerClient = new deviceFarmer.DeviceFarmerClient();11var devices = deviceFarmerClient.extractStandardizableDevices();12console.log(devices);13var deviceFarmer = require('./index.js');14var deviceFarmerClient = new deviceFarmer.DeviceFarmerClient();15var devices = deviceFarmerClient.extractStandardizableDevices();16console.log(devices);17var deviceFarmer = require('./index.js');18var deviceFarmerClient = new deviceFarmer.DeviceFarmerClient();19var devices = deviceFarmerClient.extractStandardizableDevices();20console.log(devices);

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmerStfDevice = require('devicefarmer-stf-device');2var devicefarmerStfDevice = require('devicefarmer-stf-device');3var device = new devicefarmerStfDevice.Device('localhost', 7100);4var devices = device.extractStandardizableDevices(devices);5device.getDevice(devices[0].serial);6var devicefarmerStfDevice = require('devicefarmer-stf-device');7var devicefarmerStfDevice = require('devicefarmer-stf-device');8var device = new devicefarmerStfDevice.Device('localhost', 7100);9var devices = device.extractStandardizableDevices(devices);10device.getDevice(devices[0].serial);11var devicefarmerStfDevice = require('devicefarmer-stf-device');12var devicefarmerStfDevice = require('devicefarmer-stf-device');13var device = new devicefarmerStfDevice.Device('localhost', 7100);14var devices = device.extractStandardizableDevices(devices);15device.getDevice(devices[0].serial);16var devicefarmerStfDevice = require('devicefarmer-stf-device');17var devicefarmerStfDevice = require('devicefarmer-stf-device');18var device = new devicefarmerStfDevice.Device('localhost', 7100);19var devices = device.extractStandardizableDevices(devices);20device.getDevice(devices[0].serial);21var devicefarmerStfDevice = require('devicefarmer-stf-device');22var devicefarmerStfDevice = require('devicefarmer-stf-device');

Full Screen

Using AI Code Generation

copy

Full Screen

1var devices = require('devicefarmer-stf-service').extractStandardizableDevices;2devices(function(err, standardizableDevices) {3 console.log(standardizableDevices);4});5var getDevice = require('devicefarmer-stf-service').getDevice;6getDevice('device serial', function(err, device) {7 console.log(device);8});9var getDevices = require('devicefarmer-stf-service').getDevices;10getDevices(function(err, devices) {11 console.log(devices);12});13var getDevices = require('devicefarmer-stf-service').getDevices;14getDevices(function(err, devices) {15 console.log(devices);16});17var getDevices = require('devicefarmer-stf-service').getDevices;18getDevices(function(err, devices) {19 console.log(devices);20});21var getDevices = require('devicefarmer-stf-service').getDevices;22getDevices(function(err, devices) {23 console.log(devices);24});25var getDevices = require('devicefarmer-stf-service').getDevices;26getDevices(function(err, devices) {27 console.log(devices);28});

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 devicefarmer-stf 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