New tests for SMS commands: TARGET MEAL/HYPO/ACTIVITY and SMS STOP/DISABLE

This commit is contained in:
fabriziocasellato 2019-11-22 12:31:59 +01:00
parent 32f4de2c1a
commit ebc89e7526
2 changed files with 37 additions and 1 deletions

View file

@ -854,7 +854,6 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
for (number in substrings) {
var cleaned = number.replace(Regex("\\s+"), "")
if (cleaned.length < 4) continue
if (cleaned.substring(0, 1).compareTo("+") != 0) continue
cleaned = cleaned.replace("+", "")
if (!cleaned.matches(Regex("[0-9]+"))) continue
countNumbers++

View file

@ -348,6 +348,43 @@ public class SmsCommunicatorPluginTest {
Assert.assertEquals("PUMP", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).text);
//SMS : wrong format
smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "SMS");
smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored);
Assert.assertEquals("SMS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//SMS STOP
smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "SMS DISABLE");
smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("SMS DISABLE", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To disable the SMS Remote Service reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone."));
//TARGET : wrong format
smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TARGET");
smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored);
Assert.assertEquals("TARGET", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//TARGET MEAL
smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TARGET MEAL");
smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("TARGET MEAL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To set the Temp Target MEAL reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Target MEAL for 45 minutes set successfully"));
}
@Test