refactor: tRPC 조회 입력을 JSON 본문으로 전송

브라우저의 Gateway·Game tRPC 클라이언트를 POST JSON 전송으로 통일하고 서버의 query method override를 허용한다. GET mutation 거부 계약과 production Chromium 요청 형태를 회귀 테스트로 고정한다.
This commit is contained in:
2026-08-17 11:12:02 +00:00
parent e3931602cc
commit 2d302a5f91
16 changed files with 135 additions and 20 deletions
@@ -8,7 +8,7 @@ const operationNames = (route: Route): string[] => {
};
const installFixture = async (page: Page) => {
const mutations: Array<{ operation: string; body: unknown }> = [];
const requests: Array<{ operation: string; body: unknown }> = [];
let deleteAfter: string | null = null;
let graceUntil: string | null = null;
let specialGrants: Array<Record<string, unknown>> = [];
@@ -31,7 +31,7 @@ const installFixture = async (page: Page) => {
const operations = operationNames(route);
const body = route.request().postDataJSON() as unknown;
const results = operations.map((operation) => {
if (route.request().method() === 'POST') mutations.push({ operation, body });
requests.push({ operation, body });
if (operation === 'me') {
return response({
id: 'admin-user',
@@ -202,11 +202,11 @@ const installFixture = async (page: Page) => {
body: JSON.stringify(isBatch ? results : results[0]),
});
});
return mutations;
return requests;
};
test('operates OAuth grace and scheduled deletion with reasoned audit history', async ({ page }, testInfo) => {
const mutations = await installFixture(page);
const requests = await installFixture(page);
page.on('dialog', (dialog) => dialog.accept());
await page.goto('admin/users');
await expect(page.getByRole('region', { name: '계정 목록' })).toBeVisible();
@@ -247,9 +247,9 @@ test('operates OAuth grace and scheduled deletion with reasoned audit history',
await page.getByLabel('탈퇴 전 보존 일수').fill('30');
await deletionButton.click();
await expect(page.getByText(/탈퇴 예약 완료/).first()).toBeVisible();
expect(mutations.some(({ operation }) => operation === 'admin.users.updateKakaoGrace')).toBe(true);
expect(mutations.some(({ operation }) => operation === 'admin.users.grantSpecialAccess')).toBe(true);
expect(mutations.some(({ operation }) => operation === 'admin.users.scheduleDeletion')).toBe(true);
expect(requests.some(({ operation }) => operation === 'admin.users.updateKakaoGrace')).toBe(true);
expect(requests.some(({ operation }) => operation === 'admin.users.grantSpecialAccess')).toBe(true);
expect(requests.some(({ operation }) => operation === 'admin.users.scheduleDeletion')).toBe(true);
await page.setViewportSize({ width: 390, height: 844 });
const userDirectoryGeometry = await page.getByRole('region', { name: '계정 목록' }).evaluate((directory) => {
@@ -9,10 +9,16 @@ const operationNames = (route: Route): string[] => {
};
const installGatewayFixture = async (page: Page, roles: string[]) => {
const requests: Array<{ method: string; url: string; body: unknown }> = [];
await page.addInitScript(() => {
window.localStorage.setItem('sammo-session-token', 'playwright-admin-session');
});
await page.route('**/gateway/api/trpc/**', async (route) => {
requests.push({
method: route.request().method(),
url: route.request().url(),
body: route.request().postDataJSON(),
});
const results = operationNames(route).map((operation) => {
if (operation === 'me') {
return response({
@@ -107,10 +113,11 @@ const installGatewayFixture = async (page: Page, roles: string[]) => {
),
});
});
return requests;
};
test('bootstrap superuser can navigate the administrator workspace from the lobby', async ({ page }, testInfo) => {
await installGatewayFixture(page, ['superuser']);
const requests = await installGatewayFixture(page, ['superuser']);
await page.goto('lobby');
const adminLink = page.getByRole('link', { name: '관리자 페이지' });
@@ -144,6 +151,10 @@ test('bootstrap superuser can navigate the administrator workspace from the lobb
await navigation.getByRole('link', { name: 'Gateway 릴리스' }).click();
await expect(page).toHaveURL(/\/gateway\/admin\/releases$/);
await expect(page.getByRole('heading', { name: 'Gateway 릴리스', level: 1 })).toBeVisible();
expect(requests.length).toBeGreaterThan(0);
expect(requests.every(({ method }) => method === 'POST')).toBe(true);
expect(requests.every(({ url }) => !new URL(url).searchParams.has('input'))).toBe(true);
expect(requests.some(({ body }) => JSON.stringify(body).includes('"limit":30'))).toBe(true);
});
test('desktop administrator sidebar follows the navbar away and then sticks to the viewport top', async ({
@@ -180,9 +180,7 @@ const installFixture = async (page: Page, state: FixtureState) => {
await state.gatewayLogPollGate((state.gatewayLogPollCount ?? 0) + 1);
}
const results = names.map((name) => {
if (route.request().method() === 'POST') {
state.requestBodies.push({ operation: name, body });
}
state.requestBodies.push({ operation: name, body });
if (name === 'admin.profiles.list') {
return response([profile(state.runtimeRunning, state.resetDefaults)]);
}
@@ -1,3 +1,4 @@
import { trpcJsonBodyHttpClientOptions } from '@sammo-ts/common';
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { appRouter } from '@sammo-ts/game-api';
@@ -15,6 +16,7 @@ export const createGameTrpc = (profile: string, port: number, gameToken?: string
links: [
httpBatchLink({
url,
...trpcJsonBodyHttpClientOptions,
headers: gameToken ? { authorization: `Bearer ${gameToken}` } : undefined,
}),
],
+3
View File
@@ -1,3 +1,4 @@
import { trpcJsonBodyHttpClientOptions } from '@sammo-ts/common';
import { createTRPCProxyClient, httpBatchLink, httpLink } from '@trpc/client';
import type { AppRouter } from '@sammo-ts/gateway-api';
@@ -12,6 +13,7 @@ export const trpc = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: import.meta.env.VITE_GATEWAY_API_URL ?? '/api/trpc',
...trpcJsonBodyHttpClientOptions,
headers() {
const token = getSessionToken();
return token ? { 'x-session-token': token } : {};
@@ -24,6 +26,7 @@ export const directTrpc = createTRPCProxyClient<AppRouter>({
links: [
httpLink({
url: import.meta.env.VITE_GATEWAY_API_URL ?? '/api/trpc',
...trpcJsonBodyHttpClientOptions,
headers() {
const token = getSessionToken();
return token ? { 'x-session-token': token } : {};