@@ -150,6 +150,46 @@ function runTest(controller) {
150150 }
151151 } ) ;
152152
153+ it ( `${ controller . name } can pin user (unsaved)` , async ( ) => {
154+ const user = new Parse . User ( ) ;
155+ user . set ( 'field' , 'test' ) ;
156+ await user . pin ( ) ;
157+
158+ const json = user . _toFullJSON ( ) ;
159+ json . _localId = user . _localId ;
160+
161+ const localDatastore = await Parse . LocalDatastore . _getAllContents ( ) ;
162+ const cachedObject = localDatastore [ LDS_KEY ( user ) ] [ 0 ] ;
163+ assert . equal ( Object . keys ( localDatastore ) . length , 2 ) ;
164+ assert . deepEqual ( localDatastore [ DEFAULT_PIN ] , [ LDS_KEY ( user ) ] ) ;
165+ assert . deepEqual ( localDatastore [ LDS_KEY ( user ) ] , [ json ] ) ;
166+ assert . equal ( cachedObject . objectId , user . id ) ;
167+ assert . equal ( cachedObject . field , 'test' ) ;
168+ await Parse . User . logOut ( ) ;
169+ } ) ;
170+
171+ it ( `${ controller . name } can pin user (saved)` , async ( ) => {
172+ const user = new Parse . User ( ) ;
173+ user . set ( 'field' , 'test' ) ;
174+ user . setPassword ( 'asdf' ) ;
175+ user . setUsername ( 'zxcv' ) ;
176+ await user . signUp ( )
177+ await user . pin ( ) ;
178+
179+ const json = user . _toFullJSON ( ) ;
180+ delete json . password ;
181+
182+ const localDatastore = await Parse . LocalDatastore . _getAllContents ( ) ;
183+ const cachedObject = localDatastore [ LDS_KEY ( user ) ] [ 0 ] ;
184+
185+ assert . equal ( Object . keys ( localDatastore ) . length , 2 ) ;
186+ assert . deepEqual ( localDatastore [ DEFAULT_PIN ] , [ LDS_KEY ( user ) ] ) ;
187+ assert . deepEqual ( localDatastore [ LDS_KEY ( user ) ] , [ json ] ) ;
188+ assert . equal ( cachedObject . objectId , user . id ) ;
189+ assert . equal ( cachedObject . field , 'test' ) ;
190+ await Parse . User . logOut ( ) ;
191+ } ) ;
192+
153193 it ( `${ controller . name } can pin (saved)` , async ( ) => {
154194 const object = new TestObject ( ) ;
155195 object . set ( 'field' , 'test' ) ;
@@ -218,6 +258,31 @@ function runTest(controller) {
218258 assert . deepEqual ( localDatastore [ LDS_KEY ( grandchild ) ] , [ grandchild . _toFullJSON ( ) ] ) ;
219259 } ) ;
220260
261+ it ( `${ controller . name } can pin user (recursive)` , async ( ) => {
262+ const parent = new TestObject ( ) ;
263+ const child = new Parse . User ( ) ;
264+ child . setUsername ( 'username' ) ;
265+ child . setPassword ( 'password' ) ;
266+ await child . signUp ( ) ;
267+ parent . set ( 'field' , 'test' ) ;
268+ parent . set ( 'child' , child ) ;
269+ await parent . save ( ) ;
270+ await parent . pin ( ) ;
271+
272+ const parentJSON = parent . _toFullJSON ( ) ;
273+ const childJSON = child . _toFullJSON ( ) ;
274+ delete childJSON . password ;
275+ delete parentJSON . child . password ;
276+
277+ const localDatastore = await Parse . LocalDatastore . _getAllContents ( ) ;
278+ assert . equal ( Object . keys ( localDatastore ) . length , 3 ) ;
279+ assert . equal ( localDatastore [ DEFAULT_PIN ] . includes ( LDS_KEY ( parent ) ) , true ) ;
280+ assert . equal ( localDatastore [ DEFAULT_PIN ] . includes ( LDS_KEY ( child ) ) , true ) ;
281+ assert . deepEqual ( localDatastore [ LDS_KEY ( parent ) ] , [ parentJSON ] ) ;
282+ assert . deepEqual ( localDatastore [ LDS_KEY ( child ) ] , [ childJSON ] ) ;
283+ await Parse . User . logOut ( ) ;
284+ } ) ;
285+
221286 it ( `${ controller . name } can pinAll (unsaved)` , async ( ) => {
222287 const obj1 = new TestObject ( ) ;
223288 const obj2 = new TestObject ( ) ;
@@ -945,6 +1010,27 @@ function runTest(controller) {
9451010 const itemJSON = updatedLDS [ LDS_KEY ( item ) ] ;
9461011 assert . equal ( itemJSON . foo , 'changed' ) ;
9471012 } ) ;
1013+
1014+ it ( `${ controller . name } can update Local Datastore User from network` , async ( ) => {
1015+ const user = new Parse . User ( ) ;
1016+ user . setUsername ( 'asdf' ) ;
1017+ user . setPassword ( 'zxcv' ) ;
1018+ await user . signUp ( ) ;
1019+ await user . pin ( ) ;
1020+
1021+ // Updates user with { foo: 'changed' }
1022+ const params = { id : user . id } ;
1023+ await Parse . Cloud . run ( 'UpdateUser' , params ) ;
1024+
1025+ Parse . LocalDatastore . isSyncing = false ;
1026+
1027+ await Parse . LocalDatastore . updateFromServer ( ) ;
1028+
1029+ const updatedLDS = await Parse . LocalDatastore . _getAllContents ( ) ;
1030+ const userJSON = updatedLDS [ LDS_KEY ( user ) ] ;
1031+ assert . equal ( userJSON . foo , 'changed' ) ;
1032+ await Parse . User . logOut ( ) ;
1033+ } ) ;
9481034 } ) ;
9491035
9501036 describe ( `Parse Query Pinning (${ controller . name } )` , ( ) => {
@@ -1016,6 +1102,19 @@ function runTest(controller) {
10161102 assert . equal ( results . length , 3 ) ;
10171103 } ) ;
10181104
1105+ it ( `${ controller . name } can query user from pin` , async ( ) => {
1106+ const user = await Parse . User . signUp ( 'asdf' , 'zxcv' , { foo : 'bar' } ) ;
1107+ await user . pin ( ) ;
1108+
1109+ const query = new Parse . Query ( Parse . User ) ;
1110+ query . fromPin ( ) ;
1111+ const results = await query . find ( ) ;
1112+
1113+ assert . equal ( results . length , 1 ) ;
1114+ assert . equal ( results [ 0 ] . getSessionToken ( ) , user . getSessionToken ( ) ) ;
1115+ await Parse . User . logOut ( ) ;
1116+ } ) ;
1117+
10191118 it ( `${ controller . name } can do basic queries` , async ( ) => {
10201119 const baz = new TestObject ( { foo : 'baz' } ) ;
10211120 const qux = new TestObject ( { foo : 'qux' } ) ;
@@ -2551,6 +2650,7 @@ describe('Parse LocalDatastore', () => {
25512650 Parse . initialize ( 'integration' , null , 'notsosecret' ) ;
25522651 Parse . CoreManager . set ( 'SERVER_URL' , 'http://localhost:1337/parse' ) ;
25532652 Parse . enableLocalDatastore ( ) ;
2653+ Parse . User . enableUnsafeCurrentUser ( ) ;
25542654 Parse . Storage . _clear ( ) ;
25552655 clear ( ) . then ( ( ) => {
25562656 done ( )
0 commit comments