|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | const assert = require('assert');
|
4 |
| -const Parse = require('../../node'); |
5 | 4 |
|
6 | 5 | global.localStorage = require('./mockLocalStorage');
|
| 6 | +global.WebSocket = require('ws'); |
7 | 7 | const mockRNStorage = require('./mockRNStorage');
|
8 |
| -const LocalDatastoreUtils = require('../../lib/node/LocalDatastoreUtils'); |
| 8 | +const serverURL = 'http://localhost:1337/parse'; |
9 | 9 |
|
10 |
| -const { DEFAULT_PIN, PIN_PREFIX, isLocalDatastoreKey } = LocalDatastoreUtils; |
| 10 | +function runTest(controller) { |
| 11 | + const Parse = require(`../../${controller.name}`); |
| 12 | + const LocalDatastoreUtils = require('../../lib/node/LocalDatastoreUtils'); |
11 | 13 |
|
12 |
| -function LDS_KEY(object) { |
13 |
| - return Parse.LocalDatastore.getKeyForObject(object); |
14 |
| -} |
15 |
| -function LDS_FULL_JSON(object) { |
16 |
| - const json = object._toFullJSON(); |
17 |
| - if (object._localId) { |
18 |
| - json._localId = object._localId; |
| 14 | + const { DEFAULT_PIN, PIN_PREFIX, isLocalDatastoreKey } = LocalDatastoreUtils; |
| 15 | + |
| 16 | + const Item = Parse.Object.extend('Item'); |
| 17 | + const TestObject = Parse.Object.extend('TestObject'); |
| 18 | + |
| 19 | + function LDS_KEY(object) { |
| 20 | + return Parse.LocalDatastore.getKeyForObject(object); |
19 | 21 | }
|
20 |
| - return json; |
21 |
| -} |
22 |
| -function runTest(controller) { |
| 22 | + function LDS_FULL_JSON(object) { |
| 23 | + const json = object._toFullJSON(); |
| 24 | + if (object._localId) { |
| 25 | + json._localId = object._localId; |
| 26 | + } |
| 27 | + return json; |
| 28 | + } |
| 29 | + |
23 | 30 | describe(`Parse Object Pinning (${controller.name})`, () => {
|
24 | 31 | beforeEach(async () => {
|
25 | 32 | const StorageController = require(controller.file);
|
26 | 33 | Parse.CoreManager.setAsyncStorage(mockRNStorage);
|
27 | 34 | Parse.CoreManager.setLocalDatastoreController(StorageController);
|
28 |
| - Parse.enableLocalDatastore(); |
| 35 | + Parse.CoreManager.setEventEmitter(require('events').EventEmitter); |
| 36 | + Parse.User.enableUnsafeCurrentUser(); |
29 | 37 | await Parse.LocalDatastore._clear();
|
| 38 | + Parse.initialize('integration'); |
| 39 | + Parse.CoreManager.set('SERVER_URL', serverURL); |
| 40 | + Parse.CoreManager.set('MASTER_KEY', 'notsosecret'); |
| 41 | + const RESTController = Parse.CoreManager.getRESTController(); |
| 42 | + RESTController._setXHR(require('xmlhttprequest').XMLHttpRequest); |
| 43 | + Parse.enableLocalDatastore(); |
30 | 44 | });
|
| 45 | + |
31 | 46 | function getStorageCount(storage) {
|
32 | 47 | return Object.keys(storage).reduce((acc, key) => acc + (isLocalDatastoreKey(key) ? 1 : 0), 1);
|
33 | 48 | }
|
| 49 | + |
34 | 50 | it(`${controller.name} can clear localDatastore`, async () => {
|
35 | 51 | const obj1 = new TestObject();
|
36 | 52 | const obj2 = new TestObject();
|
@@ -1060,8 +1076,15 @@ function runTest(controller) {
|
1060 | 1076 | const StorageController = require(controller.file);
|
1061 | 1077 | Parse.CoreManager.setAsyncStorage(mockRNStorage);
|
1062 | 1078 | Parse.CoreManager.setLocalDatastoreController(StorageController);
|
1063 |
| - Parse.enableLocalDatastore(); |
| 1079 | + Parse.CoreManager.setEventEmitter(require('events').EventEmitter); |
1064 | 1080 | Parse.LocalDatastore._clear();
|
| 1081 | + Parse.User.enableUnsafeCurrentUser(); |
| 1082 | + Parse.initialize('integration'); |
| 1083 | + Parse.CoreManager.set('SERVER_URL', serverURL); |
| 1084 | + Parse.CoreManager.set('MASTER_KEY', 'notsosecret'); |
| 1085 | + const RESTController = Parse.CoreManager.getRESTController(); |
| 1086 | + RESTController._setXHR(require('xmlhttprequest').XMLHttpRequest); |
| 1087 | + Parse.enableLocalDatastore(); |
1065 | 1088 |
|
1066 | 1089 | const numbers = [];
|
1067 | 1090 | for (let i = 0; i < 10; i++) {
|
@@ -2949,20 +2972,10 @@ function runTest(controller) {
|
2949 | 2972 | }
|
2950 | 2973 |
|
2951 | 2974 | describe('Parse LocalDatastore', () => {
|
2952 |
| - beforeEach(() => { |
2953 |
| - Parse.CoreManager.getInstallationController()._setInstallationIdCache('1234'); |
2954 |
| - Parse.enableLocalDatastore(); |
2955 |
| - Parse.User.enableUnsafeCurrentUser(); |
2956 |
| - }); |
2957 |
| - |
2958 | 2975 | const controllers = [
|
2959 |
| - { name: 'Default', file: '../../lib/node/LocalDatastoreController' }, |
2960 |
| - { |
2961 |
| - name: 'React-Native', |
2962 |
| - file: '../../lib/node/LocalDatastoreController.react-native', |
2963 |
| - }, |
| 2976 | + { name: 'node', file: '../../lib/node/LocalDatastoreController' }, |
| 2977 | + { name: 'react-native', file: '../../lib/react-native/LocalDatastoreController.react-native' }, |
2964 | 2978 | ];
|
2965 |
| - |
2966 | 2979 | for (let i = 0; i < controllers.length; i += 1) {
|
2967 | 2980 | const controller = controllers[i];
|
2968 | 2981 | runTest(controller);
|
|
0 commit comments