forked from parse-community/Parse-SDK-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstallationController-test.js
98 lines (86 loc) · 3.71 KB
/
InstallationController-test.js
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
jest.dontMock('../CoreManager');
jest.dontMock('../decode');
jest.dontMock('../encode');
jest.dontMock('../InstallationController');
jest.dontMock('../ObjectStateMutations');
jest.dontMock('../ParseInstallation');
jest.dontMock('../ParseObject');
jest.dontMock('../ParseOp');
jest.dontMock('../Storage');
jest.dontMock('../StorageController.default');
jest.dontMock('../SingleInstanceStateController');
jest.dontMock('../UniqueInstanceStateController');
jest.mock('../uuid', () => {
let value = 0;
return () => value++ + '';
});
const CoreManager = require('../CoreManager').default;
const ParseInstallation = require('../ParseInstallation').default;
const InstallationController = require('../InstallationController').default;
const Storage = require('../Storage').default;
CoreManager.setStorageController(require('../StorageController.default').default);
describe('InstallationController', () => {
beforeEach(() => {
CoreManager.set('APPLICATION_ID', 'A');
CoreManager.set('JAVASCRIPT_KEY', 'B');
Storage._clear();
InstallationController._clearCache();
});
it('generates a new installation id when there is none', async () => {
const iid = await InstallationController.currentInstallationId();
expect(typeof iid).toBe('string');
expect(iid.length).toBeGreaterThan(0);
});
it('caches the installation id', async () => {
const iid = await InstallationController.currentInstallationId();
Storage._clear();
const i = await InstallationController.currentInstallationId();
expect(i).toBe(iid);
});
it('permanently stores the installation id', async () => {
const iid = await InstallationController.currentInstallationId();
InstallationController._clearCache();
const i = await InstallationController.currentInstallationId();
expect(i).toBe(iid);
});
it('can set installation id', async () => {
const iid = '12345678';
InstallationController._setInstallationIdCache(iid);
const i = await InstallationController.currentInstallationId();
expect(i).toBe(iid);
});
it('generates a new installation when there is none', async () => {
const installation = await InstallationController.currentInstallation();
expect(installation instanceof ParseInstallation).toBe(true);
expect(installation.deviceType).toBe('web');
expect(installation.installationId).toBeDefined();
});
it('caches the current installation', async () => {
const iid = 'cached-installation-id';
InstallationController._setInstallationIdCache(iid);
const installation = await InstallationController.currentInstallation();
Storage._clear();
const i = await InstallationController.currentInstallation();
expect(i.installationId).toEqual(installation.installationId);
});
it('permanently stores the current installation', async () => {
const iid = 'stored-installation-id';
InstallationController._setInstallationIdCache(iid);
const installation = await InstallationController.currentInstallation();
InstallationController._clearCache();
const i = await InstallationController.currentInstallation();
expect(i.installationId).toEqual(installation.installationId);
});
it('can update installation on disk', async () => {
const installationId = 'new-installation-id';
const installation = new ParseInstallation({ installationId });
InstallationController.updateInstallationOnDisk(installation);
const i = await InstallationController.currentInstallation();
expect(i.installationId).toBe(installationId);
});
it('can handle cache not matching disk', async () => {
InstallationController._setCurrentInstallationCache(null, true);
const i = await InstallationController.currentInstallation();
expect(i).toBeNull();
});
});