This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
package space.kklochko.spring_rest_example.db.repositories
|
||||
|
||||
import groovy.sql.Sql
|
||||
import jakarta.persistence.EntityManager
|
||||
import space.kklochko.spring_rest_example.config.factories.LoadDataBaseConfigFromEnvFile
|
||||
import space.kklochko.spring_rest_example.config.models.DataBaseConfig
|
||||
import space.kklochko.spring_rest_example.db.factories.DataBaseConnection
|
||||
import space.kklochko.spring_rest_example.db.factories.EntityManagerConnection
|
||||
import space.kklochko.spring_rest_example.models.Token
|
||||
import space.kklochko.spring_rest_example.models.User
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Stepwise
|
||||
import spock.lang.Subject
|
||||
|
||||
@Stepwise
|
||||
class UserRepositorySpec extends Specification {
|
||||
def "Read one user"() {
|
||||
given: "I have a repo"
|
||||
@Subject
|
||||
UserRepository repo = new UserRepository()
|
||||
|
||||
when: "reading the entry"
|
||||
def result = repo.read(username)
|
||||
|
||||
then: "checking that the reading was successful"
|
||||
result
|
||||
|
||||
and: "the user has a role"
|
||||
with(result) {
|
||||
getRole() == expectedRole
|
||||
getPassword() == expectedPassword
|
||||
}
|
||||
|
||||
where: "the expected data"
|
||||
username || expectedRole | expectedPassword
|
||||
"admin" || "ADMIN" | "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918"
|
||||
"user" || "USER" | "04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb"
|
||||
}
|
||||
|
||||
def "Read one user and check if exists"() {
|
||||
given: "I have a repo"
|
||||
@Subject
|
||||
UserRepository repo = new UserRepository()
|
||||
|
||||
when: "reading the entry"
|
||||
def result = repo.read(username)
|
||||
|
||||
then: "checking that the reading was successful"
|
||||
isNull == (result == null)
|
||||
|
||||
where: "the expected data"
|
||||
username || isNull
|
||||
"admin" || false
|
||||
"user" || false
|
||||
"user2" || true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user