How to use getDeviceFilteredGroups method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

devices.js

Source:devices.js Github

copy

Full Screen

...28 .catch(function(err) {29 apiutil.internalError(res, 'Failed to load device list: ', err.stack)30 })31}32function getDeviceFilteredGroups(serial, fields, bookingOnly) {33 return dbapi.getDeviceGroups(serial).then(function(groups) {34 return Promise.map(groups, function(group) {35 return !bookingOnly || !apiutil.isOriginGroup(group.class) ?36 group :37 'filtered'38 })39 .then(function(groups) {40 return _.without(groups, 'filtered').map(function(group) {41 if (fields) {42 return _.pick(apiutil.publishGroup(group), fields.split(','))43 }44 return apiutil.publishGroup(group)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 = {}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2client.getDeviceFilteredGroups(function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9[ { id: 1, name: 'default' }, { id: 2, name: 'test' } ]10client.getDeviceFilteredGroups(function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17client.getDeviceGroup(1, function(err, data) {18 if (err) {19 console.log(err);20 } else {21 console.log(data);22 }23});24client.getDeviceGroupDevices(1, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31client.getDeviceGroupDevices(1, function(err, data) {32 if (err) {33 console.log(err);34 } else {35 console.log(data);36 }37});38client.getDeviceGroupDevices(1, function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45client.getDeviceGroupDevices(1, function(err, data) {46 if (err) {47 console.log(err);48 } else {49 console.log(data);50 }51});52client.getDeviceGroupDevices(1, function(err, data) {53 if (err) {54 console.log(err);55 } else {56 console.log(data);57 }58});59client.getDeviceGroupDevices(1, function(err, data) {60 if (err) {61 console.log(err);62 } else {63 console.log(data);64 }65});66client.getDeviceGroupDevices(1

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = client.getDevice('1234567890');3device.getDeviceFilteredGroups().then(function(data){4 console.log(data);5});6var stf = require('devicefarmer-stf-client');7var device = client.getDevice('1234567890');8device.getDeviceFilteredGroups().then(function(data){9 console.log(data);10});11var stf = require('devicefarmer-stf-client');12var device = client.getDevice('1234567890');13device.getDeviceFilteredGroups().then(function(data){14 console.log(data);15});16var stf = require('devicefarmer-stf-client');17var device = client.getDevice('1234567890');18device.getDeviceFilteredGroups().then(function(data){19 console.log(data);20});21var stf = require('devicefarmer-stf-client');22var device = client.getDevice('1234567890');23device.getDeviceFilteredGroups().then(function(data){24 console.log(data);25});26var stf = require('devicefarmer-stf-client');27var device = client.getDevice('1234567890');28device.getDeviceFilteredGroups().then(function(data){29 console.log(data);30});31var stf = require('devicefarmer-stf-client');

Full Screen

Using AI Code Generation

copy

Full Screen

1const Stf = require('devicefarmer-stf-client');2stf.getDeviceFilteredGroups(function(err,groups){3 if(err){4 console.log(err);5 }else{6 console.log(groups);7 }8});9[ { id: 1,10 modified: '2016-12-16T05:33:53.000Z' },11 { id: 2,12 modified: '2016-12-16T05:33:53.000Z' } ]

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var options = {3};4var deviceFarmer = new stf(options);5var device = new deviceFarmer.Device();6var deviceGroup = new deviceFarmer.DeviceGroup();7var deviceFilter = new deviceFarmer.DeviceFilter();8var deviceGroupFilter = new deviceFarmer.DeviceGroupFilter();9var filter = new deviceGroupFilter();10filter.name = 'test';11deviceGroup.getDeviceFilteredGroups(filter)12.then(function(groups) {13 console.log(groups);14})15.catch(function(err) {16 console.log(err);17});18var stf = require('devicefarmer-stf');19var options = {20};21var deviceFarmer = new stf(options);22var device = new deviceFarmer.Device();23var deviceGroup = new deviceFarmer.DeviceGroup();24var deviceFilter = new deviceFarmer.DeviceFilter();25var deviceGroupFilter = new deviceFarmer.DeviceGroupFilter();26var filter = new deviceGroupFilter();27filter.name = 'test';28deviceGroup.getDeviceFilteredGroups(filter)29.then(function(groups) {30 console.log(groups);31})32.catch(function(err) {33 console.log(err);34});35var stf = require('devicefarmer-stf');36var options = {37};38var deviceFarmer = new stf(options);39var device = new deviceFarmer.Device();40var deviceGroup = new deviceFarmer.DeviceGroup();41var deviceFilter = new deviceFarmer.DeviceFilter();42var deviceGroupFilter = new deviceFarmer.DeviceGroupFilter();43var filter = new deviceGroupFilter();44filter.name = 'test';45deviceGroup.getDeviceFilteredGroups(filter)46.then(function(groups) {47 console.log(groups);48})49.catch(function(err) {50 console.log(err);51});52var stf = require('devicefarmer-stf');53var options = {54};55var deviceFarmer = new stf(options);

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2var device = new client.Device(stf);3device.getDeviceFilteredGroups('mydevice', 'mygroup', function(err, res){4 if(err){5 console.log('error: ' + err);6 }else{7 console.log('response: ' + res);8 }9});

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