aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorArthur Rand <arand@ucsc.edu>2018-05-16 05:55:27 -0700
committerGitHub <noreply@github.com>2018-05-16 05:55:27 -0700
commit57cd7aaf5a2154af698fddc39f4bff8fd3e4f6e7 (patch)
treeefc31d48b45c10d2d2b911ab1476f2c13e86c98c /src/test
parent803c76244bd7a4772f727e5b47f84bcc9f5adcd4 (diff)
downloaddriver-core-57cd7aaf5a2154af698fddc39f4bff8fd3e4f6e7.tar.gz
driver-core-57cd7aaf5a2154af698fddc39f4bff8fd3e4f6e7.tar.bz2
driver-core-57cd7aaf5a2154af698fddc39f4bff8fd3e4f6e7.zip
[API-1584] Change AuthCredentials to accept a string identifier (#166)v1.9.3
* make email optional, add optional phone number to AuthCredentials * make AuthCredentials take a String instead of an email * wrap phone number parsing in Try * add json formatter for AuthCredentials * try val
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/xyz/driver/core/JsonTest.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/core/JsonTest.scala b/src/test/scala/xyz/driver/core/JsonTest.scala
index b845a44..fed2a9d 100644
--- a/src/test/scala/xyz/driver/core/JsonTest.scala
+++ b/src/test/scala/xyz/driver/core/JsonTest.scala
@@ -11,6 +11,7 @@ import xyz.driver.core.json._
import xyz.driver.core.time.provider.SystemTimeProvider
import spray.json._
import xyz.driver.core.TestTypes.CustomGADT
+import xyz.driver.core.auth.AuthCredentials
import xyz.driver.core.domain.{Email, PhoneNumber}
import xyz.driver.core.json.enumeratum.HasJsonFormat
import xyz.driver.core.tagging.Taggable
@@ -311,4 +312,32 @@ class JsonTest extends FlatSpec with Matchers {
inetAddressFormat.read(invalidAddress)
}
}
+
+ "AuthCredentials format" should "read and write correct JSON" in {
+ val email = Email("someone", "noehere.com")
+ val phoneId = PhoneNumber.parse("1 207 8675309")
+ val password = "nopassword"
+
+ phoneId.isDefined should be(true) // test this real quick
+
+ val emailAuth = AuthCredentials(email.toString, password)
+ val pnAuth = AuthCredentials(phoneId.get.toString, password)
+
+ val emailWritten = authCredentialsFormat.write(emailAuth)
+ emailWritten should be("""{"identifier":"someone@noehere.com","password":"nopassword"}""".parseJson)
+
+ val phoneWritten = authCredentialsFormat.write(pnAuth)
+ phoneWritten should be("""{"identifier":"+1 2078675309","password":"nopassword"}""".parseJson)
+
+ val identifierEmailParsed =
+ authCredentialsFormat.read("""{"identifier":"someone@nowhere.com","password":"nopassword"}""".parseJson)
+ var written = authCredentialsFormat.write(identifierEmailParsed)
+ written should be("{\"identifier\":\"someone@nowhere.com\",\"password\":\"nopassword\"}".parseJson)
+
+ val emailEmailParsed =
+ authCredentialsFormat.read("""{"email":"someone@nowhere.com","password":"nopassword"}""".parseJson)
+ written = authCredentialsFormat.write(emailEmailParsed)
+ written should be("{\"identifier\":\"someone@nowhere.com\",\"password\":\"nopassword\"}".parseJson)
+
+ }
}