@@ -8,6 +8,9 @@ var testUtils = require("./helpers/test_utils");
8
8
9
9
const { StorageTypes } = CountlyBulk ;
10
10
11
+ var appKey = "YOUR_APP_KEY" ;
12
+ var serverUrl = "https://tests.url.cly" ;
13
+
11
14
function validateCrash ( validator , nonfatal ) {
12
15
assert . ok ( validator . crash . _os ) ;
13
16
assert . ok ( validator . crash . _os_version ) ;
@@ -20,58 +23,6 @@ function validateCrash(validator, nonfatal) {
20
23
assert . equal ( true , validator . crash . _not_os_specific ) ;
21
24
}
22
25
23
- // note: this can replace the current one in the helper functions
24
- function validateUserDetails ( actual , expected ) {
25
- const keys = [ 'name' , 'username' , 'email' , 'organization' , 'phone' , 'picture' , 'gender' , 'byear' , 'custom' ] ;
26
- let isValid = true ;
27
-
28
- keys . forEach ( ( key ) => {
29
- if ( typeof actual [ key ] === 'object' && actual [ key ] !== null ) {
30
- if ( Array . isArray ( actual [ key ] ) ) {
31
- if ( ! Array . isArray ( expected [ key ] ) || JSON . stringify ( actual [ key ] ) !== JSON . stringify ( expected [ key ] ) ) {
32
- console . error ( `Mismatch for key "${ key } ": expected "${ JSON . stringify ( expected [ key ] ) } ", but got "${ JSON . stringify ( actual [ key ] ) } "` ) ;
33
- isValid = false ;
34
- }
35
- }
36
- else {
37
- if ( JSON . stringify ( actual [ key ] ) !== JSON . stringify ( expected [ key ] ) ) {
38
- console . error ( `Mismatch for key "${ key } ": expected "${ JSON . stringify ( expected [ key ] ) } ", but got "${ JSON . stringify ( actual [ key ] ) } "` ) ;
39
- isValid = false ;
40
- }
41
- }
42
- }
43
- else if ( actual [ key ] !== expected [ key ] ) {
44
- console . error ( `Mismatch for key "${ key } ": expected "${ expected [ key ] } ", but got "${ actual [ key ] } "` ) ;
45
- isValid = false ;
46
- }
47
- } ) ;
48
- // Validate nested custom object separately
49
- if ( expected . custom && actual . custom ) {
50
- const customKeys = Object . keys ( expected . custom ) ;
51
- customKeys . forEach ( ( key ) => {
52
- if ( typeof actual . custom [ key ] === 'object' && actual . custom [ key ] !== null ) {
53
- if ( Array . isArray ( actual . custom [ key ] ) ) {
54
- if ( ! Array . isArray ( expected . custom [ key ] ) || JSON . stringify ( actual . custom [ key ] ) !== JSON . stringify ( expected . custom [ key ] ) ) {
55
- console . error ( `Mismatch in custom object for key "${ key } ": expected "${ JSON . stringify ( expected . custom [ key ] ) } ", but got "${ JSON . stringify ( actual . custom [ key ] ) } "` ) ;
56
- isValid = false ;
57
- }
58
- }
59
- else {
60
- if ( JSON . stringify ( actual . custom [ key ] ) !== JSON . stringify ( expected . custom [ key ] ) ) {
61
- console . error ( `Mismatch in custom object for key "${ key } ": expected "${ JSON . stringify ( expected . custom [ key ] ) } ", but got "${ JSON . stringify ( actual . custom [ key ] ) } "` ) ;
62
- isValid = false ;
63
- }
64
- }
65
- }
66
- else if ( actual . custom [ key ] !== expected . custom [ key ] ) {
67
- console . error ( `Mismatch in custom object for key "${ key } ": expected "${ expected . custom [ key ] } ", but got "${ actual . custom [ key ] } "` ) ;
68
- isValid = false ;
69
- }
70
- } ) ;
71
- }
72
- return isValid ;
73
- }
74
-
75
26
// Create bulk data
76
27
function createBulkData ( bulk ) {
77
28
// Add an event
@@ -121,7 +72,7 @@ function validateCreatedBulkData(bulk) {
121
72
122
73
var req = reqQueue [ 0 ] ; // read user details queue
123
74
const actualUserDetails = req . user_details ; // Extract the user_details from the actual request
124
- const isValid = validateUserDetails ( actualUserDetails , testUtils . getUserDetailsObj ( ) ) ;
75
+ const isValid = hp . validateUserDetails ( actualUserDetails , testUtils . getUserDetailsObj ( ) ) ;
125
76
assert . equal ( true , isValid ) ;
126
77
127
78
var testUser3Request = reqQueue . find ( ( request ) => request . device_id === "TestUser3" ) ;
@@ -147,8 +98,8 @@ describe("Bulk Tests", () => {
147
98
148
99
it ( "1- CNR" , ( done ) => {
149
100
var bulk = new CountlyBulk ( {
150
- app_key : "YOUR_APP_KEY" ,
151
- url : "https://try.count.ly" ,
101
+ app_key : appKey ,
102
+ url : serverUrl ,
152
103
} ) ;
153
104
assert . equal ( storage . getStoragePath ( ) , undefined ) ;
154
105
shouldFilesExist ( false ) ;
@@ -163,8 +114,8 @@ describe("Bulk Tests", () => {
163
114
164
115
it ( "2- CNR_cPath_file" , ( done ) => {
165
116
var bulk = new CountlyBulk ( {
166
- app_key : "YOUR_APP_KEY" ,
167
- url : "https://try.count.ly" ,
117
+ app_key : appKey ,
118
+ url : serverUrl ,
168
119
storage_path : "../test/customStorageDirectory/" ,
169
120
storage_type : StorageTypes . FILE ,
170
121
} ) ;
@@ -182,8 +133,8 @@ describe("Bulk Tests", () => {
182
133
183
134
it ( "3- CNR_file" , ( done ) => {
184
135
var bulk = new CountlyBulk ( {
185
- app_key : "YOUR_APP_KEY" ,
186
- url : "https://try.count.ly" ,
136
+ app_key : appKey ,
137
+ url : serverUrl ,
187
138
storage_type : StorageTypes . FILE ,
188
139
} ) ;
189
140
assert . equal ( storage . getStoragePath ( ) , "../bulk_data/" ) ;
@@ -197,9 +148,27 @@ describe("Bulk Tests", () => {
197
148
done ( ) ;
198
149
} , hp . mWait ) ;
199
150
} ) ;
151
+
152
+ it ( "4- CNR_memory" , ( done ) => {
153
+ var bulk = new CountlyBulk ( {
154
+ app_key : appKey ,
155
+ url : serverUrl ,
156
+ storage_type : StorageTypes . MEMORY ,
157
+ } ) ;
158
+ assert . equal ( storage . getStoragePath ( ) , undefined ) ;
159
+ shouldFilesExist ( true ) ;
160
+ createBulkData ( bulk ) ;
161
+
162
+ setTimeout ( ( ) => {
163
+ validateCreatedBulkData ( bulk ) ;
164
+ shouldFilesExist ( true ) ;
165
+ assert . equal ( storage . getStoragePath ( ) , undefined ) ;
166
+ done ( ) ;
167
+ } , hp . mWait ) ;
168
+ } ) ;
200
169
} ) ;
201
170
202
171
// Currently tested: CNR, CNR_cPath_file, CNR_file
203
172
// TODO: Add tests for the following:
204
- // - CNR: memory, cPath_memory, persistTrue, persistFalse, cPath_persistTrue, cPath_persistFalse, persistTrue_file, persistFalse_file, cPath_persistTrue_file, cPath_persistFalse_file
173
+ // - CNR: cPath_memory, persistTrue, persistFalse, cPath_persistTrue, cPath_persistFalse, persistTrue_file, persistFalse_file, cPath_persistTrue_file, cPath_persistFalse_file
205
174
// - CR_CG for all of the above
0 commit comments