forked from GoogleCloudPlatform/nodejs-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcepts.test.js
More file actions
282 lines (221 loc) · 6.85 KB
/
concepts.test.js
File metadata and controls
282 lines (221 loc) · 6.85 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Copyright 2015, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';
var testUtil = require('./util.js');
var concepts = require('../../datastore/concepts');
var transaction;
var metadata;
var index;
var query;
var entity;
var Transaction = concepts.Transaction;
var Metadata = concepts.Metadata;
var Index = concepts.Index;
var Entity = concepts.Entity;
var Query = concepts.Query;
describe('datastore:concepts', function () {
before(function () {
var projectId = process.env.GCLOUD_PROJECT || 'nodejs-docs-samples';
transaction = new Transaction(projectId);
metadata = new Metadata(projectId);
index = new Index(projectId);
entity = new Entity(projectId);
query = new Query(projectId);
});
after(function (done) {
var datastore = transaction.datastore;
var query = datastore.createQuery('Task');
testUtil.deleteEntities(datastore, query, done);
});
// Transactions
it('performs a transactional update', function (done) {
transaction.testTransactionalUpdate(done);
});
it('performs retries if necessary', function (done) {
transaction.testTransactionalRetry(done);
});
it('performs a get or create', function (done) {
transaction.testTransactionalGetOrCreate(done);
});
it('gets a snapshot of task list entities', function (done) {
transaction.testSingleEntityGroupReadOnly(done);
});
// Metadata
it('performs a namespace query', function (done) {
metadata.testNamespaceRunQuery(done);
});
it('performs a kind query', function (done) {
metadata.testKindRunQuery(done);
});
it('performs a property query', function (done) {
metadata.testPropertyRunQuery(done);
});
it('performs a property by kind query', function (done) {
metadata.testPropertyByKindRunQuery(done);
});
// Indexes
it(
'performs a query with a filter on an unindexed property',
function (done) {
index.testUnindexedPropertyQuery(done);
}
);
it('inserts arrays of data', function (done) {
index.testExplodingProperties(done);
});
// Queries
it('performs a basic query', function (done) {
query.testRunQuery(done);
});
it('performs a query with a property filter', function (done) {
query.testPropertyFilter(done);
});
it('performs a query with a composite filter', function (done) {
query.testCompositeFilter(done);
});
it('performs a query with a key filter', function (done) {
query.testKeyFilter(done);
});
it('performs a query with ascending sort', function (done) {
query.testAscendingSort(done);
});
it('performs a query with descending sort', function (done) {
query.testDescendingSort(done);
});
it('performs a query with multi sort', function (done) {
query.testMultiSort(done);
});
it('performs a kindless query', function (done) {
query.testKindlessQuery(done);
});
it('performs a projection query', function (done) {
entity.testProperties(function (err, tasks) {
console.log(err, tasks);
assert(!err);
setTimeout(function () {
query.testRunQueryProjection(done);
}, 1000);
});
});
it('performs a keys only query', function (done) {
query.testKeysOnlyQuery(done);
});
it('performs a distinct query', function (done) {
query.testDistinctQuery(done);
});
it('performs a distinct on query', function (done) {
query.testDistinctOnQuery(done);
});
it('performs an array value inequality query', function (done) {
query.testArrayValueInequalityRange(done);
});
it('performs an array value equality query', function (done) {
query.testArrayValueEquality(done);
});
it('performs an inequality range query', function (done) {
query.testInequalityRange(done);
});
it('returns an error from an invalid query', function (done) {
query.testInequalityInvalid(function (err) {
assert(err);
done();
});
});
it('performs an equal and inequality range query', function (done) {
query.testEqualAndInequalityRange(done);
});
it('performs an equality sort query', function (done) {
query.testInequalitySort(done);
});
it(
'returns an error when not sorted on filtered property',
function (done) {
query.testInequalitySortInvalidNotSame(function (err) {
assert(err);
done();
});
}
);
it(
'returns an error when not sorted on first filter prop',
function (done) {
query.testInequalitySortInvalidNotFirst(function (err) {
assert(err);
done();
});
}
);
it('performs a query with a limit', function (done) {
query.testLimit(done);
});
it.skip('allows manual pagination through results', function (done) {
entity.testBatchUpsert(function (err) {
assert(!err);
setTimeout(function () {
query.testCursorPaging(done);
}, 1000);
});
});
it.skip('performs an ancestor query', function (done) {
query.testEventualConsistentQuery(done);
});
// Entities
it('saves with an incomplete key', function (done) {
entity.testIncompleteKey(done);
});
it('saves with a named key', function (done) {
entity.testNamedKey(done);
});
it('saves a key with a parent', function (done) {
entity.testKeyWithParent(done);
});
it('saves a key with multiple parents', function (done) {
entity.testKeyWithMultiLevelParent(done);
});
it('saves an entity with a parent', function (done) {
entity.testEntityWithParent(done);
});
it('saves an entity with properties', function (done) {
entity.testProperties(done);
});
it('saves an entity with arrays', function (done) {
entity.testArrayValue(done);
});
it('saves a basic entity', function (done) {
entity.testBasicEntity(done);
});
it('saves with an upsert', function (done) {
entity.testUpsert(done);
});
it('saves with an insert', function (done) {
entity.testInsert(done);
});
it('performs a lookup', function (done) {
entity.testLookup(done);
});
it('saves with an update', function (done) {
entity.testUpdate(done);
});
it('deletes an entity', function (done) {
entity.testDelete(done);
});
it('performs a batch upsert', function (done) {
entity.testBatchUpsert(done);
});
it('performs a batch lookup', function (done) {
entity.testBatchLookup(done);
});
it('performs a batch delete', function (done) {
entity.testBatchDelete(done);
});
});