How do I send Form Data (multipart/form-data) on @adonisjs/ace

I have a test which updates an organisation:

test('as a registered user I can update the organisation details', async ({ client }) => {
  newUser.email = 'organisation1@test.com'
  const user = await User.create(newUser)
  await client.get(`/organisations`).loginVia(user, 'jwt').end()

    const organisation = {
      business_name: 'business_name hehe',
      primary: '#4f9cf3',
      secondary: '#2f5784'
    }

   const form = new FormData()

   Object.keys(torganisation).forEach((key) => {
        form.append(key, organisation[key])
   })

    const response = await client
                          .patch(`/organisations`)
                          .loginVia(user, 'jwt')
                          .header('Content-Type', 'multipart/form-data')
                          .send(form)
                          .end()

  response.assertStatus(200)
})

the new FormData() is undefined, i guess its not available in node, so is there a way to send a multipart/form data on adonis ace? I cant see any solution online

1 Like

So i was just not reading more of the documentation, you can just use the .field()

const response = await client
                          .patch(`/organisations`)
                          .loginVia(user, 'jwt')
                          .field('business_name', 'business_name hehe')
                          .field('primary', '#4f9cf3')
                          .field('secondary', '#2f5784')
                          .end()

https://adonisjs.com/docs/4.0/api-tests#_multipart_requests

1 Like