diff --git a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/UserSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/UserSpec.scala index 8a840087fa..9d38569890 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/UserSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/UserSpec.scala @@ -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("a.b@example.com") == Left(UserErrorMessages.UsernameInvalid) - ) + val invalid = List("a_2.3!", "a_2-3", "a.b@example.com") + 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("j.doe@example.com").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)