I'm trying to unit test a file upload through multipartFormData and returning status 200 if it returns back the uploaded url. However, I keep getting status 400 and unsure why its been unsucessful.
I've found online of the call needs to be writeable and have included a writeable class which i've imported as lazy val
"return a 200 if successful" in new SetUp {
val fakeFileName = "testImage.png"
val fakeUploadImageUrl = "https://s3.fakeImageUrl.png"
val imageFile = new File(fakeFileName)
val tempFile = TemporaryFile(imageFile)
val multipartFormData = new MultipartFormData(
dataParts = Map(),
files = Seq(FilePart[TemporaryFile]("file", fakeFileName, Some("text/plain"), tempFile)),
badParts = Seq()
)
when(imageService.uploadWebImage(any(), any())).thenReturn(Future.successful(fakeUploadImageUrl))
val request = FakeRequest(HttpVerbs.POST, s"/internal/challengesv2/v1/instances/image/$fakeFileName")
.withBody(multipartFormData)
val response = testController.uploadImage(fakeFileName).apply(request)
assert(status(response.run()) === 200)
assert(contentAsJson(response.run()) === Json.toJson(fakeUploadImageUrl))
}
expect 200 but returning 400