-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathrql-data-models.js
62 lines (60 loc) · 1.74 KB
/
rql-data-models.js
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
import Realm from "realm";
import { ItemModel, ProjectModel } from "./schemas/rql-data-models";
/*
DON'T UPDATE THIS FILE. DEPRECATED IN FAVOR OF V12 TESTS.
Updates should be placed in the new files compatible with
JSv12 and later, located at:
examples/node/v12/__tests__/rql-data-models.test.js/ts
*/
describe("test models", () => {
let realm;
const config = {
schema: [ItemModel, ProjectModel],
path: "testing.realm",
};
beforeEach(async () => {
realm = await Realm.open(config);
});
afterEach(() => {
realm.write(() => {
realm.deleteAll();
});
realm.close();
expect(realm.isClosed).toBe(true);
});
afterAll(() => {
Realm.deleteFile(config);
});
test("open realm with config", async () => {
expect(realm.isClosed).toBe(false);
});
test("Can create object of Item type", () => {
realm.write(() => {
realm.create("Item", {
id: new Realm.BSON.ObjectId(),
name: "get coffee",
});
});
const coffeeItem = realm.objects("Item")[0];
expect(coffeeItem.id instanceof Realm.BSON.ObjectId).toBe(true);
expect(coffeeItem.name).toBe("get coffee");
expect(coffeeItem.isComplete).toBe(false);
});
test("Can create object of Project type", () => {
realm.write(() => {
const teaItem = realm.create("Item", {
id: new Realm.BSON.ObjectId(),
name: "get tea",
});
realm.create("Project", {
id: new Realm.BSON.ObjectId(),
name: "beverages",
items: [teaItem],
});
});
const bevProject = realm.objects("Project")[0];
expect(bevProject.id instanceof Realm.BSON.ObjectId).toBe(true);
expect(bevProject.name).toBe("beverages");
expect(bevProject.items[0].name).toBe("get tea");
});
});