I need an action method to get the file loaded, and I also want to check it. But my test is throwing an error
My action:
def upload = Action.async(parse.multipartFormData) { request => val multipart = request.body val optFile = multipart.files.toList.headOption.map(_.ref.file) optFile match { case None => Future.successful(Ok("got none")) case Some(file) => Future.successful(Ok("got some")) } }
I want to check this method, but get an error:
My test
"create notes" in { val temp = SingletonTemporaryFileCreator.create("test", "png") val tempFile = TemporaryFile(temp) val filePart = FilePart[TemporaryFile](key = "image", filename = "debug.png", contentType = Some("image/png"), ref = tempFile) val form = MultipartFormData(dataParts = Map(), files = Seq(filePart), badParts = Seq(), missingFileParts = Seq()) val notesController = new NotesController() val result = notesController.upload().apply(FakeRequest(POST, "/notes/upload").withMultipartFormDataBody(form)) status(result) mustEqual OK }
Error:
[error] found : play.api.libs.iteratee.Iteratee[Array[Byte],play.api.mvc.Result] [error] required: scala.concurrent.Future[play.api.mvc.Result] [error] status(result) mustEqual OK [error] ^ [error] one error found [error] (root/test:compileIncremental) Compilation failed
source share