const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const test = require('node:test'); const root = path.resolve(__dirname, '..'); function read(relativePath) { return fs.readFileSync(path.join(root, relativePath), 'utf8'); } test('配置始终使用后端提供的 PC 接口地址', () => { const createConfig = require('../config.js'); const development = createConfig({ location: { hostname: 'localhost', port: '5500' } }); const production = createConfig({ location: { hostname: 'genealogy.example.test', port: '' } }); assert.equal(development.getEnvironment(), 'development'); assert.equal(production.getEnvironment(), 'production'); assert.equal(development.getApiBaseUrl(), 'http://182.61.18.23:8080'); assert.equal(production.getApiBaseUrl(), 'http://182.61.18.23:8080'); }); test('最新 OpenAPI 文档包含已交付的家族圈接口', () => { const contract = JSON.parse(read('PC.openapi2.json')); assert.ok(contract.paths['/genealogy/pc/auth/login']); assert.ok(contract.paths['/genealogy/pc/files/upload']); assert.ok(contract.paths['/genealogy/region/children']); assert.ok(contract.paths['/genealogy/pc/genealogies/{genealogyId}/feeds']); assert.ok(contract.paths['/genealogy/pc/genealogies/{genealogyId}/feeds/{feedId}/comments/{commentId}']); }); test('旧 YAML 明确指向最新 JSON 接口源', () => { assert.match(read('PC.openapi.yaml'), /正式接口源为 PC\.openapi2\.json/); }); test('pages do not load scripts for unavailable business APIs', () => { const removedScripts = [ 'album-pages.js', 'article-pages.js', 'ceremony-pages.js', 'feedback-pages.js', 'genealogy-pages.js', 'generation-pages.js', 'growth-pages.js', 'help-pages.js', 'join-apply-pages.js', 'lineage-pages.js', 'member-admin-pages.js', 'memo-pages.js', 'notification-pages.js', 'promotion-pages.js', 'vip-pages.js' ]; const retainedPages = fs.readdirSync(root).filter((entry) => entry.endsWith('.html')); retainedPages.forEach((page) => { const source = read(page); removedScripts.forEach((script) => { assert.equal(source.includes('src="public/js/' + script + '"'), false, `${page} still loads ${script}`); }); }); ['profile-feed.html', 'profile-feed-edit.html'].forEach((page) => { assert.equal(read(page).includes('src="public/js/feed-pages.js"'), true, `${page} must load feed-pages.js`); }); });