Work through the full list of supported locales when choosing a language for voice verification.

This commit is contained in:
Jon Chambers
2021-03-10 18:13:39 -05:00
committed by Jon Chambers
parent ca2f7d2eed
commit 0bc1369e04
7 changed files with 97 additions and 27 deletions

View File

@@ -308,7 +308,7 @@ public class AccountControllerTest {
assertThat(response.getStatus()).isEqualTo(200);
verify(smsSender).deliverVoxVerification(eq(SENDER), anyString(), eq(Optional.empty()));
verify(smsSender).deliverVoxVerification(eq(SENDER), anyString(), eq(Collections.emptyList()));
verify(abusiveHostRules).getAbusiveHostRulesFor(eq(NICE_HOST));
}
@@ -325,7 +325,7 @@ public class AccountControllerTest {
assertThat(response.getStatus()).isEqualTo(200);
verify(smsSender).deliverVoxVerification(eq(SENDER), anyString(), eq(Optional.of(Locale.forLanguageTag("pt-BR"))));
verify(smsSender).deliverVoxVerification(eq(SENDER), anyString(), eq(Locale.LanguageRange.parse("pt-BR")));
verify(abusiveHostRules).getAbusiveHostRulesFor(eq(NICE_HOST));
}
@@ -342,7 +342,24 @@ public class AccountControllerTest {
assertThat(response.getStatus()).isEqualTo(200);
verify(smsSender).deliverVoxVerification(eq(SENDER), anyString(), eq(Optional.of(Locale.forLanguageTag("en-US"))));
verify(smsSender).deliverVoxVerification(eq(SENDER), anyString(), eq(Locale.LanguageRange.parse("en-US;q=1, ar-US;q=0.9, fa-US;q=0.8, zh-Hans-US;q=0.7, ru-RU;q=0.6, zh-Hant-US;q=0.5")));
verify(abusiveHostRules).getAbusiveHostRulesFor(eq(NICE_HOST));
}
@Test
public void testSendCodeVoiceInvalidLocale() throws Exception {
Response response =
resources.getJerseyTest()
.target(String.format("/v1/accounts/voice/code/%s", SENDER))
.queryParam("challenge", "1234-push")
.request()
.header("Accept-Language", "This is not a reasonable Accept-Language value")
.header("X-Forwarded-For", NICE_HOST)
.get();
assertThat(response.getStatus()).isEqualTo(400);
verify(smsSender, never()).deliverVoxVerification(eq(SENDER), anyString(), any());
verify(abusiveHostRules).getAbusiveHostRulesFor(eq(NICE_HOST));
}

View File

@@ -77,6 +77,20 @@ public class VoiceVerificationControllerTest {
assertThat(response.readEntity(String.class)).isXmlEqualTo(FixtureHelpers.fixture("fixtures/voice_verification_en_us.xml"));
}
@Test
public void testTwimlMultipleLocales() {
Response response =
resources.getJerseyTest()
.target("/v1/voice/description/123456")
.queryParam("l", "es-MX")
.queryParam("l", "ru-RU")
.request()
.post(null);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.readEntity(String.class)).isXmlEqualTo(FixtureHelpers.fixture("fixtures/voice_verification_ru.xml"));
}
@Test
public void testTwimlMissingLocale() {
Response response =

View File

@@ -18,7 +18,7 @@ import static org.mockito.Mockito.*;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.util.List;
import java.util.Locale;
import java.util.Locale.LanguageRange;
import java.util.Optional;
import javax.annotation.Nonnull;
import org.junit.Before;
@@ -136,7 +136,7 @@ public class TwilioSmsSenderTest {
TwilioConfiguration configuration = createTwilioConfiguration();
TwilioSmsSender sender = new TwilioSmsSender("http://localhost:" + wireMockRule.port(), configuration, dynamicConfigurationManager);
boolean success = sender.deliverVoxVerification("+14153333333", "123-456", Optional.of(Locale.US)).join();
boolean success = sender.deliverVoxVerification("+14153333333", "123-456", LanguageRange.parse("en-US")).join();
assertThat(success).isTrue();
@@ -145,6 +145,27 @@ public class TwilioSmsSenderTest {
.withRequestBody(matching("To=%2B14153333333&From=%2B1415(1111111|2222222)&Url=https%3A%2F%2Ftest.com%2Fv1%2Fvoice%2Fdescription%2F123-456%3Fl%3Den-US")));
}
@Test
public void testSendVoxMultipleLocales() {
wireMockRule.stubFor(post(urlEqualTo("/2010-04-01/Accounts/" + ACCOUNT_ID + "/Calls.json"))
.withBasicAuth(ACCOUNT_ID, ACCOUNT_TOKEN)
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody("{\"price\": -0.00750, \"status\": \"completed\"}")));
TwilioConfiguration configuration = createTwilioConfiguration();
TwilioSmsSender sender = new TwilioSmsSender("http://localhost:" + wireMockRule.port(), configuration, dynamicConfigurationManager);
boolean success = sender.deliverVoxVerification("+14153333333", "123-456", LanguageRange.parse("en-US;q=1, ar-US;q=0.9, fa-US;q=0.8, zh-Hans-US;q=0.7, ru-RU;q=0.6, zh-Hant-US;q=0.5")).join();
assertThat(success).isTrue();
verify(1, postRequestedFor(urlEqualTo("/2010-04-01/Accounts/" + ACCOUNT_ID + "/Calls.json"))
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withRequestBody(matching("To=%2B14153333333&From=%2B1415(1111111|2222222)&Url=https%3A%2F%2Ftest.com%2Fv1%2Fvoice%2Fdescription%2F123-456%3Fl%3Den-US%26l%3Dar-US%26l%3Dfa-US%26l%3Dzh-US%26l%3Dru-RU%26l%3Dzh-US")));
}
@Test
public void testSendSmsFiveHundred() {
wireMockRule.stubFor(post(urlEqualTo("/2010-04-01/Accounts/" + ACCOUNT_ID + "/Messages.json"))
@@ -179,7 +200,7 @@ public class TwilioSmsSenderTest {
TwilioConfiguration configuration = createTwilioConfiguration();
TwilioSmsSender sender = new TwilioSmsSender("http://localhost:" + wireMockRule.port(), configuration, dynamicConfigurationManager);
boolean success = sender.deliverVoxVerification("+14153333333", "123-456", Optional.of(Locale.US)).join();
boolean success = sender.deliverVoxVerification("+14153333333", "123-456", LanguageRange.parse("en-US")).join();
assertThat(success).isFalse();