Files
peptide-e2e/tests/04-rest-api.spec.ts
peptiderepo d46a1e4680 feat: initial Playwright smoke suite
20 tests across 5 files covering all plugin surfaces on staging:
- Homepage load and PHP fatal detection
- Reconstitution Calculator shortcode + math
- Peptide Search AI widget + AJAX response
- Admin: all plugins active, PSA + PRAutoBlogger settings pages
- REST API: prc/v1/presets, peptides/v1/search, compounds, CPT types

Staging shortcode pages:
  /reconstitution-calculator/ - [prc_calculator]
  /search-peptides/           - [peptide_search]
  /peptide-directory/         - [peptide_directory]

GHA workflow: smoke.yml supports manual dispatch + workflow_call
for use as a deploy gate from plugin repos.
2026-04-26 04:39:13 +00:00

62 lines
2.7 KiB
TypeScript
Executable File

/**
* 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