mardi 13 mars 2018

FakeRequest withMultipartFormDataBody "Missing boundary header"

I am writing controller tests with Play 2.6

I have a file upload that absolutely works outside test scenario but when I do a fake request, I get stuck with this:

A client error occurred: Missing boundary header

here is my request:

    def createMultipartFile(file: File) : MultipartFormData[TemporaryFile] = {
      MultipartFormData(Map[String,Seq[String]](),
        List(FilePart("file","",Some("Content-Type: multipart/form-data"),SingletonTemporaryFileCreator.create(file.toPath))), List())
    }
    val data = createMultipartFile(sampleCSV)
    val controller = app.injector.instanceOf[RefundableController]
    val request = FakeRequest().withMultipartFormDataBody(data)
    val result = controller.addRefundableRules().apply(request)
    assert(status(result) === 200)

tried adding a header manually but that obviously didn't work

how am i supposed to add a boundary?

Aucun commentaire:

Enregistrer un commentaire