feat: add child motion entry and fix auth env
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-05-10 18:27:51 +08:00
parent 86fc382413
commit 46a254f142
22 changed files with 2868 additions and 58 deletions

View File

@@ -0,0 +1,59 @@
import { afterEach, describe, expect, test, vi } from 'vitest';
import type { PlatformPublicGalleryCard } from '../rpg-entry/rpgEntryWorldPresentation';
import {
canExposePublicWork,
filterEdutainmentPublicWorks,
filterGeneralPublicWorks,
isEdutainmentEntryEnabled,
isEdutainmentPublicWork,
} from './platformEdutainmentVisibility';
function buildPuzzleCard(themeTags: string[]): PlatformPublicGalleryCard {
return {
sourceType: 'puzzle',
workId: 'puzzle-work-education-demo',
profileId: 'puzzle-profile-education-demo',
publicWorkCode: 'PZ-EDUDEMO',
ownerUserId: 'user-education',
authorDisplayName: '动作 Demo 作者',
worldName: '儿童动作热身 Demo',
subtitle: '拼图关卡',
summaryText: '本地动作 Demo。',
coverImageSrc: null,
themeTags,
visibility: 'published',
publishedAt: '2026-05-09T10:00:00.000Z',
updatedAt: '2026-05-09T10:00:00.000Z',
};
}
afterEach(() => {
vi.unstubAllEnvs();
});
describe('platformEdutainmentVisibility', () => {
test('matches only the exact edutainment tag from full work tags', () => {
const exact = buildPuzzleCard(['运动', '安全', '拼图', '寓教于乐']);
const fuzzy = buildPuzzleCard(['儿童教育', '寓教于乐 ']);
expect(isEdutainmentPublicWork(exact)).toBe(true);
expect(isEdutainmentPublicWork(fuzzy)).toBe(false);
expect(filterEdutainmentPublicWorks([exact, fuzzy])).toEqual([exact]);
expect(filterGeneralPublicWorks([exact, fuzzy])).toEqual([fuzzy]);
});
test('defaults to enabled and blocks exact edutainment works only when disabled', () => {
const exact = buildPuzzleCard(['寓教于乐']);
const general = buildPuzzleCard(['儿童教育']);
expect(isEdutainmentEntryEnabled()).toBe(true);
expect(canExposePublicWork(exact)).toBe(true);
vi.stubEnv('VITE_ENABLE_EDUTAINMENT_ENTRY', 'false');
expect(isEdutainmentEntryEnabled()).toBe(false);
expect(canExposePublicWork(exact)).toBe(false);
expect(canExposePublicWork(general)).toBe(true);
});
});