-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,58 +12,6 @@ object UserSpec extends ZIOSpecDefault { | |
private val validGivenName = "John" | ||
private val validFamilyName = "Rambo" | ||
|
||
private val userSuite = suite("User")() | ||
|
||
private val usernameSuite = suite("Username")( | ||
test("Username must not be empty") { | ||
assertTrue(Username.from("") == Left("Username cannot be empty.")) | ||
}, | ||
test("Username may contain alphanumeric characters, underscore, hyphen and dot") { | ||
assertTrue(Username.from("a_2.3-4").isRight) | ||
}, | ||
test("Username has to be at least 4 characters long") { | ||
assertTrue(Username.from("abc") == Left("Username is invalid.")) | ||
}, | ||
test("Username has to be at most 50 characters long") { | ||
assertTrue( | ||
Username.from("123456789012345678901234567890123456789012345678901") == Left("Username is invalid."), | ||
) | ||
}, | ||
test("Username must not contain other characters") { | ||
val invalid = List("a_2.3!", "a_2,3", "[email protected]") | ||
check(Gen.fromIterable(invalid)) { i => | ||
assertTrue(Username.from(i) == Left("Username is invalid.")) | ||
} | ||
}, | ||
test("Username must not start with a dot") { | ||
assertTrue(Username.from(".abc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not end with a dot") { | ||
assertTrue(Username.from("abc.") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not contain two dots in a row") { | ||
assertTrue(Username.from("a..bc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not start with an underscore") { | ||
assertTrue(Username.from("_abc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not end with an underscore") { | ||
assertTrue(Username.from("abc_") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not contain two underscores in a row") { | ||
assertTrue(Username.from("a__bc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not start with an hyphen") { | ||
assertTrue(Username.from("-abc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not end with an hyphen") { | ||
assertTrue(Username.from("abc-") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not contain two hyphen in a row") { | ||
assertTrue(Username.from("a--bc") == Left("Username is invalid.")) | ||
}, | ||
) | ||
|
||
private val emailSuite = suite("Email")( | ||
test("Email must be a correct email address") { | ||
assertTrue(Email.from("[email protected]").isRight) | ||
|
@@ -76,68 +24,6 @@ object UserSpec extends ZIOSpecDefault { | |
}, | ||
) | ||
|
||
private val iriSuite = suite("UserIri")( | ||
test("pass an empty value and return an error") { | ||
assertTrue(UserIri.from("") == Left("User IRI cannot be empty.")) | ||
}, | ||
test("make new should create a valid user iri") { | ||
assertTrue(UserIri.makeNew.value.startsWith("http://rdfh.ch/users/")) | ||
}, | ||
test("built in users should be builtIn") { | ||
val builtInIris = Gen.fromIterable( | ||
Seq( | ||
"http://www.knora.org/ontology/knora-admin#AnonymousUser", | ||
"http://www.knora.org/ontology/knora-admin#SystemUser", | ||
"http://www.knora.org/ontology/knora-admin#AnonymousUser", | ||
), | ||
) | ||
check(builtInIris) { i => | ||
val userIri = UserIri.unsafeFrom(i) | ||
assertTrue(!userIri.isRegularUser, userIri.isBuiltInUser) | ||
} | ||
}, | ||
test("regular user iris should not be builtIn") { | ||
val builtInIris = Gen.fromIterable( | ||
Seq( | ||
"http://rdfh.ch/users/jDEEitJESRi3pDaDjjQ1WQ", | ||
"http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGE", | ||
), | ||
) | ||
check(builtInIris) { i => | ||
val userIri = UserIri.unsafeFrom(i) | ||
assertTrue(userIri.isRegularUser, !userIri.isBuiltInUser) | ||
} | ||
}, | ||
test("valid iris should be a valid iri") { | ||
val validIris = Gen.fromIterable( | ||
Seq( | ||
"http://rdfh.ch/users/jDEEitJESRi3pDaDjjQ1WQ", | ||
"http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGE", | ||
"http://www.knora.org/ontology/knora-admin#AnonymousUser", | ||
"http://www.knora.org/ontology/knora-admin#SystemUser", | ||
"http://www.knora.org/ontology/knora-admin#AnonymousUser", | ||
"http://rdfh.ch/users/mls-0807-import-user", | ||
"http://rdfh.ch/users/root", | ||
"http://rdfh.ch/users/images-reviewer-user", | ||
"http://rdfh.ch/users/AnythingAdminUser", | ||
"http://rdfh.ch/users/subotic", | ||
"http://rdfh.ch/users/_fH9FS-VRMiPPiIMRpjevA", | ||
), | ||
) | ||
check(validIris)(i => assertTrue(UserIri.from(i).isRight)) | ||
}, | ||
test("pass an invalid value and return an error") { | ||
val invalidIris = Gen.fromIterable( | ||
Seq( | ||
"Invalid IRI", | ||
"http://rdfh.ch/user/AnythingAdminUser", | ||
"http://rdfh.ch/users/AnythingAdminUser/", | ||
), | ||
) | ||
check(invalidIris)(i => assertTrue(UserIri.from(i) == Left(s"User IRI is invalid."))) | ||
}, | ||
) | ||
|
||
private val givenNameSuite = suite("GivenName")( | ||
test("pass an empty value and return an error") { | ||
assertTrue(GivenName.from("") == Left("GivenName cannot be empty.")) | ||
|
@@ -178,10 +64,7 @@ object UserSpec extends ZIOSpecDefault { | |
) | ||
|
||
val spec: Spec[Any, Any] = suite("UserSpec")( | ||
userSuite, | ||
usernameSuite, | ||
emailSuite, | ||
iriSuite, | ||
givenNameSuite, | ||
familyNameSuite, | ||
passwordSuite, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters