-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var eventObj = { | ||
key: "event_check", | ||
count: 55, | ||
sum: 3.14, | ||
dur: 2000, | ||
segmentation: { | ||
string_value: "example", | ||
number_value: 42, | ||
boolean_value: true, | ||
array_value: ["item1", "item2"], | ||
object_value: { nested_key: "nested_value" }, | ||
null_value: null, | ||
undefined_value: undefined, | ||
}, | ||
}; | ||
|
||
var timedEventObj = { | ||
key: "timed", | ||
count: 1, | ||
segmentation: { | ||
app_version: "1.0", | ||
country: "Turkey", | ||
}, | ||
}; | ||
|
||
var userDetailObj = { | ||
name: "Alexandrina Jovovich", | ||
username: "alex_jov", | ||
email: "[email protected]", | ||
organization: "TechNova", | ||
phone: "+987654321", | ||
picture: "https://example.com/images/profile_alex.jpg", | ||
gender: "Female", | ||
byear: 1992, // birth year | ||
custom: { | ||
string_value: "example", | ||
number_value: 42, | ||
boolean_value: true, | ||
array_value: ["item1", "item2"], | ||
object_value: { nested_key: "nested_value" }, | ||
null_value: null, | ||
undefined_value: undefined, | ||
}, | ||
}; | ||
|
||
var getUserDetailsObj = function() { | ||
return userDetailObj; | ||
}; | ||
|
||
var getEventObj = function() { | ||
return eventObj; | ||
}; | ||
|
||
var getTimedEventObj = function() { | ||
return timedEventObj; | ||
}; | ||
|
||
module.exports = { | ||
getEventObj, | ||
getUserDetailsObj, | ||
getTimedEventObj, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const assert = require("assert"); | |
const CountlyBulk = require("../lib/countly-bulk"); | ||
var hp = require("./helpers/helper_functions"); | ||
var storage = require("../lib/countly-storage"); | ||
var testUtils = require("./helpers/test_utils"); | ||
|
||
const { StorageTypes } = CountlyBulk; | ||
|
||
|
@@ -71,51 +72,15 @@ function validateUserDetails(actual, expected) { | |
return isValid; | ||
} | ||
|
||
var eventObj = { | ||
key: "bulk_check", | ||
count: 55, | ||
sum: 3.14, | ||
dur: 2000, | ||
segmentation: { | ||
string_value: "example", | ||
number_value: 42, | ||
boolean_value: true, | ||
array_value: ["item1", "item2"], | ||
object_value: { nested_key: "nested_value" }, | ||
null_value: null, | ||
undefined_value: undefined, | ||
}, | ||
}; | ||
|
||
var userDetailObj = { | ||
name: "Alexandrina Jovovich", | ||
username: "alex_jov", | ||
email: "[email protected]", | ||
organization: "TechNova", | ||
phone: "+987654321", | ||
picture: "https://example.com/images/profile_alex.jpg", | ||
gender: "Female", | ||
byear: 1992, // birth year | ||
custom: { | ||
string_value: "example", | ||
number_value: 42, | ||
boolean_value: true, | ||
array_value: ["item1", "item2"], | ||
object_value: { nested_key: "nested_value" }, | ||
null_value: null, | ||
undefined_value: undefined, | ||
}, | ||
}; | ||
|
||
// Create bulk data | ||
function createBulkData(bulk) { | ||
// Add an event | ||
var user = bulk.add_user({ device_id: "testUser1" }); | ||
user.add_event(eventObj); | ||
user.add_event(testUtils.getEventObj()); | ||
|
||
// add user details | ||
var user2 = bulk.add_user({ device_id: "testUser2" }); | ||
user2.user_details(userDetailObj); | ||
user2.user_details(testUtils.getUserDetailsObj()); | ||
|
||
// add request | ||
bulk.add_request({ device_id: "TestUser3" }); | ||
|
@@ -152,11 +117,11 @@ function validateCreatedBulkData(bulk) { | |
|
||
var deviceEvents = events.testUser1; // Access the events for the specific device | ||
var recordedEvent = deviceEvents[0]; // Access the first event | ||
hp.eventValidator(eventObj, recordedEvent); | ||
hp.eventValidator(testUtils.getEventObj(), recordedEvent); | ||
|
||
var req = reqQueue[0]; // read user details queue | ||
const actualUserDetails = req.user_details; // Extract the user_details from the actual request | ||
const isValid = validateUserDetails(actualUserDetails, userDetailObj); | ||
const isValid = validateUserDetails(actualUserDetails, testUtils.getUserDetailsObj()); | ||
assert.equal(true, isValid); | ||
|
||
var testUser3Request = reqQueue.find((request) => request.device_id === "TestUser3"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,36 +7,10 @@ var Countly = require("../lib/countly"); | |
var storage = require("../lib/countly-storage"); | ||
var cc = require("../lib/countly-common"); | ||
var hp = require("./helpers/helper_functions"); | ||
var testUtils = require("./helpers/test_utils"); | ||
|
||
const { StorageTypes } = Countly; | ||
|
||
// example event object to use | ||
var eventObj = { | ||
key: "storage_check", | ||
count: 5, | ||
sum: 3.14, | ||
dur: 2000, | ||
segmentation: { | ||
app_version: "1.0", | ||
country: "Zambia", | ||
}, | ||
}; | ||
|
||
var userDetailObj = { | ||
name: "Akira Kurosawa", | ||
username: "a_kurosawa", | ||
email: "[email protected]", | ||
organization: "Toho Studios", | ||
phone: "+81312345678", | ||
picture: "https://example.com/profile_images/akira_kurosawa.jpg", | ||
gender: "Male", | ||
byear: 1910, | ||
custom: { | ||
"known for": "Film Director", | ||
"notable works": "Seven Samurai, Rashomon, Ran", | ||
}, | ||
}; | ||
|
||
// init function | ||
function initMain(device_id) { | ||
Countly.init({ | ||
|
@@ -196,13 +170,13 @@ describe("Storage Tests", () => { | |
// event should be recorded stored and validated correctly | ||
it("4- Record event and validate storage", (done) => { | ||
initMain(); | ||
Countly.add_event(eventObj); | ||
Countly.add_event(testUtils.getEventObj()); | ||
setTimeout(() => { | ||
var storedEvents = hp.readEventQueue(); | ||
assert.equal(storedEvents.length, 1); | ||
|
||
var event = storedEvents[0]; | ||
hp.eventValidator(eventObj, event); | ||
hp.eventValidator(testUtils.getEventObj(), event); | ||
done(); | ||
}, hp.mWait); | ||
}); | ||
|
@@ -379,12 +353,12 @@ describe("Storage Tests", () => { | |
hp.doesFileStoragePathsExist((exists) => { | ||
assert.equal(false, exists); | ||
}); | ||
Countly.add_event(eventObj); | ||
Countly.add_event(testUtils.getEventObj()); | ||
setTimeout(() => { | ||
const storedData = storage.storeGet("cly_queue", null); | ||
const eventArray = JSON.parse(storedData[0].events); | ||
const eventFromQueue = eventArray[0]; | ||
hp.eventValidator(eventObj, eventFromQueue); | ||
hp.eventValidator(testUtils.getEventObj(), eventFromQueue); | ||
done(); | ||
}, hp.mWait); | ||
}); | ||
|
@@ -402,10 +376,10 @@ describe("Storage Tests", () => { | |
hp.doesFileStoragePathsExist((exists) => { | ||
assert.equal(false, exists); | ||
}); | ||
Countly.user_details(userDetailObj); | ||
Countly.user_details(testUtils.getUserDetailsObj); | ||
const storedData = storage.storeGet("cly_queue", null); | ||
const userDetailsReq = storedData[0]; | ||
hp.userDetailRequestValidator(userDetailObj, userDetailsReq); | ||
hp.userDetailRequestValidator(testUtils.getUserDetailsObj, userDetailsReq); | ||
done(); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,8 @@ | ||
/* eslint-disable no-console */ | ||
var Countly = require("../lib/countly"); | ||
var hp = require("./helpers/helper_functions"); | ||
var testUtils = require("./helpers/test_utils"); | ||
|
||
var userDetailObj = { | ||
name: "Barturiana Sosinsiava", | ||
username: "bar2rawwen", | ||
email: "[email protected]", | ||
organization: "Dukely", | ||
phone: "+123456789", | ||
picture: "https://ps.timg.com/profile_images/52237/011_n_400x400.jpg", | ||
gender: "Non-binary", | ||
byear: 1987, // birth year | ||
custom: { | ||
"key1 segment": "value1 segment", | ||
"key2 segment": "value2 segment", | ||
}, | ||
}; | ||
// init function | ||
function initMain() { | ||
Countly.init({ | ||
|
@@ -34,11 +21,11 @@ describe("User details tests", () => { | |
// initialize SDK | ||
initMain(); | ||
// send user details | ||
Countly.user_details(userDetailObj); | ||
Countly.user_details(testUtils.getUserDetailsObj()); | ||
// read event queue | ||
setTimeout(() => { | ||
var req = hp.readRequestQueue()[0]; | ||
hp.userDetailRequestValidator(userDetailObj, req); | ||
hp.userDetailRequestValidator(testUtils.getUserDetailsObj(), req); | ||
done(); | ||
}, hp.sWait); | ||
}); | ||
|