Undelete a Test Case Folder

Hello,

I deleted a test case folder by mistake. I know that I can do sth like this but the problem is that I do not know the test case folder id. Could you please help me?

await testiny.testcaseFolder.undelete()

Best regards,
Mustafa

Hi Mustafa,

Do you still know the (partial) folder name? Then you could search for the folder in the console:

await testiny.testcaseFolder.find({
  includeDeleted: true, 
  filter: { 
    project_id: 1,
    is_deleted: true,
    title: { op: "like", value: "%partial folder name%"}
  }
});

Alternatively, you could also retrieve all folders that have been deleted since a timestamp:

await testiny.testcaseFolder.find({
  includeDeleted: true, 
  filter: { 
    project_id: 1,
    is_deleted: true,
    deleted_at: { op: "gte", value: "2024-11-29T00:00:00.000Z"} 
  }
});

or have been deleted in a time range:

await testiny.testcaseFolder.find({
  includeDeleted: true, 
  filter: { 
    project_id: 1,
    is_deleted: true,
    deleted_at: { op: "range", value: ["2024-11-29T12:05:30.000Z", "2024-11-29T12:05:31.000Z"]} 
  }
});

Then you can use the ID from the response to undelete the folder(s).

ETA: If you undelete a single folder, you might also want to undelete subfolders and contained test cases. See detailed answer below.

If you’re unable to undelete the folder, please let us know and with support access we can undelete it for you.

Best regards,
Hanna

Thanks for the quick response Hanna!

I found the id of the test case folder. However when I pass it like following, I get 404 error.

await testiny.testcaseFolder.undelete(1455)
POST https://app.testiny.io/api/v1/testcase-folder/bulk/undelete 404 (Not Found)
(anonymous) @ 16.bundle.377bc3f0.js:2
xhr @ 16.bundle.377bc3f0.js:2
he @ 16.bundle.377bc3f0.js:2
_request @ 16.bundle.377bc3f0.js:2
request @ 16.bundle.377bc3f0.js:2
(anonymous) @ 16.bundle.377bc3f0.js:2
internalRequest @ 14.bundle.ef7d1989.js:1
post @ 14.bundle.ef7d1989.js:1
undelete @ 14.bundle.ef7d1989.js:1
undelete @ 14.bundle.ef7d1989.js:1
(anonymous) @ VM959:1
14.bundle.ef7d1989.js:2 Uncaught i: Failed to undelete: not all items specified by id where found (entities must be deleted).
    at n.formatError (https://app.testiny.io/14.bundle.ef7d1989.js:1:38396)
    at n.internalRequest (https://app.testiny.io/14.bundle.ef7d1989.js:1:37926)
    at async n.undelete (https://app.testiny.io/14.bundle.ef7d1989.js:1:22239)
    at async <anonymous>:1:1

Thanks a lot.

You need to pass a parameter object, like this:

await testiny.testcaseFolder.undelete({ id: 1455})

:exclamation: However, this undeletes only a single folder! You might want to undelete its subfolders and its test cases:

Find all folders in deleted time range in your project:

await testiny.testcaseFolder.find({
  includeDeleted: true, 
  filter: { 
    project_id: 1,
    is_deleted: true, 
    deleted_at: { op: "range", value: ["2024-11-29T12:19:00.000Z", "2024-11-29T12:20:00.000Z"]} }
})

Find all test cases in deleted time range in your project:

await testiny.testcase.find({
  includeDeleted: true, 
  filter: { 
    project_id: 1,
    is_deleted: true, 
    deleted_at: { op: "range", value: ["2024-11-29T12:19:00.000Z", "2024-11-29T12:20:00.000Z"]} }
})

To undelete multiple folders (or test cases) at once, you can pass in multiple ids in an array like this:

await testiny.testcaseFolder.undelete(
  [{ id: 1455},{ id: 1456},...]
);

If you’re unsure, you can also send us a private message here or an email to our support team, with the information of which folder you would like to undelete and give us support access to your organization and we’ll undelete it for you. :slight_smile:

Best regards,
Hanna

Thanks a lot! It worked.