Unit testing a controller
We might have a simple project with a User model and UserRepo, defined as follows:
case class User(id: Option[Long], loginId: String, name: Option[String],
contactNo: Option[String], dob: Option[Long], address: Option[String])
object User{
implicit val userWrites = Json.writes[User]
}
trait UserRepo {
def authenticate(loginId: String, password: String): Boolean
def create(u: User, host: String, password: String): Option[Long]
def update(u: User): Boolean
def findByLogin(loginId: String): Option[User]
def delete(userId: Long): Boolean
def find(userId: Long): Option[User]
def getAll: Seq[User]
def updateStatus(userId: Long, isActive: Boolean): Int
def updatePassword(userId: Long, password: String): Int
}In this project, we need to test a getUser method of UserController—a controller that is defined to access user details, which are handled by the user model, where UserController is defined as follows:
object UserController extends Controller...