-
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
1 parent
4d2f452
commit b7c3e08
Showing
1 changed file
with
27 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ package org.knora.webapi.slice.admin.domain.model | |
|
||
import zio.test.* | ||
|
||
import dsp.valueobjects.IriErrorMessages | ||
|
||
object UserSpec extends ZIOSpecDefault { | ||
private val validUserIri = "http://rdfh.ch/users/jDEEitJESRi3pDaDjjQ1WQ" | ||
private val userIriWithUUIDVersion3 = "http://rdfh.ch/users/cCmdcpn2MO211YYOplR1hQ" | ||
|
@@ -22,46 +20,42 @@ object UserSpec extends ZIOSpecDefault { | |
|
||
private val usernameSuite = suite("Username")( | ||
test("Username must not be empty") { | ||
assertTrue(Username.from("") == Left(UserErrorMessages.UsernameMissing)) | ||
assertTrue(Username.from("") == Left("Username cannot be empty.")) | ||
}, | ||
test("Username may contain alphanumeric characters, underscore and dot") { | ||
assertTrue(Username.from("a_2.3").isRight) | ||
}, | ||
test("Username has to be at least 4 characters long") { | ||
assertTrue(Username.from("abc") == Left(UserErrorMessages.UsernameInvalid)) | ||
assertTrue(Username.from("abc") == Left("Username is invalid.")) | ||
}, | ||
test("Username has to be at most 50 characters long") { | ||
assertTrue( | ||
Username | ||
.from("123456789012345678901234567890123456789012345678901") | ||
.left | ||
.exists(_.equals(UserErrorMessages.UsernameInvalid)) | ||
Username.from("123456789012345678901234567890123456789012345678901") == Left("Username is invalid.") | ||
) | ||
}, | ||
test("Username must not contain other characters") { | ||
assertTrue( | ||
Username.from("a_2.3!") == Left(UserErrorMessages.UsernameInvalid), | ||
Username.from("a_2-3") == Left(UserErrorMessages.UsernameInvalid), | ||
Username.from("[email protected]") == Left(UserErrorMessages.UsernameInvalid) | ||
) | ||
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(UserErrorMessages.UsernameInvalid)) | ||
assertTrue(Username.from(".abc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not end with a dot") { | ||
assertTrue(Username.from("abc.") == Left(UserErrorMessages.UsernameInvalid)) | ||
assertTrue(Username.from("abc.") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not contain two dots in a row") { | ||
assertTrue(Username.from("a..bc") == Left(UserErrorMessages.UsernameInvalid)) | ||
assertTrue(Username.from("a..bc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not start with an underscore") { | ||
assertTrue(Username.from("_abc") == Left(UserErrorMessages.UsernameInvalid)) | ||
assertTrue(Username.from("_abc") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not end with an underscore") { | ||
assertTrue(Username.from("abc_") == Left(UserErrorMessages.UsernameInvalid)) | ||
assertTrue(Username.from("abc_") == Left("Username is invalid.")) | ||
}, | ||
test("Username must not contain two underscores in a row") { | ||
assertTrue(Username.from("a__bc") == Left(UserErrorMessages.UsernameInvalid)) | ||
assertTrue(Username.from("a__bc") == Left("Username is invalid.")) | ||
} | ||
) | ||
|
||
|
@@ -70,22 +64,26 @@ object UserSpec extends ZIOSpecDefault { | |
assertTrue(Email.from("[email protected]").isRight) | ||
}, | ||
test("Email must not be empty") { | ||
assertTrue(Email.from("") == Left(UserErrorMessages.EmailMissing)) | ||
assertTrue(Email.from("") == Left("Email cannot be empty.")) | ||
}, | ||
test("Email must not be a username") { | ||
assertTrue(Email.from("j.doe") == Left(UserErrorMessages.EmailInvalid)) | ||
assertTrue(Email.from("j.doe") == Left("Email is invalid.")) | ||
} | ||
) | ||
|
||
private val iriSuite = suite("UserIri")( | ||
test("pass an empty value and return an error") { | ||
assertTrue(UserIri.from("") == Left(UserErrorMessages.UserIriMissing)) | ||
assertTrue(UserIri.from("") == Left("User IRI cannot be empty.")) | ||
}, | ||
test("pass an invalid value and return an error") { | ||
assertTrue(UserIri.from(invalidIri) == Left(UserErrorMessages.UserIriInvalid(invalidIri))) | ||
assertTrue(UserIri.from(invalidIri) == Left(s"User IRI: $invalidIri is invalid.")) | ||
}, | ||
test("pass an invalid IRI containing unsupported UUID version and return an error") { | ||
assertTrue(UserIri.from(userIriWithUUIDVersion3) == Left(IriErrorMessages.UuidVersionInvalid)) | ||
assertTrue( | ||
UserIri.from(userIriWithUUIDVersion3) == Left( | ||
"Invalid UUID used to create IRI. Only versions 4 and 5 are supported." | ||
) | ||
) | ||
}, | ||
test("pass a valid value and successfully create value object") { | ||
assertTrue(UserIri.from(validUserIri).isRight) | ||
|
@@ -94,7 +92,7 @@ object UserSpec extends ZIOSpecDefault { | |
|
||
private val givenNameSuite = suite("GivenName")( | ||
test("pass an empty value and return an error") { | ||
assertTrue(GivenName.from("") == Left(UserErrorMessages.GivenNameMissing)) | ||
assertTrue(GivenName.from("") == Left("GivenName cannot be empty.")) | ||
}, | ||
test("pass a valid value and successfully create value object") { | ||
assertTrue(GivenName.from(validGivenName).isRight) | ||
|
@@ -103,7 +101,7 @@ object UserSpec extends ZIOSpecDefault { | |
|
||
private val familyNameSuite = suite("FamilyName")( | ||
test("pass an empty value and return an error") { | ||
assertTrue(FamilyName.from("") == Left(UserErrorMessages.FamilyNameMissing)) | ||
assertTrue(FamilyName.from("") == Left("FamilyName cannot be empty.")) | ||
}, | ||
test("pass a valid value and successfully create value object") { | ||
assertTrue(FamilyName.from(validFamilyName).isRight) | ||
|
@@ -112,7 +110,7 @@ object UserSpec extends ZIOSpecDefault { | |
|
||
private val passwordSuite = suite("Password")( | ||
test("pass an empty value and return an error") { | ||
assertTrue(Password.from("") == Left(UserErrorMessages.PasswordMissing)) | ||
assertTrue(Password.from("") == Left("Password cannot be empty.")) | ||
}, | ||
test("pass a valid value and successfully create value object") { | ||
assertTrue(Password.from(validPassword).isRight) | ||
|
@@ -121,7 +119,7 @@ object UserSpec extends ZIOSpecDefault { | |
|
||
private val passwordHashSuite = suite("PasswordHash")( | ||
test("pass an empty value and return an error") { | ||
assertTrue(PasswordHash.from("", pwStrength) == Left(UserErrorMessages.PasswordMissing)) | ||
assertTrue(PasswordHash.from("", pwStrength) == Left("Password cannot be empty.")) | ||
}, | ||
test("pass a valid value and successfully create value object") { | ||
val passwordString = "password1" | ||
|
@@ -141,7 +139,7 @@ object UserSpec extends ZIOSpecDefault { | |
) | ||
}, | ||
test("pass an invalid password strength value and return an error") { | ||
assertTrue(PasswordStrength.from(-1) == Left(UserErrorMessages.PasswordStrengthInvalid)) | ||
assertTrue(PasswordStrength.from(-1) == Left("PasswordStrength is invalid.")) | ||
}, | ||
test("pass a valid password strength value and create value object") { | ||
assertTrue(PasswordStrength.from(12).isRight) | ||
|