Skip to content

Commit

Permalink
Enhance E2E cleanup route to remove tags along with links and domains
Browse files Browse the repository at this point in the history
Updated the cleanup route to include the deletion of tags created during E2E tests. The route now retrieves and deletes tags that start with "e2e-" and were created more than one hour ago, improving the overall cleanup process.
  • Loading branch information
devkiran committed Jan 16, 2025
1 parent d189bf5 commit 1945830
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions apps/web/app/api/cron/cleanup/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const E2E_USER_ID = "clxz1q7c7000hbqx5ckv4r82h";
const E2E_WORKSPACE_ID = "clrei1gld0002vs9mzn93p8ik";

/***
This route is used to remove links and domains created during the E2E test.
This route is used to remove links, domains and tags created during the E2E test.
Runs every 6 hours (0 * / 6 * * *)
*/
export async function GET(req: Request) {
Expand All @@ -21,7 +21,7 @@ export async function GET(req: Request) {

const oneHourAgo = new Date(Date.now() - 1000 * 60 * 60);

const [links, domains] = await Promise.all([
const [links, domains, tags] = await Promise.all([
prisma.link.findMany({
where: {
userId: E2E_USER_ID,
Expand Down Expand Up @@ -54,6 +54,18 @@ export async function GET(req: Request) {
slug: true,
},
}),

prisma.tag.findMany({
where: {
projectId: E2E_WORKSPACE_ID,
name: {
startsWith: "e2e-",
},
createdAt: {
lt: oneHourAgo,
},
},
}),
]);

// Delete the links
Expand Down Expand Up @@ -82,7 +94,20 @@ export async function GET(req: Request) {
);
}

console.log(`Removed ${links.length} links and ${domains.length} domains`);
// Delete the tags
if (tags.length > 0) {
await prisma.tag.deleteMany({
where: {
id: {
in: tags.map((tag) => tag.id),
},
},
});
}

console.log(
`Removed ${links.length} links, ${domains.length} domains and ${tags.length} tags`,
);

return NextResponse.json({ status: "OK" });
} catch (error) {
Expand Down

0 comments on commit 1945830

Please sign in to comment.