-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
170 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = robot => robot.loadFile(__dirname, 'script.js') |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Description | ||
// A Hubot script to check status of your m2m-status sims | ||
// | ||
// Dependencies: | ||
// "m2m-status": "0.1.0" | ||
// | ||
// Configuration: | ||
// M2M_USER, M2M_PASS | ||
// | ||
// Commands: | ||
// hubot m2m check <sim> - Check status of sim | ||
// hubot m2m check <icc> - Check status of icc | ||
// | ||
// Author: | ||
// lgaticaq | ||
|
||
const M2m = require('m2m-status') | ||
|
||
module.exports = robot => { | ||
const getStatus = (res, method) => { | ||
res.send('Checking status...') | ||
const client = new M2m({ | ||
user: process.env.M2M_USER, | ||
password: process.env.M2M_PASS | ||
}) | ||
return client[method](res.match[1]) | ||
} | ||
|
||
const onResult = result => { | ||
let msg = `Administration: ${result.status.admin ? 'OK' : 'Error'}\n` | ||
msg += `GSM: ${result.status.gsm ? 'OK' : 'Error'}\n` | ||
msg += `GPRS: ${result.status.gprs ? 'OK' : 'Error'}` | ||
return msg | ||
} | ||
|
||
robot.respond(/m2m check (\+\d{11})/, res => { | ||
getStatus(res, 'checkSim') | ||
.then(result => res.send(onResult(result))) | ||
.catch(err => { | ||
res.send(`Error: ${err.message}`) | ||
robot.emit('error', err) | ||
}) | ||
}) | ||
|
||
robot.respond(/m2m check (\d{19})/, res => | ||
getStatus(res, 'checkIcc') | ||
.then(result => res.send(onResult(result))) | ||
.catch(err => { | ||
res.send(`Error: ${err.message}`) | ||
robot.emit('error', err) | ||
}) | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
'use strict' | ||
|
||
require('coffee-script/register') | ||
const Helper = require('hubot-test-helper') | ||
const { expect } = require('chai') | ||
const proxyquire = require('proxyquire') | ||
|
||
process.env.M2M_USER = 'user' | ||
process.env.M2M_PASS = 'password' | ||
|
||
class M2m { | ||
constructor (username, password) { | ||
this.username = username | ||
this.password = password | ||
} | ||
checkSim (sim) { | ||
return new Promise((resolve, reject) => { | ||
if (sim === '+56999999999') { | ||
return resolve({ status: { admin: true, gsm: true, gprs: true } }) | ||
} else if (sim === '+56888888888') { | ||
return resolve({ status: { admin: false, gsm: false, gprs: false } }) | ||
} else { | ||
return reject(new Error(`Sim ${sim} not found or not active`)) | ||
} | ||
}) | ||
} | ||
checkIcc (icc) { | ||
return new Promise((resolve, reject) => { | ||
if (icc === '1111111111111111111') { | ||
return resolve({ status: { admin: true, gsm: true, gprs: true } }) | ||
} else if (icc === '2222222222222222222') { | ||
return resolve({ status: { admin: false, gsm: false, gprs: false } }) | ||
} else { | ||
return reject(new Error(`ICC ${icc} not found or not active`)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
proxyquire('./../src/script.js', { 'm2m-status': M2m }) | ||
|
||
const helper = new Helper('./../src/index.js') | ||
|
||
describe('hubot-m2m-status', function () { | ||
beforeEach(() => { | ||
this.room = helper.createRoom({ name: 'user' }) | ||
}) | ||
|
||
afterEach(() => this.room.destroy()) | ||
|
||
context('sim invalid', () => { | ||
beforeEach(done => { | ||
this.room.user.say('user', 'hubot m2m check +56111111111') | ||
setTimeout(done, 100) | ||
}) | ||
|
||
it('should get a error', () => { | ||
expect(this.room.messages).to.eql([ | ||
['user', 'hubot m2m check +56111111111'], | ||
['hubot', 'Checking status...'], | ||
['hubot', 'Error: Sim +56111111111 not found or not active'] | ||
]) | ||
}) | ||
}) | ||
|
||
context('icc invalid', () => { | ||
beforeEach(done => { | ||
this.room.user.say('user', 'hubot m2m check 3333333333333333333') | ||
setTimeout(done, 100) | ||
}) | ||
|
||
it('should get a error', () => { | ||
expect(this.room.messages).to.eql([ | ||
['user', 'hubot m2m check 3333333333333333333'], | ||
['hubot', 'Checking status...'], | ||
['hubot', 'Error: ICC 3333333333333333333 not found or not active'] | ||
]) | ||
}) | ||
}) | ||
|
||
context('sim valid data false', () => { | ||
beforeEach(done => { | ||
this.room.user.say('user', 'hubot m2m check +56888888888') | ||
setTimeout(done, 100) | ||
}) | ||
|
||
it('should get a sim status', () => { | ||
let message = 'Administration: Error\n' | ||
message += 'GSM: Error\n' | ||
message += 'GPRS: Error' | ||
expect(this.room.messages).to.eql([ | ||
['user', 'hubot m2m check +56888888888'], | ||
['hubot', 'Checking status...'], | ||
['hubot', message] | ||
]) | ||
}) | ||
}) | ||
|
||
context('icc valid data false', () => { | ||
beforeEach(done => { | ||
this.room.user.say('user', 'hubot m2m check 2222222222222222222') | ||
setTimeout(done, 100) | ||
}) | ||
|
||
it('should get a sim status', () => { | ||
let message = 'Administration: Error\n' | ||
message += 'GSM: Error\n' | ||
message += 'GPRS: Error' | ||
expect(this.room.messages).to.eql([ | ||
['user', 'hubot m2m check 2222222222222222222'], | ||
['hubot', 'Checking status...'], | ||
['hubot', message] | ||
]) | ||
}) | ||
}) | ||
|
||
context('sim valid data true', () => { | ||
beforeEach(done => { | ||
this.room.user.say('user', 'hubot m2m check +56999999999') | ||
setTimeout(done, 100) | ||
}) | ||
|
||
it('should get a sim status', () => { | ||
let message = 'Administration: OK\n' | ||
message += 'GSM: OK\n' | ||
message += 'GPRS: OK' | ||
expect(this.room.messages).to.eql([ | ||
['user', 'hubot m2m check +56999999999'], | ||
['hubot', 'Checking status...'], | ||
['hubot', message] | ||
]) | ||
}) | ||
}) | ||
|
||
context('icc valid data true', () => { | ||
beforeEach(done => { | ||
this.room.user.say('user', 'hubot m2m check 1111111111111111111') | ||
setTimeout(done, 100) | ||
}) | ||
|
||
it('should get a sim status', () => { | ||
let message = 'Administration: OK\n' | ||
message += 'GSM: OK\n' | ||
message += 'GPRS: OK' | ||
expect(this.room.messages).to.eql([ | ||
['user', 'hubot m2m check 1111111111111111111'], | ||
['hubot', 'Checking status...'], | ||
['hubot', message] | ||
]) | ||
}) | ||
}) | ||
}) |