Jest test bulk delete requesters

We are creating an app that lets our customer delete requester based on certain conditions.

Test file that creates 150 requesters

  test('check if num created requesters equal the number created in loop', async () => {
    const freshApi = new FreshApi(args);
    const numberOfRequesters = 150;
    let requestersCreated = 0;

    for (let index = 0; index < numberOfRequesters; index++) {
      const random = Math.floor(Math.random() * 1000000);
      console.log(`${index} created the random value ${random}`);
      await'requesters', {
        primary_email: `${makeEmail(10)}${random}`,
        first_name: 'Testarinna',
        work_phone_number: '12345',
        mobile_phone_number: '7251546',


After they have been created,we are running a test file that do a bunk delete (/forget in this case).

Have now been running the file a couple of times and I get a 404 error instead of the expected 204. However sometimes we can do the bulk delete without any errors.

When we are getting the 404 error the updated_at property for the requesterid has changed just one minute before the date stamp is thrown in our catch block.

Test 1:
“updated_at”: “2023-02-01T09:42:21Z”,
DATE => Wed, 01 Feb 2023 09:43:21 GMT

Test 2
“updated_at”: “2023-02-01T10:00:17Z”,
DATE => Wed, 01 Feb 2023 10:01:02 GMT

Test 3
“updated_at”: “2023-02-01T10:47:23Z”,
DATE => Wed, 01 Feb 2023 10:48:14 GMT

All of the above errors hit when the index is 100. Did think that this could be due to pagination. However as this is not a GET request I don´t see how this can be realted to pagination and don´t see anything reagrding this in the api docs as well.

The code to delete the requester created:

      if (requestersToBeDeleted.length) {
        await freshApi.forgotFilteredRequesters({
          filteredRequesters: requestersToBeDeleted,

        let requestersDeleted = 0;
        for (let index = 0; index < requestersToBeDeleted.length; index++) {
          console.log('REQUESTER ID =>', requestersToBeDeleted[index].id);
          var deleteRequester = await freshApi
            .then((res) => console.log(res));
          console.log('deleteRequester => ', deleteRequester);
          console.log('requestersDeleted =>', requestersDeleted);
          console.log('requestersToBeDeleted =>', requestersToBeDeleted.length);
    } catch (error) {
      const date = new Date(;
      console.log('ERROR [test]=> ', error, 'DATE =>', date.toUTCString());

Moreover, for this we have implemented the npm package limiter so that we don´t encounter any 429 errors.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.