-
Notifications
You must be signed in to change notification settings - Fork 33
/
RDBC_213.ts
87 lines (69 loc) · 3.23 KB
/
RDBC_213.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { IDocumentStore } from "../../src";
import { testContext, disposeTestDocumentStore } from "../Utils/TestUtil";
import * as assert from "assert";
describe("[RDBC-213] Metadata is not saved", function () {
let store: IDocumentStore;
beforeEach(async function () {
store = await testContext.getDocumentStore();
});
afterEach(async () =>
await disposeTestDocumentStore(store));
it("session.store() saves metadata using entity '@metadata' field", async () => {
const session = store.openSession();
const expiresAt = new Date(2023, 11, 12);
const expiringDocument = {
"name": "test",
"expires": expiresAt.toISOString(),
"@metadata": {
"@expires": expiresAt.toISOString()
}
};
await session.store(expiringDocument);
await session.saveChanges();
const session2 = store.openSession();
const loaded = await session2.load(expiringDocument["id"]);
assert.strictEqual(expiresAt.toISOString(), loaded["@metadata"]["@expires"]);
});
it("session.store() saves metadata using entity '@metadata' field when updating existing document", async () => {
// Create document with metadata
const session1 = store.openSession();
const expiresAt = new Date(2023, 11, 12);
const expiringDocument = {
"name": "test",
"@metadata": {
"@expires": expiresAt.toISOString()
}
};
await session1.store(expiringDocument);
await session1.saveChanges();
// Load document and make changes to the metadata
const session2 = store.openSession();
const loadedDocument = await session2.load(expiringDocument["id"]);
const metadata = session2.advanced.getMetadataFor(loadedDocument);
const expiresAtNewTime = new Date(2024, 11, 12).toISOString();
metadata["@expires"] = expiresAtNewTime;
const customDataValue = "customDataValue";
metadata["customData"] = customDataValue;
await session2.saveChanges();
// Verify
const session3 = store.openSession();
const updatedDocument = await session3.load(loadedDocument["id"]);
assert.strictEqual(updatedDocument["@metadata"]["@expires"], expiresAtNewTime);
assert.strictEqual(updatedDocument["@metadata"]["customData"], customDataValue);
});
it("metadata is stored using session.advanced.getMetadataFor() and session.saveChanges()", async function () {
const session = store.openSession();
const expiresAt = new Date(2023, 11, 12);
const expiringDocument = {
name: "test",
expires: expiresAt.toISOString()
};
await session.store(expiringDocument);
const metadata = session.advanced.getMetadataFor(expiringDocument);
metadata["@expires"] = expiresAt.toISOString();
await session.saveChanges();
const session2 = store.openSession();
const loaded = await session2.load(expiringDocument["id"]);
assert.strictEqual(expiresAt.toISOString(), loaded["@metadata"]["@expires"]);
});
});