add tests for PUMP DISCONNECT sms command
This commit is contained in:
parent
9a1993c5f6
commit
4af06620fb
|
@ -480,18 +480,26 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
})
|
})
|
||||||
} else if (splitted.size == 3) {
|
} else if (splitted.size == 3) {
|
||||||
if (splitted[1].equals("DISCONNECT", ignoreCase = true)) {
|
if (splitted[1].equals("DISCONNECT", ignoreCase = true)) {
|
||||||
val minutes = SafeParse.stringToInt(splitted[2])
|
var duration = SafeParse.stringToInt(splitted[2])
|
||||||
|
duration = Math.max(0, duration)
|
||||||
|
duration = Math.min(120, duration)
|
||||||
|
if (duration == 0) {
|
||||||
|
receivedSms.processed = true
|
||||||
|
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_wrongduration)))
|
||||||
|
return
|
||||||
|
} else {
|
||||||
val passCode = generatePasscode()
|
val passCode = generatePasscode()
|
||||||
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_pumpdisconnectwithcode), minutes, passCode)
|
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_pumpdisconnectwithcode), duration, passCode)
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
|
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
val profile = profileFunction.getProfile()
|
val profile = profileFunction.getProfile()
|
||||||
loopPlugin.disconnectPump(minutes, profile)
|
loopPlugin.disconnectPump(duration, profile)
|
||||||
rxBus.send(EventRefreshOverview("SMS_PUMP_DISCONNECT"))
|
rxBus.send(EventRefreshOverview("SMS_PUMP_DISCONNECT"))
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_pumpdisconnected)))
|
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_pumpdisconnected)))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
||||||
return
|
return
|
||||||
|
|
|
@ -226,9 +226,12 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_loopdisablereplywithcode)).thenReturn("To disable loop reply with code %1\$s")
|
`when`(resourceHelper.gs(R.string.smscommunicator_loopdisablereplywithcode)).thenReturn("To disable loop reply with code %1\$s")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_loopenablereplywithcode)).thenReturn("To enable loop reply with code %1\$s")
|
`when`(resourceHelper.gs(R.string.smscommunicator_loopenablereplywithcode)).thenReturn("To enable loop reply with code %1\$s")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_loopresumereplywithcode)).thenReturn("To resume loop reply with code %1\$s")
|
`when`(resourceHelper.gs(R.string.smscommunicator_loopresumereplywithcode)).thenReturn("To resume loop reply with code %1\$s")
|
||||||
|
`when`(resourceHelper.gs(R.string.smscommunicator_pumpdisconnectwithcode)).thenReturn("To disconnect pump for %1d minutes reply with code %2\$s")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_pumpconnectwithcode)).thenReturn("To connect pump reply with code %1\$s")
|
`when`(resourceHelper.gs(R.string.smscommunicator_pumpconnectwithcode)).thenReturn("To connect pump reply with code %1\$s")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_reconnect)).thenReturn("Pump reconnected")
|
`when`(resourceHelper.gs(R.string.smscommunicator_reconnect)).thenReturn("Pump reconnected")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_pumpconnectfail)).thenReturn("Connection to pump failed")
|
`when`(resourceHelper.gs(R.string.smscommunicator_pumpconnectfail)).thenReturn("Connection to pump failed")
|
||||||
|
`when`(resourceHelper.gs(R.string.smscommunicator_pumpdisconnected)).thenReturn("Pump disconnected")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -547,6 +550,45 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||||
Assert.assertEquals("Pump reconnected", smsCommunicatorPlugin.messages[3].text)
|
Assert.assertEquals("Pump reconnected", smsCommunicatorPlugin.messages[3].text)
|
||||||
|
|
||||||
|
//PUMP DISCONNECT 1 2: wrong format
|
||||||
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
sms = Sms("1234", "PUMP DISCONNECT 1 2")
|
||||||
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
|
Assert.assertFalse(sms.ignored)
|
||||||
|
Assert.assertEquals("PUMP DISCONNECT 1 2", smsCommunicatorPlugin.messages[0].text)
|
||||||
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
|
||||||
|
//PUMP DISCONNECT 0
|
||||||
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
sms = Sms("1234", "PUMP DISCONNECT 0")
|
||||||
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
|
Assert.assertFalse(sms.ignored)
|
||||||
|
Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
|
||||||
|
//PUMP DISCONNECT 30
|
||||||
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
sms = Sms("1234", "PUMP DISCONNECT 30")
|
||||||
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
|
Assert.assertFalse(sms.ignored)
|
||||||
|
Assert.assertEquals("PUMP DISCONNECT 30", smsCommunicatorPlugin.messages[0].text)
|
||||||
|
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To disconnect pump for"))
|
||||||
|
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||||
|
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||||
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||||
|
Assert.assertEquals("Pump disconnected", smsCommunicatorPlugin.messages[3].text)
|
||||||
|
|
||||||
|
//PUMP DISCONNECT 30
|
||||||
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
sms = Sms("1234", "PUMP DISCONNECT 200")
|
||||||
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
|
Assert.assertFalse(sms.ignored)
|
||||||
|
Assert.assertEquals("PUMP DISCONNECT 200", smsCommunicatorPlugin.messages[0].text)
|
||||||
|
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To disconnect pump for"))
|
||||||
|
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||||
|
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||||
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||||
|
Assert.assertEquals("Pump disconnected", smsCommunicatorPlugin.messages[3].text)
|
||||||
|
|
||||||
//HELP
|
//HELP
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "HELP")
|
sms = Sms("1234", "HELP")
|
||||||
|
|
Loading…
Reference in a new issue