test: isolate chief upload fixture

This commit is contained in:
2026-08-08 03:39:47 +00:00
parent 8e65dc992d
commit 2d92114aa9
@@ -197,13 +197,23 @@ test('two users enlist, the engine advances three months, and only a chief uploa
} }
expect(enlisted.rows.every((general) => general.nation_id > 0)).toBe(true); expect(enlisted.rows.every((general) => general.nation_id > 0)).toBe(true);
// Appointment is fixture setup for the authorization boundary below. Enlistment and const waitForPaused = async (paused: boolean) => {
// month advancement above are performed exclusively by the real turn daemon. const deadline = Date.now() + 15_000;
while (Date.now() < deadline) {
const status = await admin.turnDaemon.status.query({ timeoutMs: 5_000 });
if (status?.lastError) throw new Error(`Turn daemon failed: ${status.lastError}`);
if (status?.paused === paused) return;
await sleep(200);
}
throw new Error(`Turn daemon did not become ${paused ? 'paused' : 'resumed'}.`);
};
const setOfficerLevels = async (aLevel: number, bLevel: number) => {
const connection = await db.connect(); const connection = await db.connect();
try { try {
await connection.query('BEGIN'); await connection.query('BEGIN');
await connection.query('UPDATE general SET officer_level = 5 WHERE id = $1', [generalAId]); await connection.query('UPDATE general SET officer_level = $2 WHERE id = $1', [generalAId, aLevel]);
await connection.query('UPDATE general SET officer_level = 1 WHERE id = $1', [generalBId]); await connection.query('UPDATE general SET officer_level = $2 WHERE id = $1', [generalBId, bLevel]);
await connection.query('COMMIT'); await connection.query('COMMIT');
} catch (error) { } catch (error) {
await connection.query('ROLLBACK'); await connection.query('ROLLBACK');
@@ -211,6 +221,14 @@ test('two users enlist, the engine advances three months, and only a chief uploa
} finally { } finally {
connection.release(); connection.release();
} }
};
// Appointment is fixture setup for the authorization boundary below. Enlistment and
// month advancement above are performed exclusively by the real turn daemon.
await admin.turnDaemon.pause.mutate({ reason: 'chief upload authorization fixture' });
await waitForPaused(true);
try {
await setOfficerLevels(5, 1);
await expect(userB.board.uploadImage.mutate({ dataUrl: sampleImage.toString('base64') })).rejects.toThrow( await expect(userB.board.uploadImage.mutate({ dataUrl: sampleImage.toString('base64') })).rejects.toThrow(
'권한이 부족합니다. 수뇌부가 아닙니다.' '권한이 부족합니다. 수뇌부가 아닙니다.'
@@ -222,6 +240,11 @@ test('two users enlist, the engine advances three months, and only a chief uploa
expect(uploaded.width).toBe(1); expect(uploaded.width).toBe(1);
expect(uploaded.height).toBe(1); expect(uploaded.height).toBe(1);
expect(uploaded.size).toBeGreaterThan(0); expect(uploaded.size).toBeGreaterThan(0);
} finally {
await setOfficerLevels(1, 1);
await admin.turnDaemon.resume.mutate({ reason: 'chief upload authorization fixture complete' });
await waitForPaused(false);
}
} finally { } finally {
await db.end(); await db.end();
} }