75 lines
3.1 KiB
TypeScript
75 lines
3.1 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { staffLogin, trpcCall } from '../lib/trpc';
|
|
import { superadminName, superadminPassword, stamp } from '../lib/helpers';
|
|
|
|
// NOTE: regions are non-deletable by design, so every case here leaves a
|
|
// timestamped region behind. Names use the PW-Neg- prefix for easy spotting.
|
|
let superToken = '';
|
|
|
|
test.beforeAll(async () => {
|
|
superToken = (await staffLogin(superadminName(), superadminPassword())).token;
|
|
});
|
|
|
|
const cred = (chat: string) => ({ botToken: 't', chatId: `pw-${stamp()}-${chat}` });
|
|
|
|
test('1.4 duplicate bound priorities rejected', async () => {
|
|
const r = await trpcCall(superToken, 'admin.region.createRegion', {
|
|
name: `PW-Neg-duppri-${stamp()}`,
|
|
bounds: [
|
|
{ name: 'a', description: 'da', priority: 1, geojson: '{}' },
|
|
{ name: 'b', description: 'db', priority: 1, geojson: '{}' },
|
|
],
|
|
creds: [cred('a')],
|
|
}, 'POST');
|
|
expect(r.error?.message).toMatch(/Duplicate bound priority/);
|
|
});
|
|
|
|
test('1.5 duplicate creds rejected (partial region may remain — see DATA-1)', async () => {
|
|
const name = `PW-Neg-dupcred-${stamp()}`;
|
|
const chat = `same-${stamp()}`;
|
|
const r = await trpcCall(superToken, 'admin.region.createRegion', {
|
|
name,
|
|
bounds: [],
|
|
creds: [
|
|
{ botToken: 't1', chatId: chat },
|
|
{ botToken: 't2', chatId: chat },
|
|
],
|
|
}, 'POST');
|
|
expect(r.error).toBeDefined();
|
|
});
|
|
|
|
test('1.6 duplicate region name allowed', async () => {
|
|
const name = `PW-Neg-dupname-${stamp()}`;
|
|
const first = await trpcCall(superToken, 'admin.region.createRegion', { name, bounds: [], creds: [cred('a')] }, 'POST');
|
|
expect(first.result?.data?.region?.id).toBeDefined();
|
|
const second = await trpcCall(superToken, 'admin.region.createRegion', { name, bounds: [], creds: [cred('b')] }, 'POST');
|
|
expect(second.result?.data?.region?.id).toBeDefined();
|
|
});
|
|
|
|
test('1.8 priority 0 stored', async () => {
|
|
const r = await trpcCall(superToken, 'admin.region.createRegion', {
|
|
name: `PW-Neg-pri0-${stamp()}`,
|
|
bounds: [{ name: 'z', description: 'dz', priority: 0, geojson: '{}' }],
|
|
creds: [cred('a')],
|
|
}, 'POST');
|
|
expect(r.result?.data?.region?.bounds?.[0]?.priority).toBe(0);
|
|
});
|
|
|
|
test('1.15 deleteRegion always refused', async () => {
|
|
const r = await trpcCall(superToken, 'admin.region.deleteRegion', { id: 1 }, 'POST');
|
|
expect(r.error?.message).toMatch(/cannot be deleted/);
|
|
});
|
|
|
|
test('1.18 non-superadmin region mutation forbidden', async () => {
|
|
if (!process.env.R1_ADMIN_NAME || !process.env.R1_ADMIN_PASSWORD) {
|
|
throw new Error('R1_ADMIN_NAME/R1_ADMIN_PASSWORD required (see tests/web/.env.example)');
|
|
}
|
|
const { token } = await staffLogin(process.env.R1_ADMIN_NAME, process.env.R1_ADMIN_PASSWORD);
|
|
const r = await trpcCall(token, 'admin.region.createRegion', { name: 'PW-Hack', bounds: [], creds: [cred('x')] }, 'POST');
|
|
expect(r.error?.data?.code).toBe('FORBIDDEN');
|
|
});
|
|
|
|
test('1.19 anonymous region mutation unauthorized', async () => {
|
|
const r = await trpcCall(null, 'admin.region.createRegion', { name: 'PW-Anon', bounds: [], creds: [cred('x')] }, 'POST');
|
|
expect(r.error?.data?.code).toBe('UNAUTHORIZED');
|
|
});
|