Seeding & Testing¶
Mock Strapi Server¶
The mock server (scripts/mock-strapi.mjs) is a lightweight Node.js HTTP
server that mimics the Strapi v5 REST API, enabling local development without
a running CMS instance.
Start it:
node scripts/mock-strapi.mjs
It listens on http://localhost:1337.
Reference Data¶
The server creates in-memory reference data on startup:
Author:
FlexGalaxy.AI Team(documentIdauthor-001)Category:
Features(slugfeatures; localized to产品特性for zh-CN and機能紹介for ja)Tags (16): efficiency, security, collaboration, data-analytics, AI, automation, scheduling, visualization, compliance, encryption, monitoring, IoT, integration, maintenance, AMR, API
Articles are merged from seed-blog-content.mjs (9 feature articles) and
seed-blog-edge-cases.mjs (11 edge-case articles) for a total of 20.
Endpoints¶
Path |
Behavior |
|---|---|
|
Paginated list with query filters (see below) |
|
Returns categories; supports |
|
Paginated tag list |
|
Returns empty list (no mock pages) |
|
Returns 204 (CORS preflight) |
Any other path |
Returns 404 JSON |
Article query parameters:
filters[slug][$eq]=<slug>— fetch single article by slugfilters[category][slug][$eq]=<slug>— filter by categoryfilters[tags][slug][$eq]=<slug>— filter by tagpagination[page]=<n>/pagination[pageSize]=<n>— pagination
Seed Scripts¶
These scripts populate a real Strapi v5 instance via the Admin Content Manager API.
seed-blog-articles.mjs¶
Creates all reference data (author, category with localizations, 16 tags) and 9 feature articles with English, Chinese, and Japanese localizations.
STRAPI_EMAIL=admin@flexgalaxy.ai \
STRAPI_PASSWORD=Admin12345 \
node scripts/seed-blog-articles.mjs
Environment variables:
Variable |
Default |
Description |
|---|---|---|
|
|
Strapi base URL |
|
(required) |
Admin email |
|
(required) |
Admin password |
The script uses Strapi Content Manager UIDs:
api::article.articleapi::author.authorapi::category.categoryapi::tag.tag
Localizations are created via the /actions/localize endpoint for zh-CN
and ja. All articles are published after creation.
seed-blog-content.mjs¶
Exports ARTICLES — an array of 9 feature article definitions covering
FlexGalaxy.AI warehouse and factory automation topics:
# |
Slug |
Tags |
|---|---|---|
1 |
|
efficiency, data-analytics, AI |
2 |
|
scheduling, automation, AI, efficiency |
3 |
|
visualization, data-analytics, efficiency |
4 |
|
security, encryption, compliance |
5 |
|
monitoring, IoT, maintenance |
6 |
|
monitoring, maintenance, AI, automation |
7 |
|
AMR, collaboration, automation |
8 |
|
IoT, AMR, integration |
9 |
|
integration, API, automation, efficiency |
Each article has slug, tags[], and locales.en.{ title, summary, content }.
seed-blog-edge-cases.mjs¶
Exports EDGE_CASE_ARTICLES — 11 articles designed to stress-test the
blog rendering engine:
# |
Slug |
Tests |
|---|---|---|
1 |
|
Title overflow and wrapping |
2 |
|
h2 through h6 headings |
3 |
|
Fenced code (TS, Python, Bash, JSON) |
4 |
|
Ordered, unordered, nested lists |
5 |
|
Blockquotes, bold, italic, strikethrough |
6 |
|
Wide tables, alignment, long content |
7 |
|
8-section article, scroll behaviour |
8 |
|
Various image sizes and sequences |
9 |
|
YouTube iframes, responsive wrappers |
10 |
|
Flowcharts, sequence, ER, state, Gantt |
11 |
|
Inline and display LaTeX math |
Unit Tests¶
The project uses Vitest with React Testing Library and jsdom as the DOM environment.
# Run once (CI mode)
npm test
# Watch mode
npm run test:watch
Test Suites¶
i18n.test.ts — Tests src/lib/i18n.ts:
Locale configuration: 3 locales, default is
en, labels exist for allisValidLocalereturns true for valid locales, false for invalidt()returns correct translations for en, zh-CN, jaFalls back to English when a key is missing in a locale
Returns the key itself when no translation exists
Supports
{placeholder}interpolation in all locales
strapi.test.ts — Tests src/lib/strapi.ts (mocks global.fetch):
fetchPublicPagessends correct filters and locale paramsfetchPublicPagereturns page or null when not foundfetchPublicArticlessends pagination and category filter paramsfetchPublicArticlereturns article by slugfetchFeaturedArticlesfilters byfeatured=truefetchCategoriesandfetchTagsreturn arraysfetchPublicMediaCollections/fetchPublicMediaCollectionreturn dataThrows
"Strapi API error: <status>"on non-OK responsesstrapiMediaUrlhandles null, undefined, absolute URLs, and relative URLs
SectionRenderer.test.tsx — Tests CMS section rendering:
Renders hero, feature grid, rich text, and call-to-action sections
Skips unknown section types gracefully
Renders empty output for no sections
Renders multiple sections in correct order