AI Implementation feature(867): Admin Area Players Management (#56)

This commit was merged in pull request #56.
This commit is contained in:
2026-07-23 08:08:50 +00:00
parent 705530e71f
commit e4ccf0fe13
27 changed files with 2039 additions and 218 deletions
+39 -3
View File
@@ -5,7 +5,7 @@ process.env.FRONTEND_DIST = './frontend/dist';
import { Test } from '@nestjs/testing';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { HttpAdapterHost } from '@nestjs/core';
import { Repository } from 'typeorm';
import { DataSource, Repository } from 'typeorm';
import { getRepositoryToken } from '@nestjs/typeorm';
import { AppModule } from '../../backend/src/app.module';
import { GlobalExceptionFilter } from '../../backend/src/common/filters/global-exception.filter';
@@ -40,8 +40,44 @@ describe('Setup: POST /api/v1/setup/create-admin', () => {
});
beforeEach(async () => {
await refreshTokens.clear();
await users.clear();
// The deployment-wide last-admin triggers reject the deletion of
// the last admin row, which is exactly what `clear()` would attempt
// when a prior test left a sole admin in the table. Disable the
// triggers for the duration of the cleanup, then re-enable them.
const ds = app.get(DataSource);
await ds.query(`DROP TRIGGER IF EXISTS "trg_user_last_admin_update"`);
await ds.query(`DROP TRIGGER IF EXISTS "trg_user_last_admin_delete"`);
try {
await refreshTokens.clear();
await users.clear();
} finally {
await ds.query(`
CREATE TRIGGER IF NOT EXISTS "trg_user_last_admin_update"
BEFORE UPDATE OF "role" ON "user"
FOR EACH ROW
WHEN OLD."role" = 'admin' AND NEW."role" <> 'admin'
AND NOT EXISTS (
SELECT 1 FROM "user" AS "other"
WHERE "other"."role" = 'admin' AND "other"."id" <> OLD."id"
)
BEGIN
SELECT RAISE(ABORT, 'LAST_ADMIN');
END;
`);
await ds.query(`
CREATE TRIGGER IF NOT EXISTS "trg_user_last_admin_delete"
BEFORE DELETE ON "user"
FOR EACH ROW
WHEN OLD."role" = 'admin'
AND NOT EXISTS (
SELECT 1 FROM "user" AS "other"
WHERE "other"."role" = 'admin' AND "other"."id" <> OLD."id"
)
BEGIN
SELECT RAISE(ABORT, 'LAST_ADMIN');
END;
`);
}
});
it('creates the very first admin and exposes a session + cookie', async () => {