-
Notifications
You must be signed in to change notification settings - Fork 33
/
TrackEntityTest.ts
83 lines (68 loc) · 2.52 KB
/
TrackEntityTest.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
import * as assert from "assert";
import { testContext, disposeTestDocumentStore } from "../Utils/TestUtil";
import {
IDocumentStore,
} from "../../src";
import { User } from "../Assets/Entities";
describe("TrackEntityTest", function () {
let store: IDocumentStore;
beforeEach(async function () {
store = await testContext.getDocumentStore();
});
afterEach(async () =>
await disposeTestDocumentStore(store));
it("deletingEntityThatIsNotTrackedShouldThrow", async () => {
const session = store.openSession();
try {
await session.delete(new User());
assert.fail("Should have thrown.");
} catch (err) {
assert.strictEqual(err.name, "InvalidOperationException");
assert.ok(err.message.includes(
"is not associated with the session, cannot delete unknown entity instance"));
}
});
it("loadingDeletedDocumentShouldReturnNull", async () => {
{
const session = store.openSession();
const user1 = new User();
user1.name = "John";
user1.id = "users/1";
const user2 = new User();
user2.name = "Jonathan";
user2.id = "users/2";
await session.store(user1);
await session.store(user2);
await session.saveChanges();
}
{
const session = store.openSession();
await session.delete("users/1");
await session.delete("users/2");
await session.saveChanges();
}
{
const session = store.openSession();
assert.ok(!await session.load("users/1"));
assert.ok(!await session.load("users/2"));
}
});
it("storingDocumentWithTheSameIdInTheSameSessionShouldThrow", async () => {
const session = store.openSession();
const user = new User();
user.id = "users/1";
user.name = "User1";
await session.store(user);
await session.saveChanges();
const newUser = new User();
newUser.name = "User2";
newUser.id = "users/1";
try {
await session.store(newUser);
assert.fail("Should have thrown.");
} catch (err) {
assert.strictEqual(err.name, "NonUniqueObjectException");
assert.ok(err.message.includes("Attempted to associate a different object with id 'users/1'"));
}
});
});