Files
starr-philproperties/apps/e2e/helpers/cleanup.js
T
kennethobsequio 05f27e34d7 asset viewer now viewing on tabs
Tabs is better for this yay

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-08-28 19:34:10 +08:00

35 lines
1.3 KiB
JavaScript

const { Course } = require('../../api/models/courses/courses.mdl');
const Unit = require('../../api/models/courses/units.mdl');
const Lesson = require('../../api/models/courses/lessons.mdl');
const { TaskList, Task } = require('../../api/models/task/task.mdl');
const Advertisement = require('../../api/models/advertisements/advertisements.mdl');
const TierPlan = require('../../api/models/tiers/tier_plans.mdl');
const { Op } = require('sequelize');
const QA_PREFIX = '[QA-TEST';
const TARGETS = [
{ model: Task, column: 'name' },
{ model: TaskList, column: 'name' },
{ model: Advertisement, column: 'headline' },
{ model: Unit, column: 'title' },
{ model: Lesson, column: 'title' },
{ model: Course, column: 'title' },
{ model: TierPlan, column: 'label' },
];
/** Hard-deletes every QA-TEST-prefixed fixture row across all modules this suite touches. */
async function cleanupQaTestFixtures() {
const removed = {};
for (const { model, column } of TARGETS) {
const count = await model.destroy({
where: { [column]: { [Op.like]: `${QA_PREFIX}%` } },
force: true, // hard delete, not just paranoid soft-delete — mirrors the manual "archive then permanently delete" cleanup flow
});
if (count) removed[model.name] = count;
}
return removed;
}
module.exports = { cleanupQaTestFixtures, QA_PREFIX };