Hide sidebar sub status for friends once the tournament has started
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
E2E Tests / publish-docs-screenshots (push) Has been cancelled

This commit is contained in:
Kalle
2026-11-05 19:43:42 +02:00
parent 451d092afd
commit 1ca083e128
3 changed files with 71 additions and 13 deletions

View File

@@ -1,7 +1,11 @@
import { addDays, subDays } from "date-fns";
import { beforeEach, describe, expect, test } from "vitest";
import * as FriendRequestFactory from "~/db/seed/factories/FriendRequestFactory";
import * as FriendshipFactory from "~/db/seed/factories/FriendshipFactory";
import * as TournamentFactory from "~/db/seed/factories/TournamentFactory";
import * as TournamentLFGTeamFactory from "~/db/seed/factories/TournamentLFGTeamFactory";
import * as UserFactory from "~/db/seed/factories/UserFactory";
import { dateToDatabaseTimestamp } from "~/utils/dates";
import { withUserId } from "~/utils/Test";
import * as FriendRepository from "./FriendRepository.server";
@@ -419,6 +423,56 @@ describe("findByUserIdWithActivity", () => {
expect(result).toHaveLength(0);
});
const lookingTournamentNameOfFriend = async ({
startsAt,
regClosesAt,
}: {
startsAt: Date;
regClosesAt?: Date;
}) => {
await FriendshipFactory.create({
userOneId: users.id(1),
userTwoId: users.id(2),
});
const tournament = await TournamentFactory.create({
authorId: users.id(3),
name: "Looking Cup",
startTimes: [dateToDatabaseTimestamp(startsAt)],
regClosesAt: regClosesAt
? dateToDatabaseTimestamp(regClosesAt)
: undefined,
});
await TournamentLFGTeamFactory.create({
tournamentId: tournament.id,
userId: users.id(2),
});
const result = await FriendRepository.findByUserIdWithActivity(users.id(1));
return result.find((row) => row.id === users.id(2))?.tournamentName;
};
test("shows a friend looking for a team in an upcoming tournament", async () => {
expect(
await lookingTournamentNameOfFriend({ startsAt: addDays(new Date(), 1) }),
).toBe("Looking Cup");
});
test("ignores looking for a team in a tournament that has started", async () => {
expect(
await lookingTournamentNameOfFriend({ startsAt: subDays(new Date(), 7) }),
).toBeNull();
});
test("ignores looking for a team after registration has closed", async () => {
expect(
await lookingTournamentNameOfFriend({
startsAt: addDays(new Date(), 1),
regClosesAt: subDays(new Date(), 1),
}),
).toBeNull();
});
});
describe("updateOwnFriendshipPinned", () => {

View File

@@ -93,19 +93,18 @@ function withLfgJoins<QB extends SelectQueryBuilder<any, any, any>>(qb: QB) {
"=",
"TournamentTeamMember.tournamentTeamId",
)
.where((innerEb) =>
innerEb.or([
innerEb(
sql`json_extract("LookingTournament"."settings", '$.regClosesAt')`,
"is",
null,
),
innerEb(
sql<number>`json_extract("LookingTournament"."settings", '$.regClosesAt')`,
">",
nowTimestamp,
),
]),
.where(
sql<number>`coalesce(
"LookingTournament"."settings" ->> 'regClosesAt',
(
select min("CalendarEventDate"."startsAt")
from "CalendarEventDate"
inner join "CalendarEvent" on "CalendarEvent"."id" = "CalendarEventDate"."eventId"
where "CalendarEvent"."tournamentId" = "LookingTournament"."id"
)
)`,
">",
nowTimestamp,
),
),
),

View File

@@ -0,0 +1,5 @@
---
navItem: medal
type: bug
---
Friends who signed up as a sub no longer show in the sidebar as looking for a team in a tournament that already happened