Revert "Merge pull request 'Complete Housekeeping migration and /ase cutover' (#52) from codex/housekeeping-complete into main"

This reverts commit 488b6e57c4, reversing
changes made to b506b4499a.
This commit is contained in:
Simo committed 2026-08-30 21:31:34 +02:00
1 parent 488b6e57c4
commit b1ddda66ff
802 files changed
+61370 -76659

No files matched your search

+151 -125
View File
@@ -1,30 +1,95 @@
// @ts-nocheck
import { beforeEach, describe, expect, it, vi } from "vitest";
import { requirePermission } from "@/lib/admin/guard";
import { rcon } from "@/lib/services/rcon";
import {
bulkBan,
bulkGiveBadge,
bulkGiveCurrency,
bulkUnban,
setTradeLock,
} from "./bulk-users";
const { execute } = vi.hoisted(() => ({ execute: vi.fn() }));
vi.mock("@/features/housekeeping/domains/people/services/mutations", () => ({
createPeopleMutationInvocation: vi.fn((staff, correlationId) => ({
expectedActorId: staff.id,
correlationId,
legacy: true,
})),
peopleMutationService: { execute },
}));
const {
deleteWhere,
insertValues,
updateWhere,
selectLimit,
selectWhereResolved,
onDuplicateKeyUpdate,
} = vi.hoisted(() => {
const deleteWhere = vi.fn().mockResolvedValue([{ affectedRows: 3 }]);
const onDuplicateKeyUpdate = vi.fn().mockResolvedValue([{ affectedRows: 1 }]);
const insertValues = vi.fn(() => ({
onDuplicateKeyUpdate,
// biome-ignore lint/suspicious/noThenProperty: Drizzle query thenable mock
then(resolve, reject) {
return Promise.resolve([{ insertId: 1 }]).then(resolve, reject);
},
}));
const updateWhere = vi.fn().mockResolvedValue([{ affectedRows: 1 }]);
const selectLimit = vi.fn().mockResolvedValue([]);
/** Rows returned when a select chain is awaited without `.limit()`. */
const selectWhereResolved = vi.fn().mockResolvedValue([]);
return {
deleteWhere,
insertValues,
updateWhere,
selectLimit,
selectWhereResolved,
onDuplicateKeyUpdate,
};
});
vi.mock("@/lib/admin/guard", () => ({ requirePermission: vi.fn() }));
vi.mock("@/lib/permissions", () => ({
PERMS: { USERS_EDIT: "admin.users.edit" },
}));
vi.mock("@/lib/permissions", () => ({ PERMS: { USERS_EDIT: "users.edit" } }));
vi.mock("@/lib/db", () => ({
db: {},
User: {},
UsersCurrency: {},
db: {
delete: vi.fn(() => ({ where: deleteWhere })),
insert: vi.fn(() => ({ values: insertValues })),
update: vi.fn(() => ({
set: vi.fn(() => ({ where: updateWhere })),
})),
select: vi.fn(() => ({
from: vi.fn(() => ({
where: vi.fn(() => ({
limit: selectLimit,
// biome-ignore lint/suspicious/noThenProperty: Drizzle query thenable mock
then(resolve, reject) {
return selectWhereResolved().then(resolve, reject);
},
})),
})),
})),
transaction: vi.fn(),
},
Ban: { userId: "userId", id: "id" },
User: {
id: "id",
credits: "credits",
username: "username",
online: "online",
},
UsersCurrency: { userId: "userId", type: "type", amount: "amount" },
UsersBadges: {
id: "id",
userId: "userId",
badgeCode: "badgeCode",
slotId: "slotId",
},
Sanctions: { id: "id", habboId: "habboId" },
UsersSettings: {
userId: "userId",
canTrade: "canTrade",
tradelockAmount: "tradelockAmount",
},
}));
vi.mock("@/lib/services/rcon", () => ({
rcon: {
giveCredits: vi.fn(),
giveDuckets: vi.fn(),
givePointsGotw: vi.fn(),
giveBadge: vi.fn(),
},
}));
vi.mock("@/lib/services/staff-activity", () => ({ logStaffActivity: vi.fn() }));
@@ -33,122 +98,83 @@ const staff = { id: 1, rank: 7, username: "admin" };
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(requirePermission).mockResolvedValue(staff as never);
execute.mockImplementation(async (context, operation, input) => ({
ok: true,
data: {
before: { input },
after: {
completed: operation === "users.bulk-unban" ? 3 : 2,
total: Array.isArray(input.userIds) ? input.userIds.length : 1,
failedIds: [],
},
output: operation === "user.trade-lock" ? input : undefined,
deleteWhere.mockResolvedValue([{ affectedRows: 3 }]);
insertValues.mockImplementation(() => ({
onDuplicateKeyUpdate,
// biome-ignore lint/suspicious/noThenProperty: Drizzle query thenable mock
then(resolve, reject) {
return Promise.resolve([{ insertId: 1 }]).then(resolve, reject);
},
correlationId: context.correlationId,
}));
onDuplicateKeyUpdate.mockResolvedValue([{ affectedRows: 1 }]);
updateWhere.mockResolvedValue([{ affectedRows: 1 }]);
selectLimit.mockResolvedValue([]);
selectWhereResolved.mockResolvedValue([]);
});
describe("legacy bulk user wrappers", () => {
it("preserves result shapes while delegating the exact operations", async () => {
await expect(bulkUnban({ userIds: [1, 2, 3] })).resolves.toEqual({
ok: true,
data: { unbanned: 3, total: 3 },
describe("bulkUnban", () => {
it("unbans users", async () => {
const r = await bulkUnban({ userIds: [1, 2, 3] });
expect(r.ok).toBe(true);
expect(r.data).toEqual({ unbanned: 3, total: 3 });
});
});
describe("bulkBan", () => {
it("bans users", async () => {
const r = await bulkBan({
userIds: [1, 2],
reason: "Spam",
duration: 3600,
});
await expect(
bulkBan({ userIds: [1, 2], reason: "Spam", duration: 3600 }),
).resolves.toEqual({ ok: true, data: { banned: 2 } });
await expect(
bulkGiveCurrency({ userIds: [1], amount: 100, type: "credits" }),
).resolves.toEqual({
ok: true,
data: { given: 2, total: 1, failedIds: [] },
expect(r.ok).toBe(true);
expect(r.data.banned).toBe(2);
expect(insertValues).toHaveBeenCalledTimes(2);
});
});
describe("bulkGiveCurrency", () => {
it("gives credits", async () => {
const r = await bulkGiveCurrency({
userIds: [1],
amount: 100,
type: "credits",
});
await expect(
bulkGiveBadge({ userIds: [1], badgeCode: "ADM" }),
).resolves.toEqual({
ok: true,
data: { given: 2, total: 1, failedIds: [] },
expect(r.data.given).toBe(1);
expect(rcon.giveCredits).toHaveBeenCalledWith(1, 100);
expect(updateWhere).toHaveBeenCalled();
});
it("gives pixels", async () => {
const r = await bulkGiveCurrency({
userIds: [2],
amount: 50,
type: "pixels",
});
expect(r.data.given).toBe(1);
expect(rcon.giveDuckets).toHaveBeenCalledWith(2, 50);
expect(onDuplicateKeyUpdate).toHaveBeenCalled();
});
it("gives points", async () => {
const r = await bulkGiveCurrency({
userIds: [3],
amount: 25,
type: "points",
});
expect(r.data.given).toBe(1);
expect(rcon.givePointsGotw).toHaveBeenCalledWith(3, 25);
expect(onDuplicateKeyUpdate).toHaveBeenCalled();
});
});
expect(execute.mock.calls.map((call) => call[1])).toEqual([
"users.bulk-unban",
"users.bulk-ban",
"users.bulk-currency",
"users.bulk-badge",
]);
describe("bulkGiveBadge", () => {
it("gives badge to user", async () => {
selectLimit.mockResolvedValueOnce([]);
selectWhereResolved.mockResolvedValueOnce([{ maxSlot: 5 }]);
const r = await bulkGiveBadge({ userIds: [1], badgeCode: "ADM" });
expect(r.data.given).toBe(1);
expect(insertValues).toHaveBeenCalled();
expect(rcon.giveBadge).toHaveBeenCalledWith(1, "ADM");
});
it("preserves the trade-lock API and exact normalized payload", async () => {
await expect(
setTradeLock({ userId: 9, untilUnix: 1234.8 }),
).resolves.toEqual({
ok: true,
data: { userId: 9, untilUnix: 1234 },
});
expect(execute).toHaveBeenLastCalledWith(
expect.objectContaining({ expectedActorId: 1 }),
"user.trade-lock",
{ userId: 9, untilUnix: 1234 },
);
});
it.each([
[
"currency",
"users.bulk-currency",
() => bulkGiveCurrency({ userIds: [7], amount: 100, type: "credits" }),
],
[
"badge",
"users.bulk-badge",
() => bulkGiveBadge({ userIds: [7], badgeCode: "ADM" }),
],
] as const)(
"restores the pre-Task12 legacy result when %s RCON throws after the database commit",
async (_kind, operation, invoke) => {
execute.mockResolvedValueOnce({
ok: true,
data: {
before: { completed: 0, total: 1, failedIds: [] },
after: {
completed: 1,
total: 1,
failedIds: [],
externalSyncFailures: [
{
userId: 7,
reason:
"Database applied; emulator sync failed. Do not retry automatically.",
},
],
},
completion: {
status: "partial",
external: "failed",
audit: "persisted",
},
},
correlationId: "legacy-external-sync-failure",
completion: {
status: "partial",
external: "failed",
audit: "persisted",
},
});
await expect(invoke()).resolves.toEqual({
ok: true,
data: {
given: 0,
total: 1,
failedIds: [{ userId: 7, reason: "Database error" }],
},
});
expect(execute).toHaveBeenCalledWith(
expect.anything(),
operation,
expect.anything(),
);
},
);
});