/** * 04-rest-api.spec.ts * * What: Verifies public REST API endpoints from all plugins respond with * valid JSON and expected shapes. Catches broken REST registration, * PHP errors in REST handlers, or missing PR Core dependency. * Who triggers it: Playwright chromium project (post-auth setup). * Note: these tests do NOT need auth — they test public endpoints. * Dependencies: All plugins active on staging; at least one published peptide. * * Endpoints tested: * - GET /wp-json/prc/v1/presets — Reconstitution Calculator presets * - GET /wp-json/peptides/v1/search — PSA search REST endpoint * - GET /wp-json/peptide-search-ai/v1/compounds — PSA directory endpoint * - GET /wp-json/wp/v2/peptide — PR Core CPT via WP REST */ import { test, expect } from '@playwright/test'; test.describe('REST API — Reconstitution Calculator', () => { test('GET /wp-json/prc/v1/presets returns array', async ({ request }) => { const res = await request.get('/wp-json/prc/v1/presets'); expect(res.status()).toBe(200); const body = await res.json(); expect(Array.isArray(body)).toBe(true); expect(body.length).toBeGreaterThan(0); // Each preset should have at minimum a slug and name const first = body[0]; expect(first).toHaveProperty('slug'); expect(first).toHaveProperty('name'); }); }); test.describe('REST API — Peptide Search AI', () => { test('GET /wp-json/peptides/v1/search returns valid JSON', async ({ request }) => { const res = await request.get('/wp-json/peptides/v1/search?q=BPC'); // 200 (results found) or 404 (no results) are both acceptable; 500 is not expect([200, 404]).toContain(res.status()); if (res.status() === 200) { const body = await res.json(); expect(body).toHaveProperty('status'); expect(body).toHaveProperty('results'); } }); test('GET /wp-json/peptide-search-ai/v1/compounds returns paginated list', async ({ request }) => { const res = await request.get('/wp-json/peptide-search-ai/v1/compounds?fields=basic'); expect(res.status()).toBe(200); const body = await res.json(); // Response should be array or object with data key expect(body).toBeDefined(); }); }); test.describe('REST API — PR Core (CPT registration)', () => { test('peptide CPT is registered and appears in WP REST index', async ({ request }) => { // Confirmed via live inspection: the peptide CPT does NOT expose via /wp/v2/peptide // (not registered with show_in_rest on the default namespace). // Instead we verify the CPT exists via the WP REST types endpoint. const res = await request.get('/wp-json/wp/v2/types/peptide'); // 200 = CPT registered; 404 = CPT missing entirely — both are informative