mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-11-19 05:08:56 -06:00
Remove SendouQ options with a single value: groupAfterMorph's liker, insertFromPrevious's PREPARING default and the test-only currentViewByUserId
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
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:
@@ -184,7 +184,6 @@ export const action = defineAction(
|
||||
await SQGroupRepository.insertFromPrevious({
|
||||
previousGroupId: body.previousGroupId,
|
||||
memberUserIds: previousGroup.members.map((m) => m.id),
|
||||
status: "ACTIVE",
|
||||
});
|
||||
|
||||
await refreshSendouQInstance();
|
||||
@@ -259,7 +258,6 @@ export const action = defineAction(
|
||||
await SQGroupRepository.insertFromPrevious({
|
||||
previousGroupId: viewerGroup.id,
|
||||
memberUserIds: survivors.map((m) => m.id),
|
||||
status: "ACTIVE",
|
||||
});
|
||||
} catch (error) {
|
||||
// a concurrent voter may have already created the successor
|
||||
|
||||
@@ -221,7 +221,6 @@ describe("insert", () => {
|
||||
await SQGroupRepository.insertFromPrevious({
|
||||
previousGroupId: alphaGroupId,
|
||||
memberUserIds: alphaMembers.map((member) => member.id),
|
||||
status: "ACTIVE",
|
||||
});
|
||||
const votesBefore = await fetchVotes(alphaGroupId);
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ export async function findCurrentGroups() {
|
||||
vc: eb.ref("User.vc"),
|
||||
}).as("members"),
|
||||
])
|
||||
// != INACTIVE (same set as ACTIVE or PREPARING) so the partial
|
||||
// != INACTIVE (same set as ACTIVE, PREPARING or READY_CHECK) so the partial
|
||||
// group_status_active index applies
|
||||
.where("Group.status", "!=", "INACTIVE")
|
||||
.groupBy("Group.id")
|
||||
@@ -179,13 +179,10 @@ export async function insert(args: CreateGroupArgs) {
|
||||
type CreateGroupFromPreviousGroupArgs = {
|
||||
previousGroupId: number;
|
||||
memberUserIds: number[];
|
||||
status?: Exclude<Tables["Group"]["status"], "INACTIVE">;
|
||||
};
|
||||
export async function insertFromPrevious(
|
||||
args: CreateGroupFromPreviousGroupArgs,
|
||||
) {
|
||||
const status = args.status ?? "PREPARING";
|
||||
|
||||
return db.transaction().execute(async (trx) => {
|
||||
const previousGroup = await trx
|
||||
.selectFrom("Group")
|
||||
@@ -226,7 +223,7 @@ export async function insertFromPrevious(
|
||||
.values({
|
||||
chatRoomId,
|
||||
inviteCode: shortNanoid(),
|
||||
status,
|
||||
status: "ACTIVE",
|
||||
matchmade: previousGroup.matchmade,
|
||||
})
|
||||
.returning("id")
|
||||
|
||||
@@ -154,7 +154,6 @@ export const action = defineAction(
|
||||
if (!ourGroup || !theirGroup) return null;
|
||||
|
||||
const { id: survivingGroupId } = groupAfterMorph({
|
||||
liker: "THEM",
|
||||
ourGroup,
|
||||
theirGroup,
|
||||
});
|
||||
|
||||
@@ -198,51 +198,6 @@ describe("SendouQ", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("currentViewByUserId", () => {
|
||||
beforeEach(async () => {
|
||||
await users.create(8);
|
||||
});
|
||||
|
||||
test("returns 'default' when user not in any group", async () => {
|
||||
await refreshSendouQInstance();
|
||||
|
||||
const view = SendouQ.currentViewByUserId(users.id(1));
|
||||
|
||||
expect(view).toBe("default");
|
||||
});
|
||||
|
||||
test("returns 'preparing' when user in PREPARING group", async () => {
|
||||
await createGroup([1], { status: "PREPARING" });
|
||||
await refreshSendouQInstance();
|
||||
|
||||
const view = SendouQ.currentViewByUserId(users.id(1));
|
||||
|
||||
expect(view).toBe("preparing");
|
||||
});
|
||||
|
||||
test("returns 'match' when user in ACTIVE group with matchId", async () => {
|
||||
await SQMatchFactory.create({
|
||||
alphaUserIds: userIds([1, 2, 3, 4]),
|
||||
bravoUserIds: userIds([5, 6, 7, 8]),
|
||||
});
|
||||
|
||||
await refreshSendouQInstance();
|
||||
|
||||
const view = SendouQ.currentViewByUserId(users.id(1));
|
||||
|
||||
expect(view).toBe("match");
|
||||
});
|
||||
|
||||
test("returns 'looking' when user in ACTIVE group without matchId", async () => {
|
||||
await createGroup([1], { status: "ACTIVE" });
|
||||
await refreshSendouQInstance();
|
||||
|
||||
const view = SendouQ.currentViewByUserId(users.id(1));
|
||||
|
||||
expect(view).toBe("looking");
|
||||
});
|
||||
});
|
||||
|
||||
describe("findOwnGroup", () => {
|
||||
beforeEach(async () => {
|
||||
await users.create(8);
|
||||
|
||||
@@ -113,18 +113,6 @@ class SendouQClass {
|
||||
}));
|
||||
}
|
||||
|
||||
/** The current view state for a user based on their group status. */
|
||||
currentViewByUserId(userId: number) {
|
||||
const ownGroup = this.findOwnGroup(userId);
|
||||
|
||||
if (!ownGroup) return "default";
|
||||
if (ownGroup.status === "PREPARING") return "preparing";
|
||||
if (ownGroup.matchId) return "match";
|
||||
if (ownGroup.status === "READY_CHECK") return "ready";
|
||||
|
||||
return "looking";
|
||||
}
|
||||
|
||||
/** The user's group, or undefined if not in one. */
|
||||
findOwnGroup(userId: number) {
|
||||
return this.groups.find((group) =>
|
||||
|
||||
@@ -1,34 +1,20 @@
|
||||
import type { Tables } from "~/db/tables";
|
||||
import { databaseTimestampToDate } from "~/utils/dates";
|
||||
import type { GroupExpiryStatus } from "../q-types";
|
||||
import type { SQGroup } from "./SendouQ.server";
|
||||
|
||||
// group expires in 30min without actions performed
|
||||
const GROUP_EXPIRES_IN_MS = 30 * 60 * 1000;
|
||||
const GROUP_EXPIRING_SOON_IN_MS = 10 * 60 * 1000;
|
||||
|
||||
/** Whose settings two morphing groups keep: the bigger group's, or at equal size the liked group's. */
|
||||
export function groupAfterMorph({
|
||||
/** Whose settings two morphing groups keep: the bigger group's, or at equal size ours (the liked group's). */
|
||||
export function groupAfterMorph<Group extends { members: unknown[] }>({
|
||||
ourGroup,
|
||||
theirGroup,
|
||||
liker,
|
||||
}: {
|
||||
ourGroup: SQGroup;
|
||||
theirGroup: SQGroup;
|
||||
liker: "US" | "THEM";
|
||||
ourGroup: Group;
|
||||
theirGroup: Group;
|
||||
}) {
|
||||
const ourMembers = ourGroup.members ?? [];
|
||||
const theirMembers = theirGroup.members ?? [];
|
||||
|
||||
if (ourMembers.length > theirMembers.length) {
|
||||
return ourGroup;
|
||||
}
|
||||
|
||||
if (theirMembers.length > ourMembers.length) {
|
||||
return theirGroup;
|
||||
}
|
||||
|
||||
if (liker === "US") {
|
||||
if (theirGroup.members.length > ourGroup.members.length) {
|
||||
return theirGroup;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user