diff options
Diffstat (limited to 'src/test/scala/xyz/driver/core')
-rw-r--r-- | src/test/scala/xyz/driver/core/JsonTest.scala | 15 | ||||
-rw-r--r-- | src/test/scala/xyz/driver/core/PhoneNumberTest.scala | 19 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/core/JsonTest.scala b/src/test/scala/xyz/driver/core/JsonTest.scala index 2aa3572..5c1274c 100644 --- a/src/test/scala/xyz/driver/core/JsonTest.scala +++ b/src/test/scala/xyz/driver/core/JsonTest.scala @@ -247,6 +247,21 @@ class JsonTest extends WordSpec with Matchers with Inspectors { json.phoneNumberFormat.read(phoneJson) }.getMessage shouldBe "Invalid phone number" } + + "parse phone number from string" in { + JsString("+14243039608").convertTo[PhoneNumber] shouldBe PhoneNumber("1", "4243039608") + } + } + + "Path matcher for PhoneNumber" should { + "read valid phone number" in { + val string = "+14243039608" + val phone = PhoneNumber("1", "4243039608") + + val matcher = PathMatcher("foo") / PhoneInPath + + matcher(Uri.Path("foo") / string / "bar") shouldBe Matched(Uri.Path./("bar"), Tuple1(phone)) + } } "Json format for ADT mappings" should { diff --git a/src/test/scala/xyz/driver/core/PhoneNumberTest.scala b/src/test/scala/xyz/driver/core/PhoneNumberTest.scala index 384c7be..7ccf0d8 100644 --- a/src/test/scala/xyz/driver/core/PhoneNumberTest.scala +++ b/src/test/scala/xyz/driver/core/PhoneNumberTest.scala @@ -76,4 +76,23 @@ class PhoneNumberTest extends FlatSpec with Matchers { List(PhoneNumber("45", "27452522"), PhoneNumber("86", "13452522256")) } + "PhoneNumber.toCompactString/toE164String" should "produce phone number in international format without whitespaces" in { + PhoneNumber.parse("+1 800 5252225").get.toCompactString shouldBe "+18005252225" + PhoneNumber.parse("+1 800 5252225").get.toE164String shouldBe "+18005252225" + } + + "PhoneNumber.toHumanReadableString" should "produce nice readable result for different countries" in { + PhoneNumber.parse("+14154234567").get.toHumanReadableString shouldBe "+1 415-423-4567" + + PhoneNumber.parse("+78005252225").get.toHumanReadableString shouldBe "+7 800 525-22-25" + + PhoneNumber.parse("+41219437898").get.toHumanReadableString shouldBe "+41 21 943 78 98" + } + + it should "throw an IllegalArgumentException if the PhoneNumber object is not parsable/valid" in { + intercept[IllegalStateException] { + PhoneNumber("+123", "1238123120938120938").toHumanReadableString + }.getMessage should include("+123 1238123120938120938 is not a valid number") + } + } |