mirror of
https://github.com/kamask-dev/pchelpmaster.git
synced 2026-11-11 05:49:38 +00:00
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
// Проверяет правило `/pb/` в proxy.conf.mjs: оно должно повторять `location /pb/` из nginx и серверный `PB_URL`.
|
||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||
import type { ProxyRules } from '../../proxy.conf.mjs';
|
||
|
||
async function loadRules(pbUrl: string | undefined): Promise<ProxyRules> {
|
||
vi.stubEnv('PB_URL', pbUrl);
|
||
vi.resetModules();
|
||
return (await import('../../proxy.conf.mjs')).default;
|
||
}
|
||
|
||
describe('прокси /pb для ng serve', () => {
|
||
afterEach(() => vi.unstubAllEnvs());
|
||
|
||
it('содержит правило /pb/ с target из PB_URL', async () => {
|
||
const rules = await loadRules('http://pb.test:1234');
|
||
|
||
expect(rules['/pb/']?.target).toBe('http://pb.test:1234');
|
||
expect(rules['/pb/']?.changeOrigin).toBe(true);
|
||
});
|
||
|
||
it.each([undefined, ''])('при PB_URL=%j target — http://127.0.0.1:8090', async (pbUrl) => {
|
||
const rules = await loadRules(pbUrl);
|
||
|
||
expect(rules['/pb/']?.target).toBe('http://127.0.0.1:8090');
|
||
});
|
||
|
||
it('rewrite срезает префикс /pb', async () => {
|
||
const rewrite = (await loadRules(undefined))['/pb/']?.rewrite;
|
||
|
||
expect(rewrite?.('/pb/api/health')).toBe('/api/health');
|
||
expect(rewrite?.('/pb/api/collections/x/records?a=1')).toBe(
|
||
'/api/collections/x/records?a=1',
|
||
);
|
||
});
|
||
});
|