Skip to content

Commit

Permalink
ID-779 Add some new fields to user profiles (#1209)
Browse files Browse the repository at this point in the history
* ID-779 Add some new fields to user profiles

* more test coverage

* update swagger docs
  • Loading branch information
tlangs authored Sep 12, 2023
1 parent 0f38d31 commit 05c01b3
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/main/resources/swagger/api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7770,6 +7770,12 @@ components:
description:
The Terms of Service url, "app.terra.bio/#terms-of-service", which a user
must include to show they accept the Terms of Service
department:
type: string
description: User's department within an institution
interestInTerra:
type: string
description: A string of comma-separated values of why the User is interested in Terra
PublishConfigurationIngest:
required:
- configurationName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ object ModelJsonProtocol extends WorkspaceJsonSupport with SprayJsonSupport {
implicit val impFireCloudKeyValue = jsonFormat2(FireCloudKeyValue)
implicit val impThurloeKeyValue = jsonFormat2(ThurloeKeyValue)
implicit val impThurloeKeyValues = jsonFormat2(ThurloeKeyValues)
implicit val impBasicProfile = jsonFormat10(BasicProfile)
implicit val impProfile = jsonFormat11(Profile.apply)
implicit val impBasicProfile = jsonFormat12(BasicProfile)
implicit val impProfile = jsonFormat13(Profile.apply)
implicit val impProfileWrapper = jsonFormat2(ProfileWrapper)
implicit val impProfileKVP = jsonFormat2(ProfileKVP)
implicit val impTerraPreference = jsonFormat2(TerraPreference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ case class BasicProfile (
programLocationState: String,
programLocationCountry: String,
termsOfService: Option[String],
researchArea: Option[String]
researchArea: Option[String],
department: Option[String],
interestInTerra: Option[String],
) extends mappedPropVals {
require(ProfileValidator.nonEmpty(firstName), "first name must be non-empty")
require(ProfileValidator.nonEmpty(lastName), "last name must be non-empty")
Expand All @@ -52,7 +54,9 @@ case class Profile (
programLocationCountry: String,
researchArea: Option[String],
linkedNihUsername: Option[String] = None,
linkExpireTime: Option[Long] = None
linkExpireTime: Option[Long] = None,
department: Option[String],
interestInTerra: Option[String],
) extends mappedPropVals {
require(ProfileValidator.nonEmpty(firstName), "first name must be non-empty")
require(ProfileValidator.nonEmpty(lastName), "last name must be non-empty")
Expand All @@ -67,9 +71,9 @@ case class Profile (
object Profile {

// increment this number every time you make a change to the user-provided profile fields
val currentVersion:Int = 4
val currentVersion:Int = 5

val requiredKeys = List("firstName", "lastName", "title", "institute", "programLocationCity",
val requiredKeys = List("firstName", "lastName", "title", "institute", "department", "programLocationCity",
"programLocationState", "programLocationCountry")

def apply(wrapper: ProfileWrapper): Profile = {
Expand All @@ -95,7 +99,9 @@ object Profile {
linkExpireTime = mappedKVPs.get("linkExpireTime") match {
case Some(time) => Some(time.toLong)
case _ => None
}
},
department = mappedKVPs.get("department"),
interestInTerra = mappedKVPs.get("interestInTerra")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
programLocationCity = randomString,
programLocationState = randomString,
programLocationCountry = randomString,
termsOfService = Some(termsOfServiceUrl)
termsOfService = Some(termsOfServiceUrl),
department = Some(randomString),
interestInTerra = Some(randomString)
)
basicProfile shouldNot be(null)
}
Expand All @@ -38,7 +40,9 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
programLocationCity = randomString,
programLocationState = randomString,
programLocationCountry = randomString,
termsOfService = Some(termsOfServiceUrl)
termsOfService = Some(termsOfServiceUrl),
department = Some(randomString),
interestInTerra = Some(randomString)
)
basicProfile shouldNot be(null)
}
Expand All @@ -52,7 +56,9 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
researchArea = Some(randomString),
programLocationCity = randomString,
programLocationState = randomString,
programLocationCountry = randomString
programLocationCountry = randomString,
department = Some(randomString),
interestInTerra = Some(randomString)
)
profile shouldNot be(null)
}
Expand All @@ -66,7 +72,9 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
researchArea = Some(randomString),
programLocationCity = randomString,
programLocationState = randomString,
programLocationCountry = randomString
programLocationCountry = randomString,
department = Some(randomString),
interestInTerra = Some(randomString)
)
profile shouldNot be(null)
}
Expand All @@ -80,10 +88,28 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
researchArea = Some(randomString),
programLocationCity = randomString,
programLocationState = randomString,
programLocationCountry = randomString
programLocationCountry = randomString,
department = Some(randomString),
interestInTerra = Some(randomString)
)
profile shouldNot be(null)
}

