File tree 2 files changed +6
-17
lines changed 2 files changed +6
-17
lines changed Original file line number Diff line number Diff line change 10
10
*/
11
11
12
12
import Storage from './Storage' ;
13
+ const uuidv4 = require ( 'uuid/v4' ) ;
13
14
14
15
let iidCache = null ;
15
16
16
- function hexOctet ( ) {
17
- return Math . floor (
18
- ( 1 + Math . random ( ) ) * 0x10000
19
- ) . toString ( 16 ) . substring ( 1 ) ;
20
- }
21
-
22
- function generateId ( ) {
23
- return (
24
- hexOctet ( ) + hexOctet ( ) + '-' +
25
- hexOctet ( ) + '-' +
26
- hexOctet ( ) + '-' +
27
- hexOctet ( ) + '-' +
28
- hexOctet ( ) + hexOctet ( ) + hexOctet ( )
29
- ) ;
30
- }
31
-
32
17
const InstallationController = {
33
18
currentInstallationId ( ) : Promise < string > {
34
19
if ( typeof iidCache === 'string' ) {
@@ -37,7 +22,7 @@ const InstallationController = {
37
22
const path = Storage . generatePath ( 'installationId' ) ;
38
23
return Storage . getItemAsync ( path ) . then ( ( iid ) => {
39
24
if ( ! iid ) {
40
- iid = generateId ( ) ;
25
+ iid = uuidv4 ( ) ;
41
26
return Storage . setItemAsync ( path , iid ) . then ( ( ) => {
42
27
iidCache = iid ;
43
28
return iid ;
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ jest.dontMock('../CoreManager');
11
11
jest . dontMock ( '../InstallationController' ) ;
12
12
jest . dontMock ( '../Storage' ) ;
13
13
jest . dontMock ( '../StorageController.default' ) ;
14
+ jest . mock ( 'uuid/v4' , ( ) => {
15
+ let value = 0 ;
16
+ return ( ) => value ++ + '' ;
17
+ } ) ;
14
18
15
19
const CoreManager = require ( '../CoreManager' ) ;
16
20
const InstallationController = require ( '../InstallationController' ) ;
You can’t perform that action at this time.
0 commit comments