Skip to content

Commit

Permalink
feat(NotificationUtils): Add field for SMS consent date.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Nov 15, 2023
1 parent f1bc548 commit e489d7a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import spark.Request;
import spark.Response;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -116,6 +117,7 @@ public VerificationResult sendVerificationText(Request req, Response res) {
if (verification.getStatus().equals("pending")) {
otpUser.phoneNumber = phoneNumber;
otpUser.isPhoneNumberVerified = false;
otpUser.smsConsentDate = new Date();
otpUser.notificationChannel.add(OtpUser.Notification.SMS);
Persistence.otpUsers.replace(otpUser.id, otpUser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public enum Notification {
*/
public String phoneNumber;

/**
* The date when consent was given by user to receive SMS messages, as required by Twilio,
* see https://www.twilio.com/docs/verify/sms#consent-and-opt-in-policy.
* If the user starts the phone verification process, this field is populated
* just before the verification code is sent.
*/
public Date smsConsentDate;

/**
* The user's preferred locale, in language tag format
* e.g. 'en-US', 'fr-FR', 'es-ES', 'zh-CN', etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Date;

import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.opentripplanner.middleware.testutils.PersistenceTestUtils.createUser;
Expand Down Expand Up @@ -94,12 +95,17 @@ public void canSendSmsNotification() {
*/
@Test
public void canSendTwilioVerificationText() {
Assertions.assertNull(user.smsConsentDate);
Date beforeVerificationDate = new Date();
Verification verification = NotificationUtils.sendVerificationText(
// Note: phone number is configured in setup method above.
user.phoneNumber
);
LOG.info("Verification status: {}", verification.getStatus());
Assertions.assertNotNull(verification.getSid());
Date afterVerificationDate = new Date();
Assertions.assertTrue(user.smsConsentDate.getTime() >= beforeVerificationDate.getTime());
Assertions.assertTrue(user.smsConsentDate.getTime() <= afterVerificationDate.getTime());
}

/**
Expand Down

0 comments on commit e489d7a

Please sign in to comment.