Files
jiapu/tests/media-response-contract.test.js
T
2026-08-29 19:06:07 +08:00

90 lines
3.5 KiB
JavaScript

const assert = require('node:assert/strict');
const test = require('node:test');
const ProfilePages = require('../public/js/profile-pages.js');
const FamilyHomePages = require('../public/js/family-home-pages.js');
const AlbumPages = require('../public/js/album-pages.js');
const VideoPages = require('../public/js/video-pages.js');
const ArticlePages = require('../public/js/article-pages.js');
const genealogyId = '2062179707935264769';
function fileAccess(name, mediaType, url) {
return {
fileId: '2062179707935264770',
ossId: '2062179707935264771',
fileName: name,
mediaType,
fileSize: 1024,
accessUrl: url,
expiresAt: '2026-08-28T12:00:00+08:00'
};
}
test('个人资料使用 avatarFile 展示头像且不暴露 OSS ID', () => {
const view = ProfilePages.buildProfileView({
nickName: '小雨',
avatarFile: fileAccess('avatar.jpg', 'image/jpeg', 'https://files.example/avatar.jpg?token=1')
});
assert.equal(view.avatarFile.accessUrl, 'https://files.example/avatar.jpg?token=1');
assert.equal(view.avatarStatus, '已设置');
assert.equal('ossId' in view.avatarFile, false);
});
test('家谱概览使用 coverFile,并渲染真实封面', () => {
const overview = FamilyHomePages.normalizeFamilyOverview({
genealogyId,
genealogyName: '彭氏家谱',
status: '0',
memberCount: 12,
personCount: 36,
coverFile: fileAccess('cover.jpg', 'image/jpeg', 'https://files.example/family-cover.jpg')
}, genealogyId);
const html = FamilyHomePages.renderFamilyOverview(overview);
assert.equal(overview.coverFile.accessUrl, 'https://files.example/family-cover.jpg');
assert.match(html, /<img[^>]+family-cover\.jpg/);
assert.doesNotMatch(html, /2062179707935264771/);
});
test('相册和照片使用 coverFile/photoFile 展示图片', () => {
const album = AlbumPages.normalizeAlbum({
albumId: '1', genealogyId: '2', albumName: '清明祭祖', status: '0',
coverFile: fileAccess('album.jpg', 'image/jpeg', 'https://files.example/album.jpg')
});
const photo = AlbumPages.normalizeAlbumPhoto({
photoId: '3', genealogyId: '2', albumId: '1', status: '0',
photoFile: fileAccess('group.jpg', 'image/jpeg', 'https://files.example/group.jpg')
});
const html = AlbumPages.renderAlbumDetail(album) + AlbumPages.renderPhotoList([photo]);
assert.match(html, /<img[^>]+album\.jpg/);
assert.match(html, /<img[^>]+group\.jpg/);
assert.doesNotMatch(html, /2062179707935264771/);
});
test('视频使用 videoFile 播放并使用 coverFile 作为封面', () => {
const video = VideoPages.normalizeVideo({
videoId: '1', genealogyId: '2', videoTitle: '祭祖影像', status: '0',
videoFile: fileAccess('ceremony.mp4', 'video/mp4', 'https://files.example/ceremony.mp4'),
coverFile: fileAccess('video-cover.jpg', 'image/jpeg', 'https://files.example/video-cover.jpg')
});
const html = VideoPages.renderVideoDetail(video, false);
assert.match(html, /<video[^>]+ceremony\.mp4/);
assert.match(html, /poster="https:\/\/files\.example\/video-cover\.jpg/);
assert.doesNotMatch(html, /2062179707935264771/);
});
test('谱文使用 coverFile 展示封面', () => {
const article = ArticlePages.normalizeArticle({
articleId: '1', genealogyId: '2', articleTitle: '迁徙记', articleContent: '正文', status: '0',
coverFile: fileAccess('article.jpg', 'image/jpeg', 'https://files.example/article.jpg')
});
const html = ArticlePages.renderArticleDetail(article);
assert.match(html, /<img[^>]+article\.jpg/);
assert.doesNotMatch(html, /2062179707935264771/);
});