@@ -15,7 +15,10 @@ const Entity = require('../../lib/entity');
15
15
const gstore = new Gstore ( ) ;
16
16
const chance = new Chance ( ) ;
17
17
18
- const ds = new Datastore ( { projectId : 'gstore-integration-testsx' } ) ;
18
+ const ds = new Datastore ( {
19
+ projectId : 'gstore-integration-tests' ,
20
+ keyFilename : '/Users/sebastien/secure-keys/gstore-integration-tests-67ddd52037cf.json' ,
21
+ } ) ;
19
22
gstore . connect ( ds ) ;
20
23
21
24
const { expect, assert } = chai ;
@@ -40,7 +43,7 @@ const cleanUp = cb => {
40
43
} ) ;
41
44
} ;
42
45
43
- const randomName = ( ) => chance . string ( { pool : 'abcdefghijklmnopqrstuvwxyz ' } ) ;
46
+ const randomName = ( ) => chance . string ( { pool : 'abcdefghijklmnopqrstuvwxyz0123456789 ' } ) ;
44
47
45
48
describe ( 'Model (Integration Tests)' , ( ) => {
46
49
after ( function afterAllIntTest ( done ) {
@@ -92,7 +95,7 @@ describe('Model (Integration Tests)', () => {
92
95
const name = randomName ( ) ;
93
96
const user = new UserModel ( {
94
97
name, company, email : chance . email ( ) , private : randomName ( ) ,
95
- } ) ;
98
+ } , randomName ( ) ) ;
96
99
return user . save ( )
97
100
. then ( ( { entityKey } ) => {
98
101
addKey ( entityKey ) ;
@@ -102,7 +105,7 @@ describe('Model (Integration Tests)', () => {
102
105
103
106
const addPost = ( userKey = null , publicationKey = null ) => {
104
107
const title = randomName ( ) ;
105
- const post = new PostModel ( { title, user : userKey , publication : publicationKey } ) ;
108
+ const post = new PostModel ( { title, user : userKey , publication : publicationKey } , randomName ( ) ) ;
106
109
return post . save ( )
107
110
. then ( ( { entityKey } ) => {
108
111
addKey ( entityKey ) ;
@@ -125,24 +128,24 @@ describe('Model (Integration Tests)', () => {
125
128
const { name : userName , entityKey : userKey } = await addUser ( ) ;
126
129
const { entityKey : postKey } = await addPost ( userKey ) ;
127
130
128
- const { entityData } = await PostModel . get ( postKey . id ) . populate ( 'user' ) ;
129
- expect ( entityData . user . id ) . equal ( userKey . id ) ;
131
+ const { entityData } = await PostModel . get ( postKey . name ) . populate ( 'user' ) ;
132
+ expect ( entityData . user . id ) . equal ( userKey . name ) ;
130
133
expect ( entityData . user . name ) . equal ( userName ) ;
131
134
assert . isUndefined ( entityData . user . private ) ; // make sure "read: false" is not leaked
132
135
} ) ;
133
136
134
137
it ( 'should return "null" if trying to populate a prop that does not exist' , async ( ) => {
135
138
const { entityKey : postKey } = await addPost ( ) ;
136
139
137
- const { entityData } = await PostModel . get ( postKey . id ) . populate ( 'unknown' ) ;
140
+ const { entityData } = await PostModel . get ( postKey . name ) . populate ( 'unknown' ) ;
138
141
expect ( entityData . unknown ) . equal ( null ) ;
139
142
} ) ;
140
143
141
144
it ( 'should populate multiple props' , async ( ) => {
142
145
const { name : userName , entityKey : userKey } = await addUser ( ) ;
143
146
const { entityKey : postKey } = await addPost ( userKey ) ;
144
147
145
- const { entityData } = await PostModel . get ( postKey . id ) . populate ( [ 'user' , 'publication' , 'unknown' ] ) ;
148
+ const { entityData } = await PostModel . get ( postKey . name ) . populate ( [ 'user' , 'publication' , 'unknown' ] ) ;
146
149
expect ( entityData . user . name ) . equal ( userName ) ;
147
150
expect ( entityData . publication ) . equal ( null ) ;
148
151
expect ( entityData . unknown ) . equal ( null ) ;
@@ -153,7 +156,7 @@ describe('Model (Integration Tests)', () => {
153
156
const { title : publicationTitle , entityKey : publicationKey } = await addPublication ( userKey ) ;
154
157
const { entityKey : postKey } = await addPost ( userKey , publicationKey ) ;
155
158
156
- const { entityData } = await PostModel . get ( postKey . id ) . populate ( [ 'user' , 'publication' ] ) ;
159
+ const { entityData } = await PostModel . get ( postKey . name ) . populate ( [ 'user' , 'publication' ] ) ;
157
160
expect ( entityData . user . name ) . equal ( userName ) ;
158
161
expect ( entityData . publication . title ) . equal ( publicationTitle ) ;
159
162
} ) ;
@@ -163,7 +166,7 @@ describe('Model (Integration Tests)', () => {
163
166
const { title : publicationTitle , entityKey : publicationKey } = await addPublication ( userKey ) ;
164
167
const { entityKey : postKey } = await addPost ( userKey , publicationKey ) ;
165
168
166
- const { entityData } = await PostModel . get ( postKey . id )
169
+ const { entityData } = await PostModel . get ( postKey . name )
167
170
. populate ( 'user' )
168
171
. populate ( 'publication' ) ;
169
172
expect ( entityData . user . name ) . equal ( userName ) ;
@@ -174,7 +177,7 @@ describe('Model (Integration Tests)', () => {
174
177
const { entityKey : userKey } = await addUser ( ) ;
175
178
const { entityKey : postKey } = await addPost ( userKey ) ;
176
179
177
- const { entityData } = await PostModel . get ( postKey . id ) . populate ( 'user' , [ 'email' , 'private' ] ) ;
180
+ const { entityData } = await PostModel . get ( postKey . name ) . populate ( 'user' , [ 'email' , 'private' ] ) ;
178
181
assert . isDefined ( entityData . user . email ) ;
179
182
assert . isUndefined ( entityData . user . name ) ;
180
183
assert . isDefined ( entityData . user . private ) ; // force get private fields
@@ -185,7 +188,7 @@ describe('Model (Integration Tests)', () => {
185
188
const { entityKey : postKey } = await addPost ( userKey ) ;
186
189
187
190
try {
188
- await PostModel . get ( postKey . id ) . populate ( [ 'user' , 'publication' ] , [ 'email' , 'private' ] ) ;
191
+ await PostModel . get ( postKey . name ) . populate ( [ 'user' , 'publication' ] , [ 'email' , 'private' ] ) ;
189
192
throw new Error ( 'Shoud not get here.' ) ;
190
193
} catch ( err ) {
191
194
expect ( err . message ) . equal ( 'Only 1 property can be populated when fields to select are provided' ) ;
@@ -198,10 +201,10 @@ describe('Model (Integration Tests)', () => {
198
201
const { entityKey : postKey1 } = await addPost ( userKey1 ) ;
199
202
const { entityKey : postKey2 } = await addPost ( userKey2 ) ;
200
203
201
- const [ post1 , post2 ] = await PostModel . get ( [ postKey1 . id , postKey2 . id ] ) . populate ( 'user' ) ;
202
- expect ( post1 . entityData . user . id ) . equal ( userKey1 . id ) ;
204
+ const [ post1 , post2 ] = await PostModel . get ( [ postKey1 . name , postKey2 . name ] ) . populate ( 'user' ) ;
205
+ expect ( post1 . entityData . user . id ) . equal ( userKey1 . name ) ;
203
206
expect ( post1 . entityData . user . name ) . equal ( userName1 ) ;
204
- expect ( post2 . entityData . user . id ) . equal ( userKey2 . id ) ;
207
+ expect ( post2 . entityData . user . id ) . equal ( userKey2 . name ) ;
205
208
expect ( post2 . entityData . user . name ) . equal ( userName2 ) ;
206
209
} ) ;
207
210
@@ -211,14 +214,14 @@ describe('Model (Integration Tests)', () => {
211
214
const { title : publicationTitle , entityKey : publicationKey } = await addPublication ( userKey ) ;
212
215
const { entityKey : postKey } = await addPost ( userKey , publicationKey ) ;
213
216
214
- const { entityData } = await PostModel . get ( postKey . id )
217
+ const { entityData } = await PostModel . get ( postKey . name )
215
218
. populate ( [ 'user' , 'user.company' ] )
216
219
. populate ( 'publication' )
217
220
. populate ( 'publication.user' )
218
221
. populate ( 'publication.user.company' )
219
222
. populate ( 'path.that.does.not.exist' ) ;
220
223
221
- expect ( entityData . user . id ) . equal ( userKey . id ) ;
224
+ expect ( entityData . user . id ) . equal ( userKey . name ) ;
222
225
expect ( entityData . user . name ) . equal ( userName ) ;
223
226
expect ( entityData . user . company . name ) . equal ( companyName ) ;
224
227
expect ( entityData . publication . title ) . equal ( publicationTitle ) ;
@@ -230,7 +233,7 @@ describe('Model (Integration Tests)', () => {
230
233
const { name : userName , entityKey : userKey } = await addUser ( ) ;
231
234
const { entityKey : postKey } = await addPost ( userKey ) ;
232
235
233
- const { entityData } = await PostModel . get ( postKey . id ) . populate ( ) ;
236
+ const { entityData } = await PostModel . get ( postKey . name ) . populate ( ) ;
234
237
expect ( entityData . user . name ) . equal ( userName ) ;
235
238
expect ( entityData . publication ) . equal ( null ) ;
236
239
assert . isUndefined ( entityData . user . private ) ; // make sure "read: false" is not leaked
@@ -244,7 +247,7 @@ describe('Model (Integration Tests)', () => {
244
247
const { entityKey : postKey } = await addPost ( userKey ) ;
245
248
246
249
await transaction . run ( ) ;
247
- const { entityData } = await PostModel . get ( postKey . id , null , null , transaction ) . populate ( 'user' ) ;
250
+ const { entityData } = await PostModel . get ( postKey . name , null , null , transaction ) . populate ( 'user' ) ;
248
251
await transaction . commit ( ) ;
249
252
expect ( transaction . get . called ) . equal ( true ) ;
250
253
expect ( transaction . get . callCount ) . equal ( 2 ) ;
@@ -274,19 +277,19 @@ describe('Model (Integration Tests)', () => {
274
277
const transaction = gstore . transaction ( ) ;
275
278
return transaction . run ( )
276
279
. then ( async ( ) => {
277
- await User . update ( fromUser . entityKey . id , {
280
+ await User . update ( fromUser . entityKey . name , {
278
281
coins : fromUser . coins - amount ,
279
282
} , null , null , transaction ) ;
280
283
281
- await User . update ( toUser . entityKey . id , {
284
+ await User . update ( toUser . entityKey . name , {
282
285
coins : toUser . coins + amount ,
283
286
} , null , null , transaction ) ;
284
287
285
288
transaction . commit ( )
286
289
. then ( async ( ) => {
287
290
const [ user1 , user2 ] = await User . get ( [
288
- fromUser . entityKey . id ,
289
- toUser . entityKey . id ,
291
+ fromUser . entityKey . name ,
292
+ toUser . entityKey . name ,
290
293
] , null , null , null , { preserveOrder : true } ) ;
291
294
expect ( user1 . name ) . equal ( 'User1' ) ;
292
295
expect ( user1 . coins ) . equal ( 0 ) ;
@@ -303,8 +306,8 @@ describe('Model (Integration Tests)', () => {
303
306
} ) ;
304
307
}
305
308
306
- const fromUser = new User ( { name : 'User1' , coins : 1000 } ) ;
307
- const toUser = new User ( { name : 'User2' , coins : 50 } ) ;
309
+ const fromUser = new User ( { name : 'User1' , coins : 1000 } , randomName ( ) ) ;
310
+ const toUser = new User ( { name : 'User2' , coins : 50 } , randomName ( ) ) ;
308
311
309
312
return fromUser . save ( )
310
313
. then ( ( { entityKey } ) => {
@@ -319,7 +322,6 @@ describe('Model (Integration Tests)', () => {
319
322
} ) ;
320
323
} ) ;
321
324
322
-
323
325
describe ( 'hooks' , ( ) => {
324
326
it ( 'post delete hook should set scope on entity instance' , ( ) => {
325
327
const schema = new Schema ( { name : { type : 'string' } } ) ;
0 commit comments