"Profile instantiated with ProfileWrapper is valid" in {
val pw = ProfileWrapper("123", List(
FireCloudKeyValue(Some("firstName"), Some("test-firstName")),
FireCloudKeyValue(Some("lastName"), Some("test-lastName")),
FireCloudKeyValue(Some("title"), Some("test-title")),
FireCloudKeyValue(Some("institute"), Some("test-institute")),
FireCloudKeyValue(Some("department"), Some("test-department")),
FireCloudKeyValue(Some("programLocationCity"), Some("test-programLocationCity")),
FireCloudKeyValue(Some("programLocationState"), Some("test-programLocationState")),
FireCloudKeyValue(Some("programLocationCountry"), Some("test-programLocationCountry")),
FireCloudKeyValue(Some("contactEmail"), Some("[email protected]"))
))
val profile = Profile(pw)
profile shouldNot be(null)
}
}

"Incorrectly formed profiles" - {
Expand All @@ -99,6 +125,8 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
programLocationState = "",
programLocationCountry = "",
None,
None,
None,
None
)
}
Expand All @@ -115,7 +143,9 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
researchArea = Some(randomString),
programLocationCity = randomString,
programLocationState = randomString,
programLocationCountry = randomString
programLocationCountry = randomString,
department = Some(randomString),
interestInTerra = Some(randomString)
)
}
ex shouldNot be(null)
Expand All @@ -134,15 +164,15 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
))

"getString" - {
"returns None if key doesn't exist" - {
"returns None if key doesn't exist" in {
val targetKey = "nonexistent"
// assert key does not exist in sample data
pw.keyValuePairs.find(_.key.contains(targetKey)) shouldBe None
// and therefore getString returns None
val actual = ProfileUtils.getString(targetKey, pw)
actual shouldBe None
}
"returns None if key exists but value doesn't" - {
"returns None if key exists but value doesn't" in {
val targetKey = "imnothing"
// assert key exists in sample data with no value
val targetKV = pw.keyValuePairs.find(_.key.contains(targetKey))
Expand All @@ -152,14 +182,14 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
val actual = ProfileUtils.getString(targetKey, pw)
actual shouldBe None
}
"returns Some(String) if key and value exist" - {
"returns Some(String) if key and value exist" in {
val targetKey = "imastring"
val actual = ProfileUtils.getString(targetKey, pw)
actual shouldBe Some("hello")
}
}
"getLong" - {
"returns None if key doesn't exist" - {
"returns None if key doesn't exist" in {
val targetKey = "nonexistent"
// assert key does not exist in sample data
pw.keyValuePairs.find(_.key.contains(targetKey)) shouldBe None
Expand All @@ -168,7 +198,7 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
actual shouldBe None

}
"returns None if key exists but value doesn't" - {
"returns None if key exists but value doesn't" in {
val targetKey = "imnothing"
// assert key exists in sample data with no value
val targetKV = pw.keyValuePairs.find(_.key.contains(targetKey))
Expand All @@ -178,15 +208,15 @@ class ProfileSpec extends AnyFreeSpec with Matchers {
val actual = ProfileUtils.getLong(targetKey, pw)
actual shouldBe None
}
"returns None if key and value exist but value is not a Long" - {
"returns None if key and value exist but value is not a Long" in {
val targetKey = "imnotalong"
// assert the key exists
ProfileUtils.getString(targetKey, pw) shouldBe Some("not-a-long")
// but can't be parsed as a Long
val actual = ProfileUtils.getLong(targetKey, pw)
actual shouldBe None
}
"returns Some(Long) if key and value exist and value is Long-able" - {
"returns Some(Long) if key and value exist and value is Long-able" in {
val targetKey = "imalong"
val actual = ProfileUtils.getLong(targetKey, pw)
actual shouldBe Some(1556724034L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ final class RegisterApiServiceSpec extends BaseServiceSpec with RegisterApiServi
programLocationCity = randomString,
programLocationState = randomString,
programLocationCountry = randomString,
termsOfService = if (hasTermsOfService) Some(termsOfServiceUrl) else None
termsOfService = if (hasTermsOfService) Some(termsOfServiceUrl) else None,
department = Some(randomString),
interestInTerra = Some(randomString)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class UserApiServiceSpec extends BaseServiceSpec with SamMockserverUtils
programLocationCity = randomAlpha(),
programLocationState = randomAlpha(),
programLocationCountry = randomAlpha(),
termsOfService = None
termsOfService = None,
department = Some(randomAlpha()),
interestInTerra = Some(randomAlpha())
)
val allProperties: Map[String, String] = fullProfile.propertyValueMap

Expand Down

0 comments on commit 05c01b3

Please sign in to comment.