From 4d0c8c7e65c201fe004435dce1408ad22fae6916 Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Sun, 30 Aug 2026 21:06:40 +0200 Subject: [PATCH] test(housekeeping): finalize release evidence --- .../mutations-production-workflows.test.ts | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/features/housekeeping/domains/people/services/mutations-production-workflows.test.ts b/src/features/housekeeping/domains/people/services/mutations-production-workflows.test.ts index 6eeac817..513c4712 100644 --- a/src/features/housekeeping/domains/people/services/mutations-production-workflows.test.ts +++ b/src/features/housekeeping/domains/people/services/mutations-production-workflows.test.ts @@ -234,24 +234,60 @@ describe("People production workflow adapter", () => { expect(mocks.transaction).not.toHaveBeenCalled(); }); - it("checks every bulk target hierarchy before starting a mutation", async () => { + it("assigns an existing configured rank above 7 for a super-admin", async () => { mocks.resolveServerContext.mockResolvedValue({ ...context(), actor: { id: 42, username: "operator", rank: 8 }, - isSuperAdmin: false, + isSuperAdmin: true, }); - mocks.selectQueue.push([{ id: 7, rank: 8 }]); + mocks.selectQueue.push([target({ rank: 2 })]); + mocks.execute.mockResolvedValueOnce([[{ id: 9 }], []]); const result = await peopleMutationService.execute( invocation, - "users.bulk-ban", - { userIds: [7], duration: 3600, reason: "Denied" }, + "user.update", + { userId: 7, fields: { rank: 9 } }, ); - expect(result).toMatchObject({ ok: false, error: { code: "FORBIDDEN" } }); - expect(mocks.transaction).not.toHaveBeenCalled(); + expect(result).toMatchObject({ ok: true, data: { after: { rank: 9 } } }); + expect(mocks.updateSet).toHaveBeenCalledWith( + expect.objectContaining({ rank: 9 }), + ); + expect(mocks.transaction).toHaveBeenCalledTimes(1); }); + it.each([ + ["users.bulk-ban", { userIds: [7], duration: 3600, reason: "Denied" }], + ["users.bulk-unban", { userIds: [7] }], + ["users.bulk-currency", { userIds: [7], type: "credits", amount: 50 }], + ["users.bulk-badge", { userIds: [7], badgeCode: "ADM" }], + ] as const)( + "checks target hierarchy before starting %s", + async (operation, input) => { + mocks.resolveServerContext.mockResolvedValue({ + ...context(), + actor: { id: 42, username: "operator", rank: 8 }, + isSuperAdmin: false, + }); + mocks.selectQueue.push([{ id: 7, rank: 8 }]); + + const result = await peopleMutationService.execute( + invocation, + operation, + input, + ); + + expect(result).toMatchObject({ + ok: false, + error: { code: "FORBIDDEN" }, + }); + expect(mocks.transaction).not.toHaveBeenCalled(); + expect(mocks.insertValues).not.toHaveBeenCalled(); + expect(mocks.updateSet).not.toHaveBeenCalled(); + expect(mocks.deleteWhere).not.toHaveBeenCalled(); + }, + ); + it("preserves legacy bulk order, duplicates, totals, and StaffActivities", async () => { const ids = Array.from({ length: 101 }, (_, index) => (index % 2) + 1); mocks.selectQueue.push([