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 (documentId author-001)

  • Category: Features (slug features; 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

GET /api/articles

Paginated list with query filters (see below)

GET /api/categories

Returns categories; supports locale param

GET /api/tags

Paginated tag list

GET /api/pages

Returns empty list (no mock pages)

OPTIONS *

Returns 204 (CORS preflight)

Any other path

Returns 404 JSON

Article query parameters:

  • filters[slug][$eq]=<slug> — fetch single article by slug

  • filters[category][slug][$eq]=<slug> — filter by category

  • filters[tags][slug][$eq]=<slug> — filter by tag

  • pagination[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_URL

http://localhost:1337

Strapi base URL

STRAPI_EMAIL

(required)

Admin email

STRAPI_PASSWORD

(required)

Admin password

The script uses Strapi Content Manager UIDs:

  • api::article.article

  • api::author.author

  • api::category.category

  • api::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

data-processing-and-prediction

efficiency, data-analytics, AI

2

execution-and-planning

scheduling, automation, AI, efficiency

3

dashboards-and-statistics

visualization, data-analytics, efficiency

4

data-isolation-and-encryption

security, encryption, compliance

5

real-time-monitoring

monitoring, IoT, maintenance

6

proactive-alerts

monitoring, maintenance, AI, automation

7

unified-human-machine-platform

AMR, collaboration, automation

8

connect-multiple-iot-devices

IoT, AMR, integration

9

seamless-integration

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

edge-case-extremely-long-title-...

Title overflow and wrapping

2

edge-case-deep-heading-nesting

h2 through h6 headings

3

edge-case-code-blocks

Fenced code (TS, Python, Bash, JSON)

4

edge-case-lists-and-nesting

Ordered, unordered, nested lists

5

edge-case-rich-formatting

Blockquotes, bold, italic, strikethrough

6

edge-case-tables

Wide tables, alignment, long content

7

edge-case-very-long-article

8-section article, scroll behaviour

8

edge-case-images

Various image sizes and sequences

9

edge-case-youtube-embeds

YouTube iframes, responsive wrappers

10

edge-case-mermaid-diagrams

Flowcharts, sequence, ER, state, Gantt

11

edge-case-math-equations

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 all

  • isValidLocale returns true for valid locales, false for invalid

  • t() returns correct translations for en, zh-CN, ja

  • Falls 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):

  • fetchPublicPages sends correct filters and locale params

  • fetchPublicPage returns page or null when not found

  • fetchPublicArticles sends pagination and category filter params

  • fetchPublicArticle returns article by slug

  • fetchFeaturedArticles filters by featured=true

  • fetchCategories and fetchTags return arrays

  • fetchPublicMediaCollections / fetchPublicMediaCollection return data

  • Throws "Strapi API error: <status>" on non-OK responses

  • strapiMediaUrl handles 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