155 lines
4.4 KiB
TypeScript
155 lines
4.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import type { RuntimeRepositoryPort } from '../runtimeRepository.js';
|
|
import { RpgBrowseHistoryRepository } from './RpgBrowseHistoryRepository.js';
|
|
import { RpgProfileDashboardRepository } from './RpgProfileDashboardRepository.js';
|
|
|
|
function createRuntimeRepositoryStub(): RuntimeRepositoryPort {
|
|
return {
|
|
async getSnapshot() {
|
|
return null;
|
|
},
|
|
async putSnapshot(_userId, payload) {
|
|
return {
|
|
version: 1,
|
|
...payload,
|
|
};
|
|
},
|
|
async getProfileDashboard() {
|
|
return {
|
|
walletBalance: 0,
|
|
totalPlayTimeMs: 0,
|
|
playedWorldCount: 0,
|
|
updatedAt: '2026-04-21T00:00:00.000Z',
|
|
};
|
|
},
|
|
async listProfileWalletLedger() {
|
|
return [];
|
|
},
|
|
async getProfilePlayStats() {
|
|
return {
|
|
totalPlayTimeMs: 0,
|
|
playedWorks: [],
|
|
updatedAt: '2026-04-21T00:00:00.000Z',
|
|
};
|
|
},
|
|
async listProfileSaveArchives() {
|
|
return [];
|
|
},
|
|
async resumeProfileSaveArchive() {
|
|
return null;
|
|
},
|
|
async deleteSnapshot() {},
|
|
async getSettings() {
|
|
return {
|
|
musicVolume: 0.5,
|
|
platformTheme: 'light',
|
|
};
|
|
},
|
|
async putSettings(_userId, settings) {
|
|
return settings;
|
|
},
|
|
async listCustomWorldProfiles() {
|
|
return [];
|
|
},
|
|
async listPlatformBrowseHistory() {
|
|
return [
|
|
{
|
|
ownerUserId: 'owner-1',
|
|
profileId: 'profile-1',
|
|
worldName: '雾港',
|
|
subtitle: '沿海试炼',
|
|
summaryText: '最近访问',
|
|
coverImageSrc: null,
|
|
themeMode: 'mythic',
|
|
authorDisplayName: '测试者',
|
|
visitedAt: '2026-04-21T00:00:00.000Z',
|
|
},
|
|
];
|
|
},
|
|
async upsertPlatformBrowseHistoryEntries(_userId, entries) {
|
|
return entries.map((entry) => ({
|
|
ownerUserId: entry.ownerUserId,
|
|
profileId: entry.profileId,
|
|
worldName: entry.worldName,
|
|
subtitle: entry.subtitle ?? '',
|
|
summaryText: entry.summaryText ?? '',
|
|
coverImageSrc: entry.coverImageSrc ?? null,
|
|
themeMode: entry.themeMode ?? 'mythic',
|
|
authorDisplayName: entry.authorDisplayName ?? '玩家',
|
|
visitedAt: entry.visitedAt ?? '2026-04-21T00:00:00.000Z',
|
|
}));
|
|
},
|
|
async clearPlatformBrowseHistory() {},
|
|
async upsertCustomWorldProfile() {
|
|
return {
|
|
entry: {} as never,
|
|
entries: [],
|
|
};
|
|
},
|
|
async deleteCustomWorldProfile() {
|
|
return [];
|
|
},
|
|
async listCustomWorldSessions() {
|
|
return [];
|
|
},
|
|
async getCustomWorldSession() {
|
|
return null;
|
|
},
|
|
async upsertCustomWorldSession(_userId, _sessionId, session) {
|
|
return session;
|
|
},
|
|
async publishCustomWorldProfile() {
|
|
return null;
|
|
},
|
|
async unpublishCustomWorldProfile() {
|
|
return null;
|
|
},
|
|
async listPublishedCustomWorldGallery() {
|
|
return [];
|
|
},
|
|
async getPublishedCustomWorldGalleryDetail() {
|
|
return null;
|
|
},
|
|
};
|
|
}
|
|
|
|
test('RpgProfileDashboardRepository 只暴露资料看板域方法', async () => {
|
|
const repository = new RpgProfileDashboardRepository(
|
|
createRuntimeRepositoryStub(),
|
|
);
|
|
|
|
const dashboard = await repository.getProfileDashboard('user-1');
|
|
const playStats = await repository.getProfilePlayStats('user-1');
|
|
const settings = await repository.getSettings('user-1');
|
|
|
|
assert.equal(dashboard.playedWorldCount, 0);
|
|
assert.equal(playStats.playedWorks.length, 0);
|
|
assert.equal(settings.platformTheme, 'light');
|
|
assert.equal('listPlatformBrowseHistory' in repository, false);
|
|
});
|
|
|
|
test('RpgBrowseHistoryRepository 独立承接浏览历史读写,不再混入资料看板仓储', async () => {
|
|
const repository = new RpgBrowseHistoryRepository(createRuntimeRepositoryStub());
|
|
|
|
const history = await repository.listPlatformBrowseHistory('user-1');
|
|
const updated = await repository.upsertPlatformBrowseHistoryEntries('user-1', [
|
|
{
|
|
ownerUserId: 'owner-2',
|
|
profileId: 'profile-2',
|
|
worldName: '盐雾镇',
|
|
subtitle: '盐路补给点',
|
|
summaryText: '测试写入浏览历史',
|
|
coverImageSrc: null,
|
|
themeMode: 'mythic',
|
|
authorDisplayName: '测试者二号',
|
|
visitedAt: '2026-04-21T01:00:00.000Z',
|
|
},
|
|
]);
|
|
|
|
assert.equal(history[0]?.worldName, '雾港');
|
|
assert.equal(updated[0]?.profileId, 'profile-2');
|
|
assert.equal('getProfileDashboard' in repository, false);
|
|
});
|