Skip to content

Commit c266ae5

Browse files
committed
added unit test for root value rewriting for testing against regression
1 parent 813e2f4 commit c266ae5

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

packages/runner/test/storage-transaction-shim.test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,94 @@ describe("URI Utils", () => {
560560
});
561561
});
562562

563+
describe("root value rewriting", () => {
564+
let storageManager: ReturnType<typeof StorageManager.emulate>;
565+
let runtime: Runtime;
566+
567+
beforeEach(() => {
568+
storageManager = StorageManager.emulate({ as: signer });
569+
runtime = new Runtime({
570+
storageManager,
571+
blobbyServerUrl: "http://localhost:8080",
572+
});
573+
});
574+
575+
afterEach(async () => {
576+
await runtime?.dispose();
577+
await storageManager?.close();
578+
});
579+
580+
it("should rewrite root writes with value property", () => {
581+
const transaction = runtime.edit();
582+
583+
// Write to empty path with object containing "value" property
584+
const writeResult = transaction.write({
585+
space,
586+
id: "of:test-root",
587+
type: "application/json",
588+
path: [],
589+
}, { value: { foo: "bar" } });
590+
591+
expect(writeResult.ok).toBeDefined();
592+
593+
// Should be able to read the value at path ["value"]
594+
const readResult = transaction.readOrThrow({
595+
space,
596+
id: "of:test-root",
597+
type: "application/json",
598+
path: ["value"],
599+
});
600+
601+
expect(readResult).toEqual({ foo: "bar" });
602+
});
603+
604+
it("should not rewrite non-empty paths", () => {
605+
const transaction = runtime.edit();
606+
607+
// First create a document
608+
transaction.write({
609+
space,
610+
id: "of:test-nested",
611+
type: "application/json",
612+
path: ["value"],
613+
}, {});
614+
615+
// Write to non-empty path with object containing "value" property
616+
transaction.write({
617+
space,
618+
id: "of:test-nested",
619+
type: "application/json",
620+
path: ["value", "nested"],
621+
}, { value: "should not be rewritten" });
622+
623+
// Should store the object as-is
624+
const readResult = transaction.readOrThrow({
625+
space,
626+
id: "of:test-nested",
627+
type: "application/json",
628+
path: ["value", "nested"],
629+
});
630+
631+
expect(readResult).toEqual({ value: "should not be rewritten" });
632+
});
633+
634+
it("should not rewrite non-objects", () => {
635+
const transaction = runtime.edit();
636+
637+
// Write non-object to empty path
638+
const writeResult = transaction.write({
639+
space,
640+
id: "of:test-string",
641+
type: "application/json",
642+
path: [],
643+
}, "plain string");
644+
645+
// Should get an error since path is empty and value is not rewritten
646+
expect(writeResult.error).toBeDefined();
647+
expect(writeResult.error?.name).toBe("NotFoundError");
648+
});
649+
});
650+
563651
describe("data: URI behaviors", () => {
564652
let runtime: Runtime;
565653
let storageManager: ReturnType<typeof StorageManager.emulate>;

0 commit comments

Comments
 (0)