'how do I test express endpoints without actually creating a user object?

I would like to create an Jest test to test this endpoint. I have been able to deal with the checkjwt function, but I am still struggling with testing the post. The issue is that every time I test this route I create a new user.. and so afterward I have to use the delete method so that I can delete the ID that has been created.

usersRouter.post("/", checkJwt, async (req, res ) => {
  const email = req.body.email;
  const password = req.body.password;

  const data = await getMgmtApiJwt();
  const token = await data.access_token;
  const options = {
    method: 'POST',
    url: `https://dev-bb1or4ie.us.auth0.com/api/v2/users`,
    headers: {
      'authorization': `Bearer ${token}`, 
      'content-type': 'application/json'
    },
    json: true,
    data: {
      email: email,
      password: password,
      connection: process.env.AUTH0_CONNECTION
    }
  }
  try {
    const rest = await axios(options);
    const id = rest.data.identities[0].user_id
    return res.status(201).json({ message: "user has been created", id: id });
  }
  catch (err) {
    return res.status(500).json({ message: err})
  }
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source