Don’t delete polls with options in the future (#273)

This commit is contained in:
Luke Vella 2022-08-05 16:47:10 +01:00 committed by GitHub
parent dac1041361
commit 2648be9b0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 9 deletions

View file

@ -75,10 +75,9 @@ test.beforeAll(async ({ request, baseURL }) => {
participantUrlId: "p6",
adminUrlId: "a6",
},
// Old demo poll
{
demo: true,
title: "Demo poll",
title: "Old demo poll",
id: "demo-poll-old",
type: "date",
userId: "user1",
@ -86,6 +85,15 @@ test.beforeAll(async ({ request, baseURL }) => {
participantUrlId: "p7",
adminUrlId: "a7",
},
{
title: "Inactive poll with future option",
id: "inactive-poll-future-option",
type: "date",
userId: "user1",
touchedAt: dayjs().add(-30, "days").toDate(),
participantUrlId: "p8",
adminUrlId: "a8",
},
],
});
@ -106,6 +114,21 @@ test.beforeAll(async ({ request, baseURL }) => {
value: "2022-02-24",
pollId: "deleted-poll-7d",
},
{
id: "option-4",
value: `${dayjs()
.add(10, "days")
.format("YYYY-MM-DDTHH:mm:ss")}/${dayjs()
.add(10, "days")
.add(1, "hour")
.format("YYYY-MM-DDTHH:mm:ss")}`,
pollId: "inactive-poll-future-option",
},
{
id: "option-5",
value: dayjs().add(-1, "days").format("YYYY-MM-DD"),
pollId: "inactive-poll",
},
],
});
@ -144,7 +167,7 @@ test.beforeAll(async ({ request, baseURL }) => {
});
expect(await res.json()).toMatchObject({
inactive: 1,
softDeleted: 1,
deleted: 2,
});
});
@ -252,6 +275,16 @@ test("should delete old demo poll", async () => {
expect(oldDemoPoll).toBeNull();
});
test("should not delete poll that has options in the future", async () => {
const futureOptionPoll = await prisma.poll.findFirst({
where: {
id: "inactive-poll-future-option",
},
});
expect(futureOptionPoll).not.toBeNull();
});
// Teardown
test.afterAll(async () => {
await prisma.$executeRaw`DELETE FROM polls WHERE id IN (${Prisma.join([
@ -263,4 +296,13 @@ test.afterAll(async () => {
"demo-poll-new",
"demo-poll-old",
])})`;
await prisma.$executeRaw`DELETE FROM options WHERE id IN (${Prisma.join([
"active-poll",
"deleted-poll-6d",
"deleted-poll-7d",
"still-active-poll",
"inactive-poll",
"demo-poll-new",
"demo-poll-old",
])})`;
});