7

I need an action method to receive file upload and I want to test this also. But my test is throwing 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 test this method but getting 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
surenyonjan
  • 1,989
  • 2
  • 15
  • 25

0 Answers0