feat(v2.2): 建立分区关系表和AppData迁移预演
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { APP_DATA_KEYS } from '../data/data-keys';
|
||||
import { AppDataV22MigrationService } from './app-data-v22.migration.service';
|
||||
|
||||
describe('AppDataV22MigrationService', () => {
|
||||
it('loads allowed AppData keys and returns a migration preview without writing domain tables', async () => {
|
||||
const findMany = jest.fn().mockResolvedValue([
|
||||
{
|
||||
key: 'products-overview',
|
||||
value: [
|
||||
{
|
||||
id: 'product-1',
|
||||
name: 'FTB',
|
||||
projects: [{ id: 'project-1', name: 'CRM', description: '', createdAt: '2026-01-01T00:00:00.000Z' }],
|
||||
versions: [{ id: 'version-1', name: 'CRM V1.0', createdAt: '2026-01-01T00:00:00.000Z' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'requirements',
|
||||
value: {
|
||||
requirements: [
|
||||
{
|
||||
id: 'req-1',
|
||||
code: 'REQ-001',
|
||||
productId: 'product-1',
|
||||
projectId: 'project-1',
|
||||
versionId: 'version-1',
|
||||
title: 'Customer import',
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'dev-tasks',
|
||||
value: [
|
||||
{
|
||||
id: 'dev-1',
|
||||
taskNo: 'DEV-001',
|
||||
requirementId: 'req-1',
|
||||
title: 'Build import UI',
|
||||
status: 'todo',
|
||||
isBlocked: false,
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
updatedAt: '2026-01-01T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
const createMany = jest.fn();
|
||||
const prisma = { appData: { findMany }, requirement: { createMany } };
|
||||
const service = new AppDataV22MigrationService(prisma as any);
|
||||
|
||||
const preview = await service.preview();
|
||||
|
||||
expect(findMany).toHaveBeenCalledWith({
|
||||
where: { key: { in: APP_DATA_KEYS } },
|
||||
select: { key: true, value: true },
|
||||
});
|
||||
expect(createMany).not.toHaveBeenCalled();
|
||||
expect(preview.readyToImport).toBe(true);
|
||||
expect(preview.counts).toEqual(
|
||||
expect.objectContaining({
|
||||
products: 1,
|
||||
projects: 1,
|
||||
versions: 1,
|
||||
requirements: 1,
|
||||
devTasks: 1,
|
||||
}),
|
||||
);
|
||||
expect(preview.skipped).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user