test(e2e): honor configured game base paths
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { expect, test, type Page, type Route } from '@playwright/test';
|
||||
import { gameBasePath, gameProfile, gameTrpcRoute } from './gameTestPaths.js';
|
||||
|
||||
const response = (data: unknown) => ({ result: { data } });
|
||||
|
||||
@@ -24,22 +25,23 @@ const publicResponse = (operation: string): unknown => {
|
||||
};
|
||||
|
||||
const seedGameStorage = async (page: Page, gameToken: string): Promise<void> => {
|
||||
await page.addInitScript((token) => {
|
||||
window.localStorage.setItem('sammo-game-token', token);
|
||||
window.localStorage.setItem('sammo-game-profile', 'che:default');
|
||||
}, gameToken);
|
||||
await page.addInitScript(
|
||||
({ token, profile }) => {
|
||||
window.localStorage.setItem('sammo-game-token', token);
|
||||
window.localStorage.setItem('sammo-game-profile', profile);
|
||||
},
|
||||
{ token: gameToken, profile: gameProfile }
|
||||
);
|
||||
};
|
||||
|
||||
test('removes an invalid ga_ token and redirects an authenticated route to public', async ({
|
||||
page,
|
||||
}) => {
|
||||
test('removes an invalid ga_ token and redirects an authenticated route to public', async ({ page }) => {
|
||||
await seedGameStorage(page, 'ga_invalid');
|
||||
let gatewayRequests = 0;
|
||||
await page.route('http://127.0.0.1:15120/api/trpc/**', async (route) => {
|
||||
gatewayRequests += 1;
|
||||
await route.abort();
|
||||
});
|
||||
await page.route('**/che/api/trpc/**', async (route) => {
|
||||
await page.route(gameTrpcRoute, async (route) => {
|
||||
const operations = operationNames(route);
|
||||
if (operations.includes('auth.status')) {
|
||||
expect(route.request().headers().authorization).toBe('Bearer ga_invalid');
|
||||
@@ -58,7 +60,7 @@ test('removes an invalid ga_ token and redirects an authenticated route to publi
|
||||
});
|
||||
|
||||
await page.goto('select-general');
|
||||
await expect(page).toHaveURL(/\/che\/public$/);
|
||||
await expect(page).toHaveURL(new RegExp(`${gameBasePath}/public$`));
|
||||
await expect(page.getByRole('heading', { name: '공개 동향' })).toBeVisible();
|
||||
expect(await page.evaluate(() => window.localStorage.getItem('sammo-game-token'))).toBeNull();
|
||||
expect(gatewayRequests).toBe(0);
|
||||
@@ -74,7 +76,7 @@ test('keeps a valid ga_ token when only lobby.info is unavailable', async ({ pag
|
||||
gatewayRequests += 1;
|
||||
await route.abort();
|
||||
});
|
||||
await page.route('**/che/api/trpc/**', async (route) => {
|
||||
await page.route(gameTrpcRoute, async (route) => {
|
||||
const operations = operationNames(route);
|
||||
if (operations.includes('auth.status')) {
|
||||
statusRequests += 1;
|
||||
@@ -103,11 +105,9 @@ test('keeps a valid ga_ token when only lobby.info is unavailable', async ({ pag
|
||||
});
|
||||
|
||||
await page.goto('select-general');
|
||||
await expect(page).toHaveURL(/\/che\/select-general$/);
|
||||
await expect(page).toHaveURL(new RegExp(`${gameBasePath}/select-general$`));
|
||||
await expect(page.locator('.page-title')).toContainText('장 수 선 택');
|
||||
expect(await page.evaluate(() => window.localStorage.getItem('sammo-game-token'))).toBe(
|
||||
'ga_valid'
|
||||
);
|
||||
expect(await page.evaluate(() => window.localStorage.getItem('sammo-game-token'))).toBe('ga_valid');
|
||||
expect(statusRequests).toBe(1);
|
||||
expect(lobbyRequests).toBe(1);
|
||||
expect(gatewayRequests).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user