New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add emulator gsm methods #228
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! Awesome!
lib/tools/adb-emu-commands.js
Outdated
}; | ||
|
||
emuMethods.gsmSignal = async function (strength = 4) { | ||
if (!(strength in [0, 1, 2, 3, 4])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else is constants, maybe this array should be too?
lib/tools/adb-emu-commands.js
Outdated
@@ -23,6 +23,7 @@ const GSM_VOICE_STATES = [ | |||
GSM_VOICE_DENIED, GSM_VOICE_OFF, | |||
GSM_VOICE_ON | |||
]; | |||
const GSM_SIGNAL_STRENGTH = [0, 1, 2, 3, 4]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GSM_SIGNAL_STRENGTHS might be better to show this is an array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mykola-mokhnach what do you mean ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an S
to the end of the name.
lib/tools/adb-emu-commands.js
Outdated
}; | ||
|
||
emuMethods.gsmSignal = async function (strength = 4) { | ||
if (!(strength in GSM_SIGNAL_STRENGTH)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is better to use a single approach - either indexOf like above or in
lib/tools/adb-emu-commands.js
Outdated
@@ -43,4 +65,45 @@ emuMethods.sendSMS = async function (phoneNumber, message = '') { | |||
await this.adbExecEmu(['sms', 'send', phoneNumber, message]); | |||
}; | |||
|
|||
emuMethods.gsmCall = async function (phoneNumber, action = '') { | |||
if (GSM_CALL_ACTIONS.indexOf(action) === -1) { | |||
log.errorAndThrow(`Invalid gsm action param ${action}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be useful to show the list of supported values in these error messages. This will help the client to put the correct value.
lib/tools/adb-emu-commands.js
Outdated
await this.adbExecEmu(['gsm', 'voice', state]); | ||
}; | ||
|
||
emuMethods.GSM_CALL = GSM_CALL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any point to have duplicated constant declarations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might define all this like const emuMethods = {GSM_CALL: 'call' ...} and then use emuMethods.GSM_CALL... values in other constant declarations
lib/tools/adb-emu-commands.js
Outdated
@@ -77,7 +73,7 @@ emuMethods.gsmCall = async function (phoneNumber, action = '') { | |||
}; | |||
|
|||
emuMethods.gsmSignal = async function (strength = 4) { | |||
if (!(strength in GSM_SIGNAL_STRENGTH)) { | |||
if (!(strength in emuMethods.GSM_SIGNAL_STRENGTHS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost perfect. Only one small comment left - usage of indexOf/in.
lib/tools/adb-emu-commands.js
Outdated
} | ||
await this.adbExecEmu(['gsm', action, phoneNumber]); | ||
}; | ||
|
||
emuMethods.gsmSignal = async function (strength = 4) { | ||
if (!(strength in emuMethods.GSM_SIGNAL_STRENGTHS)) { | ||
strength = parseInt(strength, 10); | ||
if (emuMethods.GSM_SIGNAL_STRENGTHS.indexOf(strength) === -1) { | ||
log.errorAndThrow(`Invalid signal strength param ${strength}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the error message could be changed to
Invalid signal strength param ${strength}. Supported values: ${_.values(emuMethods.GSM_SIGNAL_STRENGTHS)}
@@ -109,5 +109,188 @@ describe('adb emulator commands', () => { | |||
mocks.adb.verify(); | |||
}); | |||
})); | |||
describe("gsm signal method", withMocks({adb}, (mocks) => { | |||
it("should throw exception on invalid strength", async () => { | |||
await adb.gsmSignal(5).should.eventually.be.rejectedWith("Invalid signal strength"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rejectedWith also supports regexp patterns
lib/tools/adb-emu-commands.js
Outdated
let emuMethods = {}; | ||
emuMethods.GSM_CALL_ACTIONS = { | ||
'GSM_CALL' : 'call', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with the other, no need to quote keys in object literal syntax, unless there is some special character (e.g., 'GSM-CALL'
would need them, GSM_CALL
does not).
Published in |
Add GSM methods supported by emulators
with this methods we can emulate phone calls, change the signal strength and the state of the gprs connection.