How to use updateUsersForMigration method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

api.js

Source:api.js Github

copy

Full Screen

...27 ])28}29dbapi.createBootStrap = function(env) {30 const now = Date.now()31 function updateUsersForMigration(group) {32 return dbapi.getUsers().then(function(users) {33 return Promise.map(users, function(user) {34 return db.run(r.table('users').get(user.email).update({35 privilege: user.email !== group.owner.email ? apiutil.USER : apiutil.ADMIN36 , groups: {37 subscribed: []38 , lock: false39 , quotas: {40 allocated: {41 number: group.envUserGroupsNumber42 , duration: group.envUserGroupsDuration43 }44 , consumed: {45 number: 046 , duration: 047 }48 , defaultGroupsNumber: user.email !== group.owner.email ?49 0 :50 group.envUserGroupsNumber51 , defaultGroupsDuration: user.email !== group.owner.email ?52 0 :53 group.envUserGroupsDuration54 , defaultGroupsRepetitions: user.email !== group.owner.email ?55 0 :56 group.envUserGroupsRepetitions57 , repetitions: group.envUserGroupsRepetitions58 }59 }60 }))61 .then(function(stats) {62 if (stats.replaced) {63 return dbapi.addGroupUser(group.id, user.email)64 }65 return stats66 })67 })68 })69 }70 function getDevices() {71 return db.run(r.table('devices'))72 .then(function(cursor) {73 return cursor.toArray()74 })75 }76 77 function updateDevicesForMigration(group) {78 return getDevices().then(function(devices) {79 return Promise.map(devices, function(device) {80 return db.run(r.table('devices').get(device.serial).update({81 group: {82 id: group.id83 , name: group.name84 , lifeTime: group.dates[0]85 , owner: group.owner86 , origin: group.id87 , class: group.class88 , repetitions: group.repetitions89 , originName: group.name90 , lock: false91 }}92 ))93 .then(function(stats) {94 if (stats.replaced) {95 return dbapi.addOriginGroupDevice(group, device.serial)96 }97 return stats98 })99 })100 })101 }102 return dbapi.createGroup({103 name: env.STF_ROOT_GROUP_NAME104 , owner: {105 email: env.STF_ADMIN_EMAIL106 , name: env.STF_ADMIN_NAME107 }108 , users: [env.STF_ADMIN_EMAIL]109 , privilege: apiutil.ROOT110 , class: apiutil.STANDARD111 , repetitions: 0112 , duration: 0113 , isActive: true114 , state: apiutil.READY115 , dates: [{116 start: new Date(now)117 , stop: new Date(now + apiutil.ONE_YEAR)118 }]119 , envUserGroupsNumber: apiutil.MAX_USER_GROUPS_NUMBER120 , envUserGroupsDuration: apiutil.MAX_USER_GROUPS_DURATION121 , envUserGroupsRepetitions: apiutil.MAX_USER_GROUPS_REPETITIONS122 })123 .then(function(group) {124 return dbapi.saveUserAfterLogin({125 name: group.owner.name126 , email: group.owner.email127 , ip: '127.0.0.1'128 })129 .then(function() {130 return updateUsersForMigration(group)131 })132 .then(function() {133 return updateDevicesForMigration(group)134 })135 .then(function() {136 return dbapi.reserveUserGroupInstance(group.owner.email)137 })138 })139}140dbapi.deleteDevice = function(serial) {141 return db.run(r.table('devices').get(serial).delete())142}143dbapi.deleteUser = function(email) {144 return db.run(r.table('users').get(email).delete())...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var r = request.post(url, function optionalCallback(err, httpResponse, body) {3 if (err) {4 return console.error('upload failed:', err);5 }6 console.log('Upload successful! Server responded with:', body);7});8var form = r.form();9form.append('my_file', fs.createReadStream('/home/rahul/Desktop/STF/stf/test4.js'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var config = require('./config.json');3var async = require('async');4var util = require('util');5var stfClient = stf.createClient(config);6var users = [];7var updateUsers = [];8stfClient.getUsers(function(err, res) {9 if (err) {10 console.log('Error getting users: ' + err);11 } else {12 users = res;13 console.log('Users: ' + JSON.stringify(users));14 async.eachSeries(users, function(user, callback) {15 stfClient.getUser(user.id, function(err, res) {16 if (err) {17 console.log('Error getting user: ' + err);18 } else {19 if (res.version == '1.2.0') {20 updateUsers.push(user);21 }22 }23 callback();24 });25 }, function(err) {26 if (err) {27 console.log('Error getting users: ' + err);28 } else {29 console.log('Users to update: ' + JSON.stringify(updateUsers));30 stfClient.updateUsersForMigration(updateUsers, function(err, res) {31 if (err) {32 console.log('Error updating users: ' + err);33 } else {34 console.log('Users updated: ' + JSON.stringify(res));35 }36 });37 }38 });39 }40});41stfClient.getUsers(function(err, res) {42 if (err) {43 console.log('Error getting users: ' + err);44 } else {45 users = res;46 console.log('Users: ' + JSON.stringify(users));47 async.eachSeries(users, function(user, callback) {48 stfClient.getUser(user.id, function(err, res) {49 if (err) {50 console.log('Error getting user: ' + err);51 } else {52 if (res.version == '1.2.0') {

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