Skip to content

Commit 89b1b6a

Browse files
committed
Stabilize role cache deletion tests
Refactors ParseRole cache invalidation specs to use the app config controllers instead of global server state, and adds explicit spies for both role cache and LiveQuery role cache clearing. The role-deletion test now waits on the actual clear promise rather than a fixed timeout, making it deterministic, while the non-role deletion test verifies no cache clear methods are called.
1 parent 619e7cb commit 89b1b6a

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

spec/ParseRole.spec.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -677,30 +677,42 @@ describe('Parse Role testing', () => {
677677
});
678678

679679
it('clears the role cache when a role is deleted', async () => {
680-
const cacheController = Parse.Server.cacheController;
680+
const config = Config.get(Parse.applicationId);
681681
const role = new Parse.Role('Doomed', new Parse.ACL());
682682
await role.save(null, { useMasterKey: true });
683683

684684
// Saving the role already clears the cache, so seed the entry afterwards.
685-
await cacheController.role.put('someUser', ['role:Doomed']);
686-
expect(await cacheController.role.get('someUser')).toEqual(['role:Doomed']);
685+
await config.cacheController.role.put('someUser', ['role:Doomed']);
686+
expect(await config.cacheController.role.get('someUser')).toEqual(['role:Doomed']);
687+
688+
const clearSpy = spyOn(config.cacheController.role, 'clear').and.callThrough();
689+
const liveQuerySpy = spyOn(config.liveQueryController, 'clearCachedRoles').and.callThrough();
687690

688691
await role.destroy({ useMasterKey: true });
689-
// The clear is issued without being awaited, matching RestWrite.
690-
await new Promise(resolve => setTimeout(resolve, 200));
691692

692-
expect(await cacheController.role.get('someUser')).toEqual(null);
693+
expect(clearSpy).toHaveBeenCalledTimes(1);
694+
expect(liveQuerySpy).toHaveBeenCalledTimes(1);
695+
// The clear is issued without being awaited, matching RestWrite, so wait on
696+
// the promise the call returned rather than on a fixed delay.
697+
await clearSpy.calls.mostRecent().returnValue;
698+
699+
expect(await config.cacheController.role.get('someUser')).toEqual(null);
693700
});
694701

695702
it('leaves the role cache alone when a non-role object is deleted', async () => {
696-
const cacheController = Parse.Server.cacheController;
703+
const config = Config.get(Parse.applicationId);
697704
const object = new Parse.Object('TestObject');
698705
await object.save(null, { useMasterKey: true });
699706

700-
await cacheController.role.put('someUser', ['role:Admin']);
707+
await config.cacheController.role.put('someUser', ['role:Admin']);
708+
709+
const clearSpy = spyOn(config.cacheController.role, 'clear').and.callThrough();
710+
const liveQuerySpy = spyOn(config.liveQueryController, 'clearCachedRoles').and.callThrough();
711+
701712
await object.destroy({ useMasterKey: true });
702-
await new Promise(resolve => setTimeout(resolve, 200));
703713

704-
expect(await cacheController.role.get('someUser')).toEqual(['role:Admin']);
714+
expect(clearSpy).not.toHaveBeenCalled();
715+
expect(liveQuerySpy).not.toHaveBeenCalled();
716+
expect(await config.cacheController.role.get('someUser')).toEqual(['role:Admin']);
705717
});
706718
});

0 commit comments

Comments
 (0)