-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathRDBC_649.ts
84 lines (69 loc) · 2.17 KB
/
RDBC_649.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
import { testContext, disposeTestDocumentStore } from "../Utils/TestUtil";
import * as assert from "assert";
import {
IDocumentSession,
IDocumentStore
} from "../../src";
class User {
public name: string;
public age: number;
public registeredAt: Date;
constructor(opts: object) {
opts = opts || {};
Object.assign(this, opts);
}
}
describe("RDBC-649", function () {
let store: IDocumentStore;
let session: IDocumentSession;
beforeEach(async function () {
store = await testContext.getDocumentStore();
session = store.openSession();
});
afterEach(async () =>
await disposeTestDocumentStore(store));
describe("default operator for query", function () {
beforeEach(async () => prepareUserDataSet(store));
it("AND is used when default operator is not set", async () => {
const queryResults = await session.query({ collection: "users" })
.whereExists("kids")
.whereLessThan("age", 29)
.all();
assert.strictEqual(queryResults.length, 0);
});
it("set default operator to OR", async () => {
const queryResults = await session.query({ collection: "users" })
.usingDefaultOperator("OR") // override the default 'AND' operator
.whereExists("kids")
.whereLessThan("age", 29)
.all();
assert.strictEqual(queryResults.length, 3);
});
});
});
async function prepareUserDataSet(store: IDocumentStore) {
const users = [
new User({
name: "John",
age: 30,
registeredAt: new Date(2017, 10, 11),
kids: ["Dmitri", "Mara"]
}),
new User({
name: "Stefanie",
age: 25,
registeredAt: new Date(2015, 6, 30)
}),
new User({
name: "Thomas",
age: 25,
registeredAt: new Date(2016, 3, 25)
})
];
const newSession = store.openSession();
for (const u of users) {
await newSession.store(u);
}
await newSession.saveChanges();
return users;
}