mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 00:23:25 +02:00
Implement account check (if it's already added).
This commit is contained in:
@@ -14,7 +14,35 @@ module.exports = syrup.serial()
|
||||
.define(function(options, service, identity, touch, router, push, adb) {
|
||||
var log = logger.createLogger('device:plugins:account')
|
||||
|
||||
router.on(wire.AccountGetMessage, function(channel, message){
|
||||
router.on(wire.AccountCheckMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
|
||||
log.info('Checking if account "%s" is added',message.account)
|
||||
|
||||
service.getAccounts(message.type)
|
||||
.timeout(30000)
|
||||
.then(function(accounts) {
|
||||
if(accounts.indexOf(message.account) >= 0) {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay()
|
||||
])
|
||||
}
|
||||
else {
|
||||
throw new Error('The account is not added')
|
||||
}
|
||||
})
|
||||
.catch(function(err){
|
||||
log.error('Account check failed', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail(err.message)
|
||||
])
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
router.on(wire.AccountGetMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
|
||||
log.info('Getting account(s) of type "%s"', message.type)
|
||||
|
||||
Reference in New Issue
Block a user