Improve app deletion tests with defensive cleanup and order tracking
Update delete-force-warnings.test.mjs to include user_app_orders in cleanup, add a defensive sweep for orphaned apps, and ensure app IDs are tracked for all app deletion test cases.
This commit is contained in:
@@ -81,10 +81,32 @@ after(async () => {
|
||||
await pool.query(`DELETE FROM group_apps WHERE app_id = ANY($1::int[])`, [
|
||||
createdAppIds,
|
||||
]);
|
||||
await pool.query(
|
||||
`DELETE FROM user_app_orders WHERE app_id = ANY($1::int[])`,
|
||||
[createdAppIds],
|
||||
);
|
||||
await pool.query(`DELETE FROM apps WHERE id = ANY($1::int[])`, [
|
||||
createdAppIds,
|
||||
]);
|
||||
}
|
||||
|
||||
// Defensive sweep: kill any leftover apps whose slug matches a test prefix
|
||||
// (clean_app_*, busy_app_*, force_app_*). This guards against the case
|
||||
// where a test crashes between INSERT and the createdAppIds.push above.
|
||||
const sweep = await pool.query(
|
||||
`SELECT id FROM apps
|
||||
WHERE slug LIKE 'clean_app_%'
|
||||
OR slug LIKE 'busy_app_%'
|
||||
OR slug LIKE 'force_app_%'`,
|
||||
);
|
||||
if (sweep.rowCount > 0) {
|
||||
const ids = sweep.rows.map((r) => r.id);
|
||||
await pool.query(`DELETE FROM app_opens WHERE app_id = ANY($1::int[])`, [ids]);
|
||||
await pool.query(`DELETE FROM app_permissions WHERE app_id = ANY($1::int[])`, [ids]);
|
||||
await pool.query(`DELETE FROM group_apps WHERE app_id = ANY($1::int[])`, [ids]);
|
||||
await pool.query(`DELETE FROM user_app_orders WHERE app_id = ANY($1::int[])`, [ids]);
|
||||
await pool.query(`DELETE FROM apps WHERE id = ANY($1::int[])`, [ids]);
|
||||
}
|
||||
if (createdGroupIds.length) {
|
||||
await pool.query(`DELETE FROM group_apps WHERE group_id = ANY($1::int[])`, [
|
||||
createdGroupIds,
|
||||
@@ -218,6 +240,7 @@ test("DELETE /api/apps/:id without dependents succeeds (no force needed)", async
|
||||
[slug],
|
||||
);
|
||||
const id = a.rows[0].id;
|
||||
createdAppIds.push(id);
|
||||
|
||||
const res = await fetch(`${API_BASE}/api/apps/${id}`, {
|
||||
method: "DELETE",
|
||||
@@ -274,6 +297,7 @@ test("DELETE /api/apps/:id?force=true deletes app and writes audit log", async (
|
||||
[slug],
|
||||
);
|
||||
const appId = a.rows[0].id;
|
||||
createdAppIds.push(appId);
|
||||
|
||||
const g = await pool.query(
|
||||
`INSERT INTO groups (name, description_en) VALUES ($1, 'g') RETURNING id`,
|
||||
|
||||
Reference in New Issue
Block a user