Search in sources :

Example 1 with SmsTemplate

use of org.sagebionetworks.bridge.models.apps.SmsTemplate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantController method sendSmsMessageForWorker.

@PostMapping(path = { "/v1/apps/{appId}/participants/{userId}/sendSmsMessage", "/v3/studies/{appId}/participants/{userId}/sendSmsMessage" })
@ResponseStatus(HttpStatus.ACCEPTED)
public StatusMessage sendSmsMessageForWorker(@PathVariable String appId, @PathVariable String userId) {
    getAuthenticatedSession(WORKER);
    App app = appService.getApp(appId);
    SmsTemplate template = parseJson(SmsTemplate.class);
    participantService.sendSmsMessage(app, userId, template);
    return new StatusMessage("Message sent.");
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) SmsTemplate(org.sagebionetworks.bridge.models.apps.SmsTemplate) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 2 with SmsTemplate

use of org.sagebionetworks.bridge.models.apps.SmsTemplate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantServiceTest method sendSmsMessageThrowsIfPhoneUnverified.

@Test(expectedExceptions = BadRequestException.class)
public void sendSmsMessageThrowsIfPhoneUnverified() {
    when(accountService.getAccount(any())).thenReturn(Optional.of(account));
    account.setPhone(TestConstants.PHONE);
    account.setPhoneVerified(false);
    SmsTemplate template = new SmsTemplate("This is a test ${appShortName}");
    participantService.sendSmsMessage(APP, ID, template);
}
Also used : SmsTemplate(org.sagebionetworks.bridge.models.apps.SmsTemplate) Test(org.testng.annotations.Test)

Example 3 with SmsTemplate

use of org.sagebionetworks.bridge.models.apps.SmsTemplate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantServiceTest method sendSmsMessageThrowsIfBlankMessage.

@Test(expectedExceptions = BadRequestException.class)
public void sendSmsMessageThrowsIfBlankMessage() {
    SmsTemplate template = new SmsTemplate("    ");
    participantService.sendSmsMessage(APP, ID, template);
}
Also used : SmsTemplate(org.sagebionetworks.bridge.models.apps.SmsTemplate) Test(org.testng.annotations.Test)

Example 4 with SmsTemplate

use of org.sagebionetworks.bridge.models.apps.SmsTemplate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantServiceTest method sendSmsMessageThrowsIfNoPhone.

@Test(expectedExceptions = BadRequestException.class)
public void sendSmsMessageThrowsIfNoPhone() {
    when(accountService.getAccount(any())).thenReturn(Optional.of(account));
    SmsTemplate template = new SmsTemplate("This is a test ${appShortName}");
    participantService.sendSmsMessage(APP, ID, template);
}
Also used : SmsTemplate(org.sagebionetworks.bridge.models.apps.SmsTemplate) Test(org.testng.annotations.Test)

Example 5 with SmsTemplate

use of org.sagebionetworks.bridge.models.apps.SmsTemplate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantServiceTest method sendSmsMessage.

@Test
public void sendSmsMessage() {
    when(accountService.getAccount(any())).thenReturn(Optional.of(account));
    account.setHealthCode(HEALTH_CODE);
    account.setPhone(TestConstants.PHONE);
    account.setPhoneVerified(true);
    SmsTemplate template = new SmsTemplate("This is a test ${appShortName}");
    participantService.sendSmsMessage(APP, ID, template);
    verify(smsService).sendSmsMessage(eq(ID), smsProviderCaptor.capture());
    SmsMessageProvider provider = smsProviderCaptor.getValue();
    assertEquals(provider.getPhone(), TestConstants.PHONE);
    assertEquals(provider.getSmsRequest().getMessage(), "This is a test Bridge");
    assertEquals(provider.getSmsType(), "Promotional");
}
Also used : SmsTemplate(org.sagebionetworks.bridge.models.apps.SmsTemplate) SmsMessageProvider(org.sagebionetworks.bridge.sms.SmsMessageProvider) Test(org.testng.annotations.Test)

Aggregations

SmsTemplate (org.sagebionetworks.bridge.models.apps.SmsTemplate)6 Test (org.testng.annotations.Test)5 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)2 App (org.sagebionetworks.bridge.models.apps.App)1 SmsMessageProvider (org.sagebionetworks.bridge.sms.SmsMessageProvider)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1