feat(platform): add managed data product history plane
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { Pool } from "pg";
|
||||
import { validateDataProductPatch, validateDataProductSnapshot } from "@nodedc/external-provider-contract/data-plane";
|
||||
import { validateDataProductHistory, validateDataProductPatch, validateDataProductSnapshot } from "@nodedc/external-provider-contract/data-plane";
|
||||
import {
|
||||
loadDataProductDefinition,
|
||||
persistDataProductDefinition,
|
||||
persistDataProductPublish,
|
||||
readDataProductHistory,
|
||||
readDataProductSnapshot,
|
||||
readPatchEvents,
|
||||
} from "../src/data-product-delivery.mjs";
|
||||
@@ -154,6 +155,47 @@ try {
|
||||
assert.equal(unitOneHistory.some((row) => new Date(row.observed_at).toISOString() === "2026-07-15T10:01:30.000Z"), true);
|
||||
assert.equal(unitOneHistory.some((row) => new Date(row.observed_at).toISOString() === "2026-07-15T10:02:00.000Z"), true);
|
||||
|
||||
const historyPageOne = await readDataProductHistory(pool, binding, storedDefinition, {
|
||||
from: "2026-07-15T10:00:00.000Z",
|
||||
to: "2026-07-15T10:04:00.000Z",
|
||||
resolutionMs: 60_000,
|
||||
sourceIds: ["unit-01"],
|
||||
limit: 2,
|
||||
});
|
||||
assert.equal(validateDataProductHistory(historyPageOne).ok, true);
|
||||
assert.equal(historyPageOne.facts.length, 2);
|
||||
assert.equal(typeof historyPageOne.nextCursor, "string");
|
||||
const historyPageTwo = await readDataProductHistory(pool, binding, storedDefinition, {
|
||||
from: "2026-07-15T10:00:00.000Z",
|
||||
to: "2026-07-15T10:04:00.000Z",
|
||||
resolutionMs: 60_000,
|
||||
sourceIds: ["unit-01"],
|
||||
limit: 2,
|
||||
cursor: historyPageOne.nextCursor,
|
||||
});
|
||||
assert.equal(validateDataProductHistory(historyPageTwo).ok, true);
|
||||
assert.equal(historyPageTwo.facts.length, 1);
|
||||
assert.equal(historyPageTwo.nextCursor, undefined);
|
||||
assert.deepEqual(
|
||||
[...historyPageOne.facts, ...historyPageTwo.facts].map((value) => value.bucketStart),
|
||||
[
|
||||
"2026-07-15T10:00:00.000Z",
|
||||
"2026-07-15T10:01:00.000Z",
|
||||
"2026-07-15T10:02:00.000Z",
|
||||
],
|
||||
);
|
||||
await assert.rejects(
|
||||
readDataProductHistory(pool, binding, storedDefinition, {
|
||||
from: "2026-07-15T10:00:00.000Z",
|
||||
to: "2026-07-15T10:04:00.000Z",
|
||||
resolutionMs: 60_000,
|
||||
sourceIds: ["unit-02"],
|
||||
limit: 2,
|
||||
cursor: historyPageOne.nextCursor,
|
||||
}),
|
||||
(error) => error?.status === 400 && error?.code === "data_product_history_cursor_invalid",
|
||||
);
|
||||
|
||||
console.log("external-data-plane delivery integration: ok");
|
||||
} finally {
|
||||
await pool.end();
|
||||
|
||||
Reference in New Issue
Block a user