Skip to content

Commit 4ac73f4

Browse files
committed
allow to set an email and address as primary
1 parent 8342bec commit 4ac73f4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

core/src/main/scala/ch/linkyard/scim/model/User.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ object User:
9292
region: Option[String],
9393
postalCode: Option[String],
9494
country: Option[String],
95+
primary: Option[Boolean] = None,
9596
)
9697
case class EnterpriseUser(
9798
employeeNumber: Option[String],
@@ -102,7 +103,7 @@ object User:
102103
manager: Option[UserRef],
103104
)
104105
case class SimpleValue(value: String)
105-
case class ValueWithTypeAndDisplay(value: Option[String], display: Option[String], `type`: Option[String])
106+
case class ValueWithTypeAndDisplay(value: Option[String], display: Option[String] = None, `type`: Option[String] = None, primary: Option[Boolean] = None)
106107
case class UserRef(
107108
value: String,
108109
`$ref`: Option[String],

core/src/test/scala/ch/linkyard/scim/model/UserSpec.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ch.linkyard.scim.model.User.UserRef
88
import ch.linkyard.scim.model.Codecs.given
99

1010
import java.net.URI
11+
import ch.linkyard.scim.model.User.ValueWithTypeAndDisplay
1112

1213
class UserSpec extends AnyFunSpec with Matchers with OptionValues {
1314

@@ -28,12 +29,35 @@ class UserSpec extends AnyFunSpec with Matchers with OptionValues {
2829
json should include("urn:ietf:params:scim:schemas:core:2.0:User")
2930
}
3031

32+
it("should serialize primary email") {
33+
val json = User(User.Root(
34+
id = Some("2819c223-7f76-453a-919d-413861904646"),
35+
userName = "[email protected]",
36+
emails = Some(List(ValueWithTypeAndDisplay(Some("[email protected]"), None, None, Some(true))))
37+
)).json.noSpaces
38+
json should include("""{"value":"[email protected]","primary":true}""")
39+
}
40+
41+
it("should serialize multiple emails with type") {
42+
val json = User(User.Root(
43+
id = Some("2819c223-7f76-453a-919d-413861904646"),
44+
userName = "[email protected]",
45+
emails = Some(List(
46+
ValueWithTypeAndDisplay(Some("[email protected]"), Some("work"), None, Some(true)),
47+
ValueWithTypeAndDisplay(Some("[email protected]"), Some("home"), None),
48+
))
49+
)).json.noSpaces
50+
json should include("""{"value":"[email protected]","display":"work","primary":true}""")
51+
json should include("""{"value":"[email protected]","display":"home"}""")
52+
}
53+
3154
it("should parse 'userMinimal'") {
3255
val root = User(Jsons.userMinimal).rootOrDefault
3356
root.userName should be("[email protected]")
3457
root.id.value should be("2819c223-7f76-453a-919d-413861904646")
3558
root.name should be(None)
3659
}
60+
3761
it("should parse 'userMinimalExternal'") {
3862
val root = User(Jsons.userMinimalExternal).rootOrDefault
3963
root.userName should be("[email protected]")

0 commit comments

Comments
 (0)