Expose project revision timeline
This commit is contained in:
@@ -83,6 +83,150 @@ function getRowQuantity(context: DatabaseContext) {
|
||||
}
|
||||
|
||||
describe("project history repository", () => {
|
||||
it("lists revision metadata in stable descending pages without payloads", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const circuitsStore = new CircuitProjectCommandRepository(context.db);
|
||||
const rowsStore = new CircuitDeviceRowProjectCommandRepository(context.db);
|
||||
const first = circuitsStore.executeUpdate({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
source: "user",
|
||||
actorId: "planner-1",
|
||||
description: "Stromkreis umbenennen",
|
||||
command: createCircuitUpdateProjectCommand("circuit-1", {
|
||||
displayName: "Neu",
|
||||
}),
|
||||
});
|
||||
const second = rowsStore.executeUpdate({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 1,
|
||||
source: "user",
|
||||
description: "Anzahl ändern",
|
||||
command: createCircuitDeviceRowUpdateProjectCommand("row-1", {
|
||||
quantity: 2,
|
||||
}),
|
||||
});
|
||||
const third = rowsStore.executeUpdate({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 2,
|
||||
source: "undo",
|
||||
description: "Anzahl zurücknehmen",
|
||||
historyTargetChangeSetId: second.revision.changeSetId,
|
||||
command: second.inverse,
|
||||
});
|
||||
const history = new ProjectHistoryRepository(context.db);
|
||||
|
||||
assert.deepEqual(
|
||||
history.listRevisions({
|
||||
projectId: "project-1",
|
||||
limit: 2,
|
||||
}),
|
||||
{
|
||||
projectId: "project-1",
|
||||
currentRevision: 3,
|
||||
revisions: [
|
||||
{
|
||||
revisionId: third.revision.revisionId,
|
||||
changeSetId: third.revision.changeSetId,
|
||||
revisionNumber: 3,
|
||||
createdAtIso: third.revision.createdAtIso,
|
||||
actorId: null,
|
||||
source: "undo",
|
||||
description: "Anzahl zurücknehmen",
|
||||
commandType: "circuit-device-row.update",
|
||||
payloadSchemaVersion: 1,
|
||||
},
|
||||
{
|
||||
revisionId: second.revision.revisionId,
|
||||
changeSetId: second.revision.changeSetId,
|
||||
revisionNumber: 2,
|
||||
createdAtIso: second.revision.createdAtIso,
|
||||
actorId: null,
|
||||
source: "user",
|
||||
description: "Anzahl ändern",
|
||||
commandType: "circuit-device-row.update",
|
||||
payloadSchemaVersion: 1,
|
||||
},
|
||||
],
|
||||
nextBeforeRevision: 2,
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
history.listRevisions({
|
||||
projectId: "project-1",
|
||||
limit: 2,
|
||||
beforeRevision: 2,
|
||||
}),
|
||||
{
|
||||
projectId: "project-1",
|
||||
currentRevision: 3,
|
||||
revisions: [
|
||||
{
|
||||
revisionId: first.revision.revisionId,
|
||||
changeSetId: first.revision.changeSetId,
|
||||
revisionNumber: 1,
|
||||
createdAtIso: first.revision.createdAtIso,
|
||||
actorId: "planner-1",
|
||||
source: "user",
|
||||
description: "Stromkreis umbenennen",
|
||||
commandType: "circuit.update",
|
||||
payloadSchemaVersion: 1,
|
||||
},
|
||||
],
|
||||
nextBeforeRevision: null,
|
||||
}
|
||||
);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("lists an empty timeline and rejects invalid page inputs", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const history = new ProjectHistoryRepository(context.db);
|
||||
assert.deepEqual(
|
||||
history.listRevisions({
|
||||
projectId: "project-1",
|
||||
limit: 25,
|
||||
}),
|
||||
{
|
||||
projectId: "project-1",
|
||||
currentRevision: 0,
|
||||
revisions: [],
|
||||
nextBeforeRevision: null,
|
||||
}
|
||||
);
|
||||
assert.equal(
|
||||
history.listRevisions({
|
||||
projectId: "missing",
|
||||
limit: 25,
|
||||
}),
|
||||
null
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
history.listRevisions({
|
||||
projectId: "project-1",
|
||||
limit: 0,
|
||||
}),
|
||||
/between 1 and 100/
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
history.listRevisions({
|
||||
projectId: "project-1",
|
||||
limit: 25,
|
||||
beforeRevision: 0,
|
||||
}),
|
||||
/positive integer/
|
||||
);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("persists project-wide undo and redo stacks across repository instances", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user