Testing - Strange behaviour 2 'client' requests inside the same test


#1

Hi

I’m getting confused about a situation and would like a second opinion on this.

Below is one of the tests for a Destroy method. If the item is really deleted, I should get a 400 status if I try to delete it again. But I’m getting a 200 status code. When I replicate this test with my server in dev mode, it works as expected and I get a 400 status code.
It’s not working only in the test.

Am I doing something wrong?

test('Should delete clinic if belongs to user', async ({ client, assert }) => {
  assert.plan(3)

  const user = await User.find(1)

  const data = {
    name: 'My Clinic',
    user_id: user.id
  }

  const newClinic = await Clinic.create(data)

  const response = await client
    .delete('/api/v1/clinics/' + newClinic.id)
    .loginVia(user)
    .end()

  response.assertStatus(200)
  response.assertJSONSubset({ data })

  const lastCheck = await client
    .delete('/api/v1/clinics/' + newClinic.id)
    .loginVia(user)
    .end()

  lastCheck.assertStatus(400)
})

ERRORS

  1. Should not find clinic after deleted
    expected 200 to equal 400
    200 => 400