diff --git a/.eslintignore b/.eslintignore index e935cfaf..7cf3347f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,7 +7,8 @@ node_modules .github .gitignore CHANGELOG.md -cypress.json +cypress.config.js generateDocs.sh jsdoc_conf.json -LICENSE \ No newline at end of file +LICENSE +cypress/ \ No newline at end of file diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 8ef6c0ed..a439ab55 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -13,7 +13,7 @@ jobs: build-and-test: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [14.x, 16.x, 18.x, 20.x] runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 56f4a142..1ac9b9c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## 24.11.0 +- Mitigated an issue where SDK could try to send old stored offline mode data during init if `clear_stored_id` was true +- Mitigated an issue where the SDK could stayed on offline mode after the first init with `offline_mode` set to true +- Mitigated an issue where old Rating widget stickers were not cleared when a new one was presented + +- Improved view tracking logic +- Default request method is now set to "POST" +- Healtchecks won't be sent in offline mode anymore +- Added a new interface 'feedback' which includes convenience methods to show feedback widgets: + - showNPS([String nameIDorTag]) - for displaying the first available NPS widget or one with the given name, Tag or ID value + - showSurvey([String nameIDorTag]) - for displaying the first available Survey widget or one with the given name, Tag or ID value + - showRating([String nameIDorTag]) - for displaying the first available Rating widget or one with the given name, Tag or ID value + ## 24.4.1 - Added types for the SDK - Added a new method `set_id(newDeviceId)` for managing device ID changes according to the device ID Type diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 00000000..6cf93d9c --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,9 @@ +const { defineConfig } = require('cypress') +module.exports = defineConfig({ + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, + userAgent: "abcd", +}); diff --git a/cypress.json b/cypress.json deleted file mode 100644 index f0a56304..00000000 --- a/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "userAgent": "abcd" -} diff --git a/cypress/integration/async_queue.js b/cypress/e2e/async_queue.cy.js similarity index 87% rename from cypress/integration/async_queue.js rename to cypress/e2e/async_queue.cy.js index d1f8ce24..6448ba39 100644 --- a/cypress/integration/async_queue.js +++ b/cypress/e2e/async_queue.cy.js @@ -1,8 +1,6 @@ -/* eslint-disable cypress/no-unnecessary-waiting */ /* eslint-disable require-jsdoc */ var Countly = require("../../lib/countly"); -// import * as Countly from "../../dist/countly_umd.js"; -var hp = require("../support/helper.js"); +var hp = require("../support/helper"); function initMain(clear) { Countly.init({ @@ -62,22 +60,22 @@ describe("Test Countly.q related methods and processes", () => { // Check that the .q is empty expect(Countly.q.length).to.equal(0); - cy.fetch_local_request_queue().then((rq_2) => { + cy.fetch_local_request_queue().then((rq) => { // Check that nothing sent to request queue - expect(rq_2.length).to.equal(0); + expect(rq.length).to.equal(0); cy.fetch_local_event_queue().then((eq) => { // Check that events are now in event queue expect(eq.length).to.equal(4); // Send events from event queue to request queue Countly._internals.sendEventsForced(); - cy.fetch_local_event_queue().then((eq_2) => { + cy.fetch_local_event_queue().then((eq) => { // Check that event queue is empty - expect(eq_2.length).to.equal(0); - cy.fetch_local_request_queue().then((rq_3) => { + expect(eq.length).to.equal(0); + cy.fetch_local_request_queue().then((rq) => { // Check that events are now in request queue - expect(rq_3.length).to.equal(1); - const eventsArray = JSON.parse(rq_3[0].events); + expect(rq.length).to.equal(1); + const eventsArray = JSON.parse(rq[0].events); expect(eventsArray[0].key).to.equal("event_1"); expect(eventsArray[1].key).to.equal("event_2"); expect(eventsArray[2].key).to.equal("event_3"); @@ -125,16 +123,16 @@ describe("Test Countly.q related methods and processes", () => { // Check that event queue has new device ID's orientation event expect(eq.length).to.equal(1); expect(eq[0].key).to.equal("[CLY]_orientation"); - cy.fetch_local_request_queue().then((rq_2) => { + cy.fetch_local_request_queue().then((rq) => { // Check that events are now in request queue (second request is begin session for new device ID) - expect(rq_2.length).to.equal(2); - const eventsArray = JSON.parse(rq_2[0].events); + expect(rq.length).to.equal(2); + const eventsArray = JSON.parse(rq[0].events); expect(eventsArray[0].key).to.equal("event_1"); expect(eventsArray[1].key).to.equal("event_2"); expect(eventsArray[2].key).to.equal("event_3"); expect(eventsArray[3].key).to.equal("event_4"); // check begin session - expect(rq_2[1].begin_session).to.equal(1); + expect(rq[1].begin_session).to.equal(1); }); }); }); @@ -175,16 +173,16 @@ describe("Test Countly.q related methods and processes", () => { cy.fetch_local_event_queue().then((eq) => { // Check that event queue is empty expect(eq.length).to.equal(0); - cy.fetch_local_request_queue().then((rq_2) => { + cy.fetch_local_request_queue().then((rq) => { // Check that events are now in request queue (second request is user details) - expect(rq_2.length).to.equal(2); - const eventsArray = JSON.parse(rq_2[0].events); + expect(rq.length).to.equal(2); + const eventsArray = JSON.parse(rq[0].events); expect(eventsArray[0].key).to.equal("event_1"); expect(eventsArray[1].key).to.equal("event_2"); expect(eventsArray[2].key).to.equal("event_3"); expect(eventsArray[3].key).to.equal("event_4"); // check user details - const user_details = JSON.parse(rq_2[1].user_details); + const user_details = JSON.parse(rq[1].user_details); expect(user_details.name).to.equal("test_user"); }); }); @@ -227,16 +225,16 @@ describe("Test Countly.q related methods and processes", () => { cy.fetch_local_event_queue().then((eq) => { // Check that event queue is empty expect(eq.length).to.equal(0); - cy.fetch_local_request_queue().then((rq_2) => { + cy.fetch_local_request_queue().then((rq) => { // Check that events are now in request queue (second request is user details) - expect(rq_2.length).to.equal(2); - const eventsArray = JSON.parse(rq_2[0].events); + expect(rq.length).to.equal(2); + const eventsArray = JSON.parse(rq[0].events); expect(eventsArray[0].key).to.equal("event_1"); expect(eventsArray[1].key).to.equal("event_2"); expect(eventsArray[2].key).to.equal("event_3"); expect(eventsArray[3].key).to.equal("event_4"); // check user data - const user_details = JSON.parse(rq_2[1].user_details); + const user_details = JSON.parse(rq[1].user_details); expect(user_details.custom.name).to.equal("test_user"); }); }); @@ -267,15 +265,15 @@ describe("Test Countly.q related methods and processes", () => { expect(Countly.q.length).to.equal(4); // Wait for heartBeat to process the .q cy.wait(1500).then(() => { - // Check that the .q is empty + // Check that the .q is empty expect(Countly.q.length).to.equal(0); - cy.fetch_local_event_queue().then((eq_2) => { - // Check that event queue is empty as all must be in request queue - expect(eq_2.length).to.equal(0); - cy.fetch_local_request_queue().then((rq_2) => { - // Check that events are now in request queue - expect(rq_2.length).to.equal(1); - const eventsArray = JSON.parse(rq_2[0].events); + cy.fetch_local_event_queue().then((eq) => { + // Check that event queue is empty as all must be in request queue + expect(eq.length).to.equal(0); + cy.fetch_local_request_queue().then((rq) => { + // Check that events are now in request queue + expect(rq.length).to.equal(1); + const eventsArray = JSON.parse(rq[0].events); expect(eventsArray[0].key).to.equal("event_1"); expect(eventsArray[1].key).to.equal("event_2"); expect(eventsArray[2].key).to.equal("event_3"); diff --git a/cypress/integration/bridge_utils.js b/cypress/e2e/bridged_utils.cy.js similarity index 87% rename from cypress/integration/bridge_utils.js rename to cypress/e2e/bridged_utils.cy.js index dda162b7..df184f57 100644 --- a/cypress/integration/bridge_utils.js +++ b/cypress/e2e/bridged_utils.cy.js @@ -1,7 +1,6 @@ /* eslint-disable cypress/no-unnecessary-waiting */ /* eslint-disable require-jsdoc */ var Countly = require("../../lib/countly"); -// import * as Countly from "../../dist/countly_umd.js"; var hp = require("../support/helper.js"); function initMain(name, version) { @@ -16,13 +15,13 @@ function initMain(name, version) { } const SDK_NAME = "javascript_native_web"; -const SDK_VERSION = "24.4.1"; +const SDK_VERSION = "24.11.0"; // tests describe("Bridged SDK Utilities Tests", () => { it("Check if we can override sdk name and version successful", () => { hp.haltAndClearStorage(() => { - initMain("javascript_gtm_web", "24.0.0"); + initMain('javascript_gtm_web', '24.0.0'); hp.events(); cy.fetch_local_request_queue().then((eq) => { expect(eq).to.have.length(1); @@ -33,7 +32,7 @@ describe("Bridged SDK Utilities Tests", () => { }); it("Check if SDK uses default values if SDK name and version was not overriden", () => { hp.haltAndClearStorage(() => { - initMain(undefined, undefined); + initMain(undefined, undefined); hp.events(); cy.fetch_local_request_queue().then((eq) => { expect(eq).to.have.length(1); diff --git a/cypress/integration/consents.js b/cypress/e2e/consents.cy.js similarity index 96% rename from cypress/integration/consents.js rename to cypress/e2e/consents.cy.js index 4d4473f4..2c747cd2 100644 --- a/cypress/integration/consents.js +++ b/cypress/e2e/consents.cy.js @@ -1,12 +1,13 @@ /* eslint-disable cypress/no-unnecessary-waiting */ /* eslint-disable require-jsdoc */ var Countly = require("../../lib/countly"); -var hp = require("../support/helper"); +// import * as Countly from "../../dist/countly_umd.js"; +var hp = require("../support/helper.js"); function initMain(consent) { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", require_consent: consent, device_id: "György Ligeti", test_mode: true, diff --git a/cypress/integration/crashes.js b/cypress/e2e/crashes.cy.js similarity index 90% rename from cypress/integration/crashes.js rename to cypress/e2e/crashes.cy.js index bc06b0dc..c766d80d 100644 --- a/cypress/integration/crashes.js +++ b/cypress/e2e/crashes.cy.js @@ -5,7 +5,7 @@ var hp = require("../support/helper"); function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true }); } @@ -26,7 +26,7 @@ describe("Crashes tests ", () => { catch (err) { Countly.log_error(err); } - cy.wait(3000).then(() => { + cy.wait(1000).then(() => { cy.fetch_local_request_queue().then((rq) => { cy.check_crash(rq[0], hp.appKey); }); diff --git a/cypress/integration/device_id.js b/cypress/e2e/device_id.cy.js similarity index 99% rename from cypress/integration/device_id.js rename to cypress/e2e/device_id.cy.js index b85c7cdf..82011ca5 100644 --- a/cypress/integration/device_id.js +++ b/cypress/e2e/device_id.cy.js @@ -5,7 +5,7 @@ var hp = require("../support/helper"); function initMain(deviceId, offline, searchQuery, clear, rq, eq) { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", device_id: deviceId, test_mode: rq, test_mode_eq: eq, diff --git a/cypress/integration/device_id_change.js b/cypress/e2e/device_id_change.cy.js similarity index 95% rename from cypress/integration/device_id_change.js rename to cypress/e2e/device_id_change.cy.js index 9cc3a269..dbb3adfa 100644 --- a/cypress/integration/device_id_change.js +++ b/cypress/e2e/device_id_change.cy.js @@ -1,5 +1,5 @@ var Countly = require("../../lib/countly"); -var hp = require("../support/helper"); +var hp = require("../support/helper.js"); // ======================================== // Device ID change tests @@ -14,7 +14,7 @@ var hp = require("../support/helper"); function initMain(offline) { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true, debug: true, offline_mode: offline @@ -220,7 +220,7 @@ describe("Device ID change tests ", ()=>{ }); describe("Set ID change tests ", () => { - it("set_id should be non merge as there was dev provided id", () => { + it('set_id should be non merge as there was dev provided id', () => { hp.haltAndClearStorage(() => { Countly.init({ app_key: "YOUR_APP_KEY", @@ -239,16 +239,16 @@ describe("Set ID change tests ", () => { cy.fetch_local_request_queue().then((eq2) => { expect(eq2.length).to.equal(3); // no merge request expect(eq2[0].device_id).to.equal("old ID"); - expect(eq2[0].events).to.contains("\"key\":\"1\""); + expect(eq2[0].events).to.contains('"key\":\"1\"'); expect(eq2[1].device_id).to.equal("new ID"); expect(eq2[1].begin_session).to.equal(1); expect(eq2[2].device_id).to.equal("new ID"); - expect(eq2[2].events).to.contains("\"key\":\"2\""); + expect(eq2[2].events).to.contains('"key\":\"2\"'); }); }); }); }); - it("set_id should be merge as there was sdk generated id", () => { + it('set_id should be merge as there was sdk generated id', () => { hp.haltAndClearStorage(() => { initMain(false); // init normally Countly.add_event(eventObj("1")); // record an event. @@ -264,13 +264,14 @@ describe("Set ID change tests ", () => { cy.log(eq2); expect(eq2.length).to.equal(3); // merge request expect(eq2[0].device_id).to.equal(generatedID); - expect(eq2[0].events).to.contains("\"key\":\"1\""); + expect(eq2[0].events).to.contains('"key\":\"1\"'); expect(eq2[1].device_id).to.equal("new ID"); expect(eq2[1].old_device_id).to.equal(generatedID); expect(eq2[2].device_id).to.equal("new ID"); - expect(eq2[2].events).to.contains("\"key\":\"2\""); + expect(eq2[2].events).to.contains('"key\":\"2\"'); }); }); }); }); + }); diff --git a/cypress/integration/device_id_init_scenarios.js b/cypress/e2e/device_id_init_scenarios.cy.js similarity index 86% rename from cypress/integration/device_id_init_scenarios.js rename to cypress/e2e/device_id_init_scenarios.cy.js index 92765070..4a75fa7e 100644 --- a/cypress/integration/device_id_init_scenarios.js +++ b/cypress/e2e/device_id_init_scenarios.cy.js @@ -8,21 +8,21 @@ * | device ID | generated | mode was | device ID | device ID | | not | | * | was set | ID | enabled | provided | enabled | | set | set | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | - | - | - | 1 | - | + * | First init | - | - | - | 1 | 65 | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | x | - | - | 2 | - | + * | First init | x | - | - | 2 | 66 | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | - | x | - | 3 | - | + * | First init | - | x | - | 3 | 67 | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | - | - | x | 4 | - | + * | First init | - | - | x | 4 | 68 | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | x | x | - | 5 | - | + * | First init | x | x | - | 5 | 69 | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | x | - | x | 6 | - | + * | First init | x | - | x | 6 | 70 | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | - | x | x | 7 | - | + * | First init | - | x | x | 7 | 71 | * +--------------------------------------------------+------------------------------------+----------------------+ - * | First init | x | x | x | 8 | - | + * | First init | x | x | x | 8 | 72 | * +--------------------------------------------------+------------------------------------+----------------------+ * | x | - | - | - | - | - | 17 | 33 | * +--------------------------------------------------+------------------------------------+----------------------+ @@ -90,7 +90,7 @@ var hp = require("../support/helper"); function initMain(deviceId, offline, searchQuery, clear) { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", device_id: deviceId, test_mode: true, debug: true, @@ -130,11 +130,11 @@ var DeviceIdTypeInternalEnumsTest = { TEMPORARY_ID: 2, URL_PROVIDED: 3 }; -describe("Device Id tests during first init", ()=>{ +describe("Device Id tests during first init", () => { // sdk is initialized w/o custom device id, w/o offline mode, w/o utm device id // we provide no device id information sdk should generate the id - it("1-SDK is initialized without custom device id, without offline mode, without utm device id", ()=>{ + it("1-SDK is initialized without custom device id, without offline mode, without utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); expect(Countly.get_device_id_type()).to.eq(Countly.DeviceIdType.SDK_GENERATED); @@ -147,7 +147,7 @@ describe("Device Id tests during first init", ()=>{ }); }); // we provide device id information sdk should use it - it("2-SDK is initialized with custom device id, without offline mode, without utm device id", ()=>{ + it("2-SDK is initialized with custom device id, without offline mode, without utm device id", () => { hp.haltAndClearStorage(() => { initMain("gerwutztreimer", false, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -160,7 +160,7 @@ describe("Device Id tests during first init", ()=>{ }); }); // we provide no device id information sdk should generate the id - it("3-SDK is initialized without custom device id, with offline mode, without utm device id", ()=>{ + it("3-SDK is initialized without custom device id, with offline mode, without utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, true, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.TEMPORARY_ID); @@ -172,7 +172,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("4-SDK is initialized without custom device id, without offline mode, with utm device id", ()=>{ + it("4-SDK is initialized without custom device id, without offline mode, with utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, "?cly_device_id=abab"); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -184,7 +184,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("5-SDK is initialized with custom device id, with offline mode, without utm device id", ()=>{ + it("5-SDK is initialized with custom device id, with offline mode, without utm device id", () => { hp.haltAndClearStorage(() => { initMain("customID", true, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -196,7 +196,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("6-SDK is initialized with custom device id, without offline mode, with utm device id", ()=>{ + it("6-SDK is initialized with custom device id, without offline mode, with utm device id", () => { hp.haltAndClearStorage(() => { initMain("customID2", false, "?cly_device_id=someID"); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -208,7 +208,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("7-SDK is initialized without custom device id, with offline mode, with utm device id", ()=>{ + it("7-SDK is initialized without custom device id, with offline mode, with utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, true, "?cly_device_id=someID"); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -220,7 +220,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("8-SDK is initialized with custom device id, with offline mode, with utm device id", ()=>{ + it("8-SDK is initialized with custom device id, with offline mode, with utm device id", () => { hp.haltAndClearStorage(() => { initMain("customID3", true, "?cly_device_id=someID2"); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -235,7 +235,7 @@ describe("Device Id tests during first init", ()=>{ // Here tests focus the device id change and offline mode // first pair - it("9-SDK is initialized with no device id, not offline mode, not utm device id", ()=>{ + it("9-SDK is initialized with no device id, not offline mode, not utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.SDK_GENERATED); @@ -251,7 +251,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("10-SDK is initialized with no device id, not offline mode, not utm device id, but then offline", ()=>{ + it("10-SDK is initialized with no device id, not offline mode, not utm device id, but then offline", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.SDK_GENERATED); @@ -269,7 +269,7 @@ describe("Device Id tests during first init", ()=>{ }); }); // second pair - it("11-SDK is initialized with user defined device id, not offline mode, not utm device id", ()=>{ + it("11-SDK is initialized with user defined device id, not offline mode, not utm device id", () => { hp.haltAndClearStorage(() => { initMain("userID", false, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -285,7 +285,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("12-SDK is initialized with user defined device id, not offline mode, not utm device id, but then offline", ()=>{ + it("12-SDK is initialized with user defined device id, not offline mode, not utm device id, but then offline", () => { hp.haltAndClearStorage(() => { initMain("userID", false, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -303,7 +303,7 @@ describe("Device Id tests during first init", ()=>{ }); }); // third pair - it("13-SDK is initialized with no device id, not offline mode, with utm device id", ()=>{ + it("13-SDK is initialized with no device id, not offline mode, with utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, "?cly_device_id=abab"); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -319,7 +319,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("14-SDK is initialized with no device id, not offline mode, with utm device id, but then offline", ()=>{ + it("14-SDK is initialized with no device id, not offline mode, with utm device id, but then offline", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, "?cly_device_id=abab"); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); @@ -337,7 +337,7 @@ describe("Device Id tests during first init", ()=>{ }); }); // fourth pair - it("15-SDK is initialized with no device id, with offline mode, no utm device id", ()=>{ + it("15-SDK is initialized with no device id, with offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, true, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.TEMPORARY_ID); @@ -353,7 +353,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("16-SDK is initialized with no device id, with offline mode, no utm device id, but then offline", ()=>{ + it("16-SDK is initialized with no device id, with offline mode, no utm device id, but then offline", () => { hp.haltAndClearStorage(() => { initMain(undefined, true, undefined); expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.TEMPORARY_ID); @@ -372,7 +372,7 @@ describe("Device Id tests during first init", ()=>{ }); // Auto generated or developer set device ID was present in the local storage before initialization - it("17-Stored ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", ()=>{ + it("17-Stored ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -386,7 +386,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("18-Stored ID precedence, SDK is initialized with device id, not offline mode, no utm device id", ()=>{ + it("18-Stored ID precedence, SDK is initialized with device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -400,7 +400,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("19-Stored ID precedence, SDK is initialized with no device id, offline mode, no utm device id", ()=>{ + it("19-Stored ID precedence, SDK is initialized with no device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -414,7 +414,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("20-Stored ID precedence, SDK is initialized with no device id, no offline mode, utm device id", ()=>{ + it("20-Stored ID precedence, SDK is initialized with no device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -428,7 +428,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("21-Stored ID precedence, SDK is initialized with device id, offline mode, no utm device id", ()=>{ + it("21-Stored ID precedence, SDK is initialized with device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -442,7 +442,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("22-Stored ID precedence, SDK is initialized with device id, no offline mode, utm device id", ()=>{ + it("22-Stored ID precedence, SDK is initialized with device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -456,7 +456,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("23-Stored ID precedence, SDK is initialized no device id, offline mode, utm device id", ()=>{ + it("23-Stored ID precedence, SDK is initialized no device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -470,7 +470,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("24-Stored ID precedence, SDK is initialized with device id, offline mode, utm device id", ()=>{ + it("24-Stored ID precedence, SDK is initialized with device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -486,7 +486,7 @@ describe("Device Id tests during first init", ()=>{ }); // Temporary ID was present in the local storage before initialization - it("25-Stored temp ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", ()=>{ + it("25-Stored temp ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -500,7 +500,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("26-Stored temp ID precedence, SDK is initialized with device id, not offline mode, no utm device id", ()=>{ + it("26-Stored temp ID precedence, SDK is initialized with device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -514,7 +514,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("27-Stored temp ID precedence, SDK is initialized with no device id, offline mode, no utm device id", ()=>{ + it("27-Stored temp ID precedence, SDK is initialized with no device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -528,7 +528,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("28-Stored temp ID precedence, SDK is initialized with no device id, no offline mode, utm device id", ()=>{ + it("28-Stored temp ID precedence, SDK is initialized with no device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -542,7 +542,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("29-Stored temp ID precedence, SDK is initialized with device id, offline mode, no utm device id", ()=>{ + it("29-Stored temp ID precedence, SDK is initialized with device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -556,7 +556,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("30-Stored temp ID precedence, SDK is initialized with device id, no offline mode, utm device id", ()=>{ + it("30-Stored temp ID precedence, SDK is initialized with device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -570,7 +570,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("31-Stored temp ID precedence, SDK is initialized with no device id, offline mode, utm device id", ()=>{ + it("31-Stored temp ID precedence, SDK is initialized with no device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -584,7 +584,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("32-Stored temp ID precedence, SDK is initialized with device id, offline mode, utm device id", ()=>{ + it("32-Stored temp ID precedence, SDK is initialized with device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -601,7 +601,7 @@ describe("Device Id tests during first init", ()=>{ // Same tests with clear device ID flag set to true // Auto generated or developer set device ID was present in the local storage before initialization - it("33-Cleared ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", ()=>{ + it("33-Cleared ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -615,7 +615,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("34-Cleared ID precedence, SDK is initialized with device id, not offline mode, no utm device id", ()=>{ + it("34-Cleared ID precedence, SDK is initialized with device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -629,7 +629,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("35-Cleared ID precedence, SDK is initialized with no device id, offline mode, no utm device id", ()=>{ + it("35-Cleared ID precedence, SDK is initialized with no device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -643,7 +643,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("36-Cleared ID precedence, SDK is initialized with no device id, no offline mode, utm device id", ()=>{ + it("36-Cleared ID precedence, SDK is initialized with no device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -657,7 +657,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("37-Cleared ID precedence, SDK is initialized with device id, offline mode, no utm device id", ()=>{ + it("37-Cleared ID precedence, SDK is initialized with device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -671,7 +671,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("38-Cleared ID precedence, SDK is initialized with device id, no offline mode, utm device id", ()=>{ + it("38-Cleared ID precedence, SDK is initialized with device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -685,7 +685,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("39-Cleared ID precedence, SDK is initialized with no device id, offline mode, utm device id", ()=>{ + it("39-Cleared ID precedence, SDK is initialized with no device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -699,7 +699,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("40-Cleared ID precedence, SDK is initialized with device id, offline mode, utm device id", ()=>{ + it("40-Cleared ID precedence, SDK is initialized with device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("storedID", false, undefined); Countly.halt(); @@ -715,21 +715,21 @@ describe("Device Id tests during first init", ()=>{ }); // Temporary ID was present in the local storage before initialization - it("41-Cleared temp ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", ()=>{ + it("41-Cleared temp ID precedence, SDK is initialized with no device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); initMain(undefined, false, undefined, true); - expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.SDK_GENERATED); - validateSdkGeneratedId(Countly.get_device_id()); - validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.SDK_GENERATED); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.TEMPORARY_ID); + expect(Countly.get_device_id()).to.eq("[CLY]_temp_id"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.TEMPORARY_ID); Countly.begin_session(); cy.fetch_local_request_queue().then((eq) => { - checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.SDK_GENERATED); + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.TEMPORARY_ID); }); }); }); - it("42-Cleared temp ID precedence, SDK is initialized with device id, not offline mode, no utm device id", ()=>{ + it("42-Cleared temp ID precedence, SDK is initialized with device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -743,7 +743,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("43-Cleared temp ID precedence, SDK is initialized with no device id, offline mode, no utm device id", ()=>{ + it("43-Cleared temp ID precedence, SDK is initialized with no device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -757,7 +757,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("44-Cleared temp ID precedence, SDK is initialized with no device id, no offline mode, utm device id", ()=>{ + it("44-Cleared temp ID precedence, SDK is initialized with no device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -771,7 +771,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("45-Cleared temp ID precedence, SDK is initialized with device id, offline mode, no utm device id", ()=>{ + it("45-Cleared temp ID precedence, SDK is initialized with device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -785,7 +785,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("46-Cleared temp ID precedence, SDK is initialized with device id, no offline mode, utm device id", ()=>{ + it("46-Cleared temp ID precedence, SDK is initialized with device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -799,7 +799,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("47-Cleared temp ID precedence, SDK is initialized with no device id, offline mode, utm device id", ()=>{ + it("47-Cleared temp ID precedence, SDK is initialized with no device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -813,7 +813,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("48-Cleared temp ID precedence, SDK is initialized with device id, offline mode, utm device id", ()=>{ + it("48-Cleared temp ID precedence, SDK is initialized with device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain("[CLY]_temp_id", false, undefined); Countly.halt(); @@ -829,7 +829,7 @@ describe("Device Id tests during first init", ()=>{ }); // SDK generated ID was present prior the second init - it("49-Stored UUID precedence, SDK is initialized with no device id, not offline mode, no utm device id", ()=>{ + it("49-Stored UUID precedence, SDK is initialized with no device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -845,7 +845,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("50-Stored UUID precedence, SDK is initialized with device id, not offline mode, no utm device id", ()=>{ + it("50-Stored UUID precedence, SDK is initialized with device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -861,7 +861,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("51-Stored UUID precedence, SDK is initialized with no device id, offline mode, no utm device id", ()=>{ + it("51-Stored UUID precedence, SDK is initialized with no device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -877,7 +877,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("52-Stored UUID precedence, SDK is initialized with no device id, no offline mode, utm device id", ()=>{ + it("52-Stored UUID precedence, SDK is initialized with no device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -893,7 +893,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("53-Stored UUID precedence, SDK is initialized with device id, offline mode, no utm device id", ()=>{ + it("53-Stored UUID precedence, SDK is initialized with device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -909,7 +909,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("54-Stored UUID precedence, SDK is initialized with device id, no offline mode, utm device id", ()=>{ + it("54-Stored UUID precedence, SDK is initialized with device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -925,7 +925,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("55-Stored UUID precedence, SDK is initialized no device id, offline mode, utm device id", ()=>{ + it("55-Stored UUID precedence, SDK is initialized no device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -941,7 +941,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("56-Stored UUID precedence, SDK is initialized with device id, offline mode, utm device id", ()=>{ + it("56-Stored UUID precedence, SDK is initialized with device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -959,7 +959,7 @@ describe("Device Id tests during first init", ()=>{ }); // SDK generated ID was present prior the second init (same tests with flag set to true) - it("57-Stored UUID precedence, SDK is initialized with no device id, not offline mode, no utm device id", ()=>{ + it("57-Stored UUID precedence, SDK is initialized with no device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -975,7 +975,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("58-Stored UUID precedence, SDK is initialized with device id, not offline mode, no utm device id", ()=>{ + it("58-Stored UUID precedence, SDK is initialized with device id, not offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -990,7 +990,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("59-Stored UUID precedence, SDK is initialized with no device id, offline mode, no utm device id", ()=>{ + it("59-Stored UUID precedence, SDK is initialized with no device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -1005,7 +1005,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("60-Stored UUID precedence, SDK is initialized with no device id, no offline mode, utm device id", ()=>{ + it("60-Stored UUID precedence, SDK is initialized with no device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -1020,7 +1020,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("61-Stored UUID precedence, SDK is initialized with device id, offline mode, no utm device id", ()=>{ + it("61-Stored UUID precedence, SDK is initialized with device id, offline mode, no utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -1035,7 +1035,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("62-Stored UUID precedence, SDK is initialized with device id, no offline mode, utm device id", ()=>{ + it("62-Stored UUID precedence, SDK is initialized with device id, no offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -1050,7 +1050,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("63-Stored UUID precedence, SDK is initialized no device id, offline mode, utm device id", ()=>{ + it("63-Stored UUID precedence, SDK is initialized no device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -1065,7 +1065,7 @@ describe("Device Id tests during first init", ()=>{ }); }); }); - it("64-Stored UUID precedence, SDK is initialized with device id, offline mode, utm device id", ()=>{ + it("64-Stored UUID precedence, SDK is initialized with device id, offline mode, utm device id", () => { hp.haltAndClearStorage(() => { initMain(undefined, false, undefined); var oldUUID = Countly.get_device_id(); @@ -1080,4 +1080,104 @@ describe("Device Id tests during first init", ()=>{ }); }); }); + + // testing first 8 tests with clear_stored_id flag set to true + it("65-SDK is initialized without custom device id, without offline mode, without utm device id", () => { + hp.haltAndClearStorage(() => { + initMain(undefined, false, undefined, true); + expect(Countly.get_device_id_type()).to.eq(Countly.DeviceIdType.SDK_GENERATED); + validateSdkGeneratedId(Countly.get_device_id()); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.SDK_GENERATED); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.SDK_GENERATED); + }); + }); + }); + // we provide device id information sdk should use it + it("66-SDK is initialized with custom device id, without offline mode, without utm device id", () => { + hp.haltAndClearStorage(() => { + initMain("gerwutztreimer", false, undefined, true); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); + expect(Countly.get_device_id()).to.eq("gerwutztreimer"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.DEVELOPER_SUPPLIED); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.DEVELOPER_SUPPLIED); + }); + }); + }); + // we provide no device id information sdk should generate the id + it("67-SDK is initialized without custom device id, with offline mode, without utm device id", () => { + hp.haltAndClearStorage(() => { + initMain(undefined, true, undefined, true); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.TEMPORARY_ID); + expect(Countly.get_device_id()).to.eq("[CLY]_temp_id"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.TEMPORARY_ID); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.TEMPORARY_ID); + }); + }); + }); + it("68-SDK is initialized without custom device id, without offline mode, with utm device id", () => { + hp.haltAndClearStorage(() => { + initMain(undefined, false, "?cly_device_id=abab", true); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); + expect(Countly.get_device_id()).to.eq("abab"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + }); + }); + }); + it("69-SDK is initialized with custom device id, with offline mode, without utm device id", () => { + hp.haltAndClearStorage(() => { + initMain("customID", true, undefined, true); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); + expect(Countly.get_device_id()).to.eq("customID"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.DEVELOPER_SUPPLIED); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.DEVELOPER_SUPPLIED); + }); + }); + }); + it("70-SDK is initialized with custom device id, without offline mode, with utm device id", () => { + hp.haltAndClearStorage(() => { + initMain("customID2", false, "?cly_device_id=someID", true); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); + expect(Countly.get_device_id()).to.eq("someID"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + }); + }); + }); + it("71-SDK is initialized without custom device id, with offline mode, with utm device id", () => { + hp.haltAndClearStorage(() => { + initMain(undefined, true, "?cly_device_id=someID", true); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); + expect(Countly.get_device_id()).to.eq("someID"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + }); + }); + }); + it("72-SDK is initialized with custom device id, with offline mode, with utm device id", () => { + hp.haltAndClearStorage(() => { + initMain("customID3", true, "?cly_device_id=someID2", true); + expect(Countly.get_device_id_type()).to.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED); + expect(Countly.get_device_id()).to.eq("someID2"); + validateInternalDeviceIdType(DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + Countly.begin_session(); + cy.fetch_local_request_queue().then((eq) => { + checkRequestsForT(eq, DeviceIdTypeInternalEnumsTest.URL_PROVIDED); + }); + }); + }); }); diff --git a/cypress/integration/events.js b/cypress/e2e/events.cy.js similarity index 99% rename from cypress/integration/events.js rename to cypress/e2e/events.cy.js index d63210c4..b0dd9380 100644 --- a/cypress/integration/events.js +++ b/cypress/e2e/events.cy.js @@ -6,7 +6,7 @@ var hp = require("../support/helper"); function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", session_update: 3, test_mode: true, test_mode_eq: true, diff --git a/cypress/e2e/health_check.cy.js b/cypress/e2e/health_check.cy.js new file mode 100644 index 00000000..69d41ca3 --- /dev/null +++ b/cypress/e2e/health_check.cy.js @@ -0,0 +1,51 @@ +/* eslint-disable require-jsdoc */ +var Countly = require("../../lib/countly"); +var hp = require("../support/helper"); + +function initMain() { + Countly.init({ + app_key: "YOUR_APP_KEY", + url: "https://your.domain.count.ly", + test_mode: true + }); +} + +describe("Health Check tests", () => { + it("Check if health check is sent at the beginning", () => { + hp.haltAndClearStorage(() => { + initMain(); + cy.intercept("POST", "https://your.domain.count.ly/i").as("postXhr"); + cy.wait("@postXhr").then((xhr) => { + const body = xhr.request.body; + const params = new URLSearchParams(body); + + const hcParam = params.get("hc"); + const hcParamObj = JSON.parse(decodeURIComponent(hcParam)); + expect(hcParamObj).to.eql({ el: 0, wl: 0, sc: -1, em: "" }); + + const metricsParam = params.get("metrics"); + expect(metricsParam).to.equal("{\"_app_version\":\"0.0\",\"_ua\":\"abcd\"}"); + + cy.fetch_local_request_queue().then((rq) => { + expect(rq.length).to.equal(0); + }); + }); + }); + }); + it("Check no health check is sent in offline mode", () => { + hp.haltAndClearStorage(() => { + Countly.init({ + app_key: "YOUR_APP_KEY", + url: "https://your.domain.count.ly", + test_mode: true, + offline_mode: true + }); + + cy.intercept("POST", "https://your.domain.count.ly/i").as("postXhr"); + cy.get('@postXhr').should('not.exist'); + cy.fetch_local_request_queue().then((rq) => { + expect(rq.length).to.equal(0); + }); + }); + }); +}); diff --git a/cypress/integration/heatmaps.js b/cypress/e2e/heatmaps.cy.js similarity index 97% rename from cypress/integration/heatmaps.js rename to cypress/e2e/heatmaps.cy.js index 2bfb38e0..ca5d4694 100644 --- a/cypress/integration/heatmaps.js +++ b/cypress/e2e/heatmaps.cy.js @@ -11,8 +11,10 @@ function click_check(segmentation, offX, offY) { expect(segmentation.height).to.be.ok; expect(segmentation.view).to.be.ok; expect(segmentation.width).to.be.ok; - expect(segmentation.x).to.equal(clickX + offX); - expect(segmentation.y).to.equal(clickY + offY); + expect(segmentation.x).to.be.above(clickX + offX - 2); + expect(segmentation.x).to.be.below(clickX + offX + 2); + expect(segmentation.y).to.be.above(clickY + offY - 2); + expect(segmentation.y).to.be.below(clickY + offY + 2); } describe("Browser heatmap tests, scrolls", () => { diff --git a/cypress/integration/integration.js b/cypress/e2e/integration.cy.js similarity index 93% rename from cypress/integration/integration.js rename to cypress/e2e/integration.cy.js index 6ad6664e..2273d158 100644 --- a/cypress/integration/integration.js +++ b/cypress/e2e/integration.cy.js @@ -7,7 +7,7 @@ var hp = require("../support/helper"); function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", debug: true, test_mode: true }); @@ -50,7 +50,7 @@ describe("Integration test", () => { // TODO: make better cy.fetch_local_request_queue().then((rq) => { cy.log(rq); - hp.testNormalFlow(rq, "/__cypress/iframes/integration%2Fintegration.js", hp.appKey); + hp.testNormalFlow(rq, "/__cypress/iframes/cypress%5Ce2e%5Cintegration.cy.js", hp.appKey); expect(consentStatus).to.equal(true); // no consent necessary expect(remote).to.eql({}); // deepEqual expect(rq[0].device_id).to.equal(id); diff --git a/cypress/integration/internal_limits.js b/cypress/e2e/internal_limits.cy.js similarity index 99% rename from cypress/integration/internal_limits.js rename to cypress/e2e/internal_limits.cy.js index d1f94eb9..39a6528b 100644 --- a/cypress/integration/internal_limits.js +++ b/cypress/e2e/internal_limits.cy.js @@ -15,7 +15,7 @@ const limits = { function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode_eq: true, test_mode: true, debug: true, diff --git a/cypress/integration/manual_widget_reporting.js b/cypress/e2e/manual_widget_reporting.cy.js similarity index 99% rename from cypress/integration/manual_widget_reporting.js rename to cypress/e2e/manual_widget_reporting.cy.js index a120f924..24008310 100644 --- a/cypress/integration/manual_widget_reporting.js +++ b/cypress/e2e/manual_widget_reporting.cy.js @@ -58,7 +58,7 @@ function common_rating_check(param, num) { function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode_eq: true, test_mode: true, debug: true diff --git a/cypress/integration/multi_instance.js b/cypress/e2e/multi_instance.cy.js similarity index 100% rename from cypress/integration/multi_instance.js rename to cypress/e2e/multi_instance.cy.js diff --git a/cypress/integration/remaining_requests.js b/cypress/e2e/remaining_requests.cy.js similarity index 86% rename from cypress/integration/remaining_requests.js rename to cypress/e2e/remaining_requests.cy.js index f9265dec..abf33dad 100644 --- a/cypress/integration/remaining_requests.js +++ b/cypress/e2e/remaining_requests.cy.js @@ -5,7 +5,7 @@ var hp = require("../support/helper"); function initMain(shouldStopRequests) { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", app_version: "1.0", // would prevent requests from being sent to the server if true test_mode: shouldStopRequests @@ -18,7 +18,7 @@ describe("Remaining requests tests ", () => { initMain(false); // We will expect 4 requests: health check, begin_session, end_session, orientation - hp.interceptAndCheckRequests(undefined, undefined, undefined, "?hc=*", "hc", (requestParams) => { + hp.interceptAndCheckRequests("POST", undefined, undefined, "?hc=*", "hc", (requestParams) => { const params = JSON.parse(requestParams.get("hc")); assert.isTrue(typeof params.el === "number"); assert.isTrue(typeof params.wl === "number"); @@ -29,19 +29,19 @@ describe("Remaining requests tests ", () => { cy.wait(1000).then(() => { // Create a session Countly.begin_session(); - hp.interceptAndCheckRequests(undefined, undefined, undefined, "?begin_session=*", "begin_session", (requestParams) => { + hp.interceptAndCheckRequests("POST", undefined, undefined, "?begin_session=*", "begin_session", (requestParams) => { expect(requestParams.get("begin_session")).to.equal("1"); expect(requestParams.get("rr")).to.equal("3"); expect(requestParams.get("av")).to.equal(av); }); // End the session Countly.end_session(undefined, true); - hp.interceptAndCheckRequests(undefined, undefined, undefined, undefined, "end_session", (requestParams) => { + hp.interceptAndCheckRequests("POST", undefined, undefined, "?end_session=*", "end", (requestParams) => { expect(requestParams.get("end_session")).to.equal("1"); expect(requestParams.get("rr")).to.equal("2"); expect(requestParams.get("av")).to.equal(av); }); - hp.interceptAndCheckRequests(undefined, undefined, undefined, undefined, "orientation", (requestParams) => { + hp.interceptAndCheckRequests("POST", undefined, undefined, undefined, "orientation", (requestParams) => { expect(JSON.parse(requestParams.get("events"))[0].key).to.equal("[CLY]_orientation"); expect(requestParams.get("rr")).to.equal("1"); expect(requestParams.get("av")).to.equal(av); diff --git a/cypress/integration/reponse_validation.js b/cypress/e2e/reponse_validation.cy.js similarity index 99% rename from cypress/integration/reponse_validation.js rename to cypress/e2e/reponse_validation.cy.js index 01d58c71..a230ba8b 100644 --- a/cypress/integration/reponse_validation.js +++ b/cypress/e2e/reponse_validation.cy.js @@ -10,7 +10,7 @@ var hp = require("../support/helper"); function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true, test_mode_eq: true, debug: true diff --git a/cypress/integration/salt.js b/cypress/e2e/salt.cy.js similarity index 93% rename from cypress/integration/salt.js rename to cypress/e2e/salt.cy.js index 4a7b1356..4479e481 100644 --- a/cypress/integration/salt.js +++ b/cypress/e2e/salt.cy.js @@ -1,9 +1,8 @@ /* eslint-disable cypress/no-unnecessary-waiting */ /* eslint-disable require-jsdoc */ var Countly = require("../../lib/countly"); -// import * as Countly from "../../dist/countly_umd.js"; var hp = require("../support/helper.js"); -const crypto = require("crypto"); +const crypto = require('crypto'); function initMain(salt) { Countly.init({ @@ -49,7 +48,7 @@ describe("Salt Tests", () => { hp.haltAndClearStorage(() => { initMain(salt); var rqArray = []; - hp.events(); + hp.events(); cy.intercept("GET", "**/i?**", (req) => { const { url } = req; rqArray.push(url.split("?")[1]); @@ -81,7 +80,7 @@ describe("Salt Tests", () => { * @returns {string} - sha256 hash */ function sha256(data) { - const hash = crypto.createHash("sha256"); + const hash = crypto.createHash('sha256'); hash.update(data); - return hash.digest("hex"); + return hash.digest('hex'); } \ No newline at end of file diff --git a/cypress/integration/sessions.js b/cypress/e2e/sessions.cy.js similarity index 59% rename from cypress/integration/sessions.js rename to cypress/e2e/sessions.cy.js index 0d03a4ab..5904e4b6 100644 --- a/cypress/integration/sessions.js +++ b/cypress/e2e/sessions.cy.js @@ -3,7 +3,7 @@ var Countly = require("../../lib/countly"); var hp = require("../support/helper"); // if you are testing on an app const app_key = hp.appKey; -const waitTime = 4000; +const waitTime = 7000; const eventObj = { key: "buttonClick", count: 1, @@ -15,7 +15,7 @@ const eventObj = { function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", session_update: 3, test_mode: true }); @@ -30,7 +30,7 @@ const dummyQueue = [ describe("Session tests ", () => { it("Checks if session start, extension and ending works with a dummy queue", () => { hp.haltAndClearStorage(() => { - // initialize countly + // initialize countly initMain(); // begin session Countly.begin_session(); @@ -50,7 +50,7 @@ describe("Session tests ", () => { }); it("Checks if session start, extension and ending works", () => { hp.haltAndClearStorage(() => { - // initialize countly + // initialize countly initMain(); // begin session Countly.begin_session(); @@ -73,15 +73,24 @@ describe("Session tests ", () => { }); }); }); - describe("Browser session tests, auto", () => { it("Single session test with auto sessions", () => { cy.visit("./cypress/fixtures/session_test_auto.html?use_session_cookie=true") .wait(waitTime); - cy.contains("Event").click().wait(1000); + cy.contains("Event").click().wait(300); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { - checkQueueForSessionTests(rq, 5, 4); + cy.log(rq); + // 3 session and 1 orientation 1 event + expect(rq.length).to.equal(5); + // first object of the queue should be about begin session, second is orientation + cy.check_session(rq[0], undefined, undefined, app_key); + // third object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[2], 5, undefined, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); + // fifth object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[4], 1, undefined, app_key); }); }); }); @@ -89,21 +98,41 @@ describe("Browser session tests, manual 1", () => { it("Single sessions test with manual sessions", () => { cy.visit("./cypress/fixtures/session_test_manual_1.html?use_session_cookie=true"); cy.contains("Start").click().wait(waitTime); - cy.contains("Event").click().wait(500); - cy.contains("End").click().wait(500); + cy.contains("Event").click().wait(300); + cy.contains("End").click().wait(300); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { - checkQueueForSessionTests(rq, 4, 4); + cy.log(rq); + // 3 session and 1 orientation 1 event + expect(rq.length).to.equal(5); + // first object of the queue should be about begin session, second is orientation + cy.check_session(rq[0], undefined, undefined, app_key); + // third object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[2], 5, undefined, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); + // fifth object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[4], 1, undefined, app_key); }); }); }); describe("Browser session tests, manual 2", () => { it("Single bounce test with manual sessions 2", () => { cy.visit("./cypress/fixtures/session_test_manual_2.html?use_session_cookie=true").wait(waitTime); - cy.contains("Event").click().wait(500); + cy.contains("Event").click().wait(300); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { - checkQueueForSessionTests(rq, 4, 4); + cy.log(rq); + // 3 session and 1 orientation 1 event + expect(rq.length).to.equal(5); + // first object of the queue should be about begin session, second is orientation + cy.check_session(rq[0], undefined, undefined, app_key); + // third object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[2], 5, undefined, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); + // fifth object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[4], 1, undefined, app_key); }); }); }); @@ -111,10 +140,20 @@ describe("Browser session tests, auto, no cookie", () => { it("Single bounce test with auto sessions and no cookies", () => { cy.visit("./cypress/fixtures/session_test_auto.html") .wait(waitTime); - cy.contains("Event").click().wait(500); + cy.contains("Event").click().wait(300); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { - checkQueueForSessionTests(rq, 5, 4); + cy.log(rq); + // 3 session and 1 orientation 1 event + expect(rq.length).to.equal(5); + // first object of the queue should be about begin session, second is orientation + cy.check_session(rq[0], undefined, undefined, app_key); + // third object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[2], 5, undefined, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); + // fifth object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[4], 1, true, app_key); }); }); }); @@ -124,12 +163,22 @@ describe("Browser session tests, manual 1, no cookie", () => { cy.contains("Start").click(); cy.wait(waitTime); cy.contains("Event").click(); - cy.wait(500); + cy.wait(300); cy.contains("End").click(); - cy.wait(500); + cy.wait(300); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { - checkQueueForSessionTests(rq, 5, 4); + cy.log(rq); + // 3 session and 1 orientation 1 event + expect(rq.length).to.equal(5); + // first object of the queue should be about begin session, second is orientation + cy.check_session(rq[0], undefined, undefined, app_key); + // third object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[2], 5, undefined, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); + // fifth object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[4], 1, true, app_key); }); }); }); @@ -139,15 +188,24 @@ describe("Browser session tests, manual 2, no cookie", () => { cy.contains("Event").click().wait(500); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { - checkQueueForSessionTests(rq, 5, 4); + cy.log(rq); + // 3 session and 1 orientation 1 event + expect(rq.length).to.equal(5); + // first object of the queue should be about begin session, second is orientation + cy.check_session(rq[0], undefined, undefined, app_key); + // third object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[2], 5, undefined, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); + // fifth object of the queue should be about session extension, also input the expected duration + cy.check_session(rq[4], 1, true, app_key); }); }); }); - describe("Check request related functions", () => { it("Check if prepareRequest forms a proper request object", () => { hp.haltAndClearStorage(() => { - // initialize countly + // initialize countly initMain(); let reqObject = {}; Countly._internals.prepareRequest(reqObject); @@ -157,7 +215,7 @@ describe("Check request related functions", () => { }); it("Check if prepareRequest forms a proper request object from a bad one ", () => { hp.haltAndClearStorage(() => { - // initialize countly + // initialize countly initMain(); let reqObject = { app_key: null, device_id: null }; Countly._internals.prepareRequest(reqObject); @@ -167,7 +225,7 @@ describe("Check request related functions", () => { }); it("Check if prepareRequest forms a proper request object and not erase an extra value ", () => { hp.haltAndClearStorage(() => { - // initialize countly + // initialize countly initMain(); let reqObject = { extraKey: "value" }; Countly._internals.prepareRequest(reqObject); @@ -176,35 +234,4 @@ describe("Check request related functions", () => { cy.check_request_commons(reqObject); }); }); -}); - -/** - * checks the queue for session tests - * @param {*} queue - queue to check - * @param {*} expectedLength - expected length of the queue - * @param {*} sessionDuration - expected session duration - */ -function checkQueueForSessionTests(queue, expectedLength, sessionDuration) { - expect(queue.length).to.be.within(expectedLength - 1, expectedLength + 1); - let beginSes = 1; - for (let i = 0; i < queue.length; i++) { - const currentRequest = queue[i]; - if (currentRequest.begin_session) { - cy.check_session(currentRequest, undefined, undefined, app_key); - beginSes--; - } - else if (currentRequest.events) { - const event = JSON.parse(currentRequest.events)[0]; - if (event.key === "buttonClick") { - cy.check_event(event, eventObj, undefined, false); - } - } - else if (currentRequest.session_duration) { - cy.check_session(currentRequest, sessionDuration, undefined, app_key); - } - else if (currentRequest.end_session) { - cy.check_session(currentRequest, 0, true, app_key); - } - } - expect(beginSes).to.equal(0); -} \ No newline at end of file +}); \ No newline at end of file diff --git a/cypress/integration/storage.js b/cypress/e2e/storage.cy.js similarity index 95% rename from cypress/integration/storage.js rename to cypress/e2e/storage.cy.js index b9cfc8e1..40b0b58b 100644 --- a/cypress/integration/storage.js +++ b/cypress/e2e/storage.cy.js @@ -5,7 +5,7 @@ var hp = require("../support/helper"); function initMain(val) { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode_eq: true, test_mode: true, debug: true, @@ -37,7 +37,7 @@ for (let i = 0; i < 5; i++) { } else if (isNone) { expect(value).to.equal(null); - expect(document.cookie).to.equal(""); + expect(document.cookie).to.equal("__cypress.initial=true"); // since cypress 13.6 } else { expect(value).to.equal(valueToStore); @@ -49,7 +49,7 @@ for (let i = 0; i < 5; i++) { hp.haltAndClearStorage(() => { initMain(flag); if (isNone) { - expect(document.cookie).to.equal(""); + expect(document.cookie).to.equal("__cypress.initial=true"); // since cypress 13.6 } Countly._internals.setValueInStorage(key, valueToStore); expect(isNone ? undefined : valueToStore).to.equal(Countly._internals.getValueFromStorage(key)); @@ -65,7 +65,7 @@ for (let i = 0; i < 5; i++) { hp.haltAndClearStorage(() => { initMain(flag); if (isNone) { - expect(document.cookie).to.equal(""); + expect(document.cookie).to.equal("__cypress.initial=true"); // since cypress 13.6 } Countly._internals.setValueInStorage(key, valueToStore); expect(isNone ? undefined : valueToStore).to.equal(Countly._internals.getValueFromStorage(key)); @@ -85,7 +85,7 @@ for (let i = 0; i < 5; i++) { expect(value).to.equal(null); }); if (isNone || isLocal) { - expect(document.cookie).to.equal(""); + expect(document.cookie).to.equal("__cypress.initial=true"); // since cypress 13.6 } else { expect(document.cookie).to.include(`${hp.appKey}/${key}=${valueToStore}`); diff --git a/cypress/integration/storage_change.js b/cypress/e2e/storage_change.cy.js similarity index 97% rename from cypress/integration/storage_change.js rename to cypress/e2e/storage_change.cy.js index 101e6360..330293db 100644 --- a/cypress/integration/storage_change.js +++ b/cypress/e2e/storage_change.cy.js @@ -6,7 +6,7 @@ import { triggerStorageChange } from "../support/integration_helper"; function initMain(val) { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", device_id: 0, // provide number test_mode_eq: true, test_mode: true, @@ -78,7 +78,7 @@ describe("Multi tab storage change test", () => { hp.haltAndClearStorage(() => { let firstIns = Countly.init({ app_key: "YOUR_APP_KEY1", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", device_id: 0, test_mode_eq: true, test_mode: true, @@ -87,7 +87,7 @@ describe("Multi tab storage change test", () => { }); let secondIns = Countly.init({ app_key: "YOUR_APP_KEY2", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", device_id: -1, test_mode_eq: true, test_mode: true, diff --git a/cypress/integration/user_agent.js b/cypress/e2e/user_agent.cy.js similarity index 90% rename from cypress/integration/user_agent.js rename to cypress/e2e/user_agent.cy.js index 9ad95de8..54143c96 100644 --- a/cypress/integration/user_agent.js +++ b/cypress/e2e/user_agent.cy.js @@ -6,7 +6,7 @@ var hp = require("../support/helper"); function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode_eq: true }); } @@ -64,4 +64,10 @@ describe("User Agent tests ", () => { expect(Countly._internals.userAgentSearchBotDetection("Lighthouse")).to.equal(true); }); }); + // userAgentData is not supported by all browsers yet so it is hard to test with consistency + it("Check if currentUserAgentDataString override works", () => { + hp.haltAndClearStorage(() => { + expect(Countly._internals.currentUserAgentDataString('123')).to.equal("123"); + }); + }); }); diff --git a/cypress/integration/user_details.js b/cypress/e2e/user_details.cy.js similarity index 99% rename from cypress/integration/user_details.js rename to cypress/e2e/user_details.cy.js index 925ee8aa..d9446bcd 100644 --- a/cypress/integration/user_details.js +++ b/cypress/e2e/user_details.cy.js @@ -6,7 +6,7 @@ var hp = require("../support/helper"); function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode_eq: true, test_mode: true }); diff --git a/cypress/integration/utm.js b/cypress/e2e/utm.cy.js similarity index 89% rename from cypress/integration/utm.js rename to cypress/e2e/utm.cy.js index 34e9102f..a9c7621b 100644 --- a/cypress/integration/utm.js +++ b/cypress/e2e/utm.cy.js @@ -5,7 +5,7 @@ var hp = require("../support/helper"); function initMulti(appKey, searchQuery, utmStuff) { Countly.init({ app_key: appKey, - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true, test_mode_eq: true, utm: utmStuff, @@ -19,7 +19,7 @@ describe("UTM tests ", () => { it("Checks if a single default utm tag works", () => { hp.haltAndClearStorage(() => { initMulti("YOUR_APP_KEY", "?utm_source=hehe", undefined); - Countly.q.push(["track_errors"]); // adding this as calling it during init used to cause an error (at v23.12.5) + Countly.q.push(['track_errors']); // adding this as calling it during init used to cause an error (at v23.12.5) cy.fetch_local_request_queue().then((rq) => { cy.log(rq); const custom = JSON.parse(rq[0].user_details).custom; @@ -29,7 +29,7 @@ describe("UTM tests ", () => { }); it("Checks if default utm tags works", () => { hp.haltAndClearStorage(() => { - initMulti("YOUR_APP_KEY", "?utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4", undefined); + initMulti("YOUR_APP_KEY", "utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4", undefined); cy.fetch_local_request_queue().then((rq) => { cy.log(rq); const custom = JSON.parse(rq[0].user_details).custom; @@ -39,7 +39,7 @@ describe("UTM tests ", () => { }); it("Checks if a single custom utm tag works", () => { hp.haltAndClearStorage(() => { - initMulti("YOUR_APP_KEY", "utm_aa=hehe", { aa: true, bb: true }); + initMulti("YOUR_APP_KEY", "?utm_aa=hehe", { aa: true, bb: true }); cy.fetch_local_request_queue().then((rq) => { cy.log(rq); const custom = JSON.parse(rq[0].user_details).custom; @@ -70,13 +70,13 @@ describe("UTM tests ", () => { initMulti("Countly_4", "?utm_source=hehe4", { ss: true }); // utm object not provided with default query - initMulti("Countly_3", "?utm_source=hehe3", undefined); + initMulti("Countly_3", "utm_source=hehe3", undefined); // utm object not provided with inappropriate query - initMulti("Countly_5", "utm_ss=hehe5", undefined); + initMulti("Countly_5", "?utm_ss=hehe5", undefined); // default (original) init with no custom tags and default query - initMulti("YOUR_APP_KEY", "?utm_source=hehe", undefined); + initMulti("YOUR_APP_KEY", "utm_source=hehe", undefined); // check original cy.fetch_local_request_queue().then((rq) => { @@ -111,7 +111,7 @@ describe("UTM tests ", () => { initMulti("YOUR_APP_KEY", "?utm_source=hehe", undefined); // utm object not provided with full + weird query - initMulti("Countly_multi_1", "?utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", undefined); + initMulti("Countly_multi_1", "utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", undefined); // utm object given that includes 2 default 1 custom, full plus custom query + gabledeboop initMulti("Countly_multi_2", "?utm_source=hehe&utm_medium=hehe1&utm_campaign=hehe2&utm_term=hehe3&utm_content=hehe4&utm_sthelse=hehe5&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", { source: true, term: true, sthelse: true }); @@ -172,7 +172,7 @@ describe("UTM tests ", () => { initMulti("Countly_multi_next_1", "?utm_sourcer=hehe&utm_mediumr=hehe1&utm_campaignr=hehe2&utm_rterm=hehe3&utm_corntent=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", undefined); // utm object default, custom query + gabledeboop - initMulti("Countly_multi_next_2", "?utm_sourcer=hehe&utm_mediumr=hehe1&utm_campaignr=hehe2&utm_rterm=hehe3&utm_corntent=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", { source: true, medium: true, campaign: true, term: true, content: true }); + initMulti("Countly_multi_next_2", "utm_sourcer=hehe&utm_mediumr=hehe1&utm_campaignr=hehe2&utm_rterm=hehe3&utm_corntent=hehe4&fdsjhflkjhsdlkfjhsdlkjfhksdjhfkj+dsf;jsdlkjflk+=skdjflksjd=fksdfl;sd=sdkfmk&&&", { source: true, medium: true, campaign: true, term: true, content: true }); // custom utm object, custom query + gabledeboop initMulti("Countly_multi_next_3", "?utm_sauce=hehe&utm_pan=hehe2&dasdashdjkhaslkjdhsakj=dasmndlask=asdkljska&&utm_source=hehe", { sauce: true, pan: true }); diff --git a/cypress/integration/view_utm_referrer.js b/cypress/e2e/view_utm_referrer.cy.js similarity index 97% rename from cypress/integration/view_utm_referrer.js rename to cypress/e2e/view_utm_referrer.cy.js index effdcca8..4b7e0840 100644 --- a/cypress/integration/view_utm_referrer.js +++ b/cypress/e2e/view_utm_referrer.cy.js @@ -5,7 +5,7 @@ var hp = require("../support/helper"); function init(appKey, searchQuery, utmStuff) { Countly.init({ app_key: appKey, - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true, test_mode_eq: true, utm: utmStuff, // utm object provided in init @@ -113,7 +113,7 @@ describe("View with utm and referrer tests ", () => { // we check if multiple custom utm tags are recorded in the view event if they are in the utm object it("Checks if multiple custom utm tags appears in view", () => { hp.haltAndClearStorage(() => { - init("YOUR_APP_KEY", "?utm_aa=hehe&utm_bb=hoho", { aa: true, bb: true }); + init("YOUR_APP_KEY", "utm_aa=hehe&utm_bb=hoho", { aa: true, bb: true }); Countly.track_view(pageNameOne); cy.fetch_local_event_queue().then((eq) => { cy.check_view_event(eq[0], pageNameOne, undefined, false); @@ -166,7 +166,7 @@ describe("View with utm and referrer tests ", () => { // default (original) init with no custom tags and default query var C1 = Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true, test_mode_eq: true, utm: undefined, // utm object provided in init @@ -179,12 +179,12 @@ describe("View with utm and referrer tests ", () => { // utm object provided with appropriate query var C2 = Countly.init({ app_key: "Countly_2", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true, test_mode_eq: true, utm: { ss: true }, // utm object provided in init getSearchQuery: function() { // override default search query - return "?utm_ss=hehe2"; + return "utm_ss=hehe2"; } }); C2.track_view(pageNameOne); @@ -278,7 +278,7 @@ describe("isReferrerUsable tests", () => { hp.haltAndClearStorage(() => { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", ignore_referrers: ["http://example.com"] }); const result = Countly._internals.isReferrerUsable("http://example.com/something"); diff --git a/cypress/integration/views.js b/cypress/e2e/views.cy.js similarity index 99% rename from cypress/integration/views.js rename to cypress/e2e/views.cy.js index 236f35e1..4d6a5c58 100644 --- a/cypress/integration/views.js +++ b/cypress/e2e/views.cy.js @@ -6,7 +6,7 @@ var hp = require("../support/helper"); function initMain() { Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode_eq: true, test_mode: true }); diff --git a/cypress/integration/web_worker_queues.js b/cypress/e2e/web_worker_queues.cy.js similarity index 93% rename from cypress/integration/web_worker_queues.js rename to cypress/e2e/web_worker_queues.cy.js index 58dfecad..d612d861 100644 --- a/cypress/integration/web_worker_queues.js +++ b/cypress/e2e/web_worker_queues.cy.js @@ -1,7 +1,7 @@ describe("Web Worker Local Queue Tests", () => { it("Verify queues for all features", () => { // create a worker - const myWorker = new Worker("../../examples/mpa/worker_for_test.js"); + const myWorker = new Worker("../../test_workers/worker_for_test.js", { type: "module" }); // send an event to worker myWorker.postMessage({ data: { key: "key" }, type: "event" }); diff --git a/cypress/integration/web_worker_requests.js b/cypress/e2e/web_worker_requests.cy.js similarity index 70% rename from cypress/integration/web_worker_requests.js rename to cypress/e2e/web_worker_requests.cy.js index b40e8154..2c20cb68 100644 --- a/cypress/integration/web_worker_requests.js +++ b/cypress/e2e/web_worker_requests.cy.js @@ -1,5 +1,6 @@ -import { appKey } from "../support/helper"; +import { turnSearchStringToObject, check_commons } from "../support/helper"; +var expectedRequests = 4; const myEvent = { key: "buttonClick", segmentation: { @@ -10,7 +11,7 @@ const myEvent = { describe("Web Worker Request Intercepting Tests", () => { it("SDK able to send requests for most basic calls", () => { // create a worker - const myWorker = new Worker("../../examples/worker.js"); + const myWorker = new Worker("../../test_workers/worker.js", { type: "module" }); // send an event to worker myWorker.postMessage({ data: myEvent, type: "event" }); @@ -22,8 +23,8 @@ describe("Web Worker Request Intercepting Tests", () => { cy.intercept("GET", "**/i?**", (req) => { const { url } = req; - // check url starts with https://your.domain.countly/i? - assert.isTrue(url.startsWith("https://your.domain.countly/i?")); + // check url starts with https://your.domain.count.ly/i? + assert.isTrue(url.startsWith("https://your.domain.count.ly/i?")); // turn query string into object const paramsObject = turnSearchStringToObject(url.split("?")[1]); @@ -32,7 +33,6 @@ describe("Web Worker Request Intercepting Tests", () => { check_commons(paramsObject); // we expect 4 requests: begin_session, end_session, healthcheck, event(event includes view and buttonClick) - let expectedRequests = 4; if (paramsObject.hc) { // check hc params types, values can change assert.isTrue(typeof paramsObject.hc.el === "number"); @@ -83,43 +83,3 @@ describe("Web Worker Request Intercepting Tests", () => { }); }); }); - -/** - * Check common params for all requests - * @param {Object} paramsObject - object from search string - */ -function check_commons(paramsObject) { - expect(paramsObject.timestamp).to.be.ok; - expect(paramsObject.timestamp.toString().length).to.equal(13); - expect(paramsObject.hour).to.be.within(0, 23); - expect(paramsObject.dow).to.be.within(0, 7); - expect(paramsObject.app_key).to.equal(appKey); - expect(paramsObject.device_id).to.be.ok; - expect(paramsObject.sdk_name).to.equal("javascript_native_web"); - expect(paramsObject.sdk_version).to.be.ok; - expect(paramsObject.t).to.be.within(0, 3); - expect(paramsObject.av).to.equal(0); // av is 0 as we parsed parsable things - if (!paramsObject.hc) { // hc is direct request - expect(paramsObject.rr).to.be.above(-1); - } - expect(paramsObject.metrics._ua).to.be.ok; -} - -/** - * Turn search string into object with values parsed - * @param {String} searchString - search string - * @returns {object} - object from search string - */ -function turnSearchStringToObject(searchString) { - const searchParams = new URLSearchParams(searchString); - const paramsObject = {}; - for (const [key, value] of searchParams.entries()) { - try { - paramsObject[key] = JSON.parse(value); // try to parse value - } - catch (e) { - paramsObject[key] = value; - } - } - return paramsObject; -} \ No newline at end of file diff --git a/cypress/fixtures/click_test.html b/cypress/fixtures/click_test.html index 1e5e3b04..bca3ef33 100644 --- a/cypress/fixtures/click_test.html +++ b/cypress/fixtures/click_test.html @@ -19,7 +19,7 @@ var domEl = queryExtractor(window.location.search).dom; Countly.init({ app_key: "YOUR_APP_KEY", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", debug: true, test_mode: true }) diff --git a/cypress/fixtures/multi_instance.html b/cypress/fixtures/multi_instance.html index b3deb9bd..fa9ddacb 100644 --- a/cypress/fixtures/multi_instance.html +++ b/cypress/fixtures/multi_instance.html @@ -22,7 +22,7 @@ //initializing first instance, which will be global Countly Countly.init({ app_key: "YOUR_APP_KEY1", - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true }) Countly.remove_consent(); @@ -57,7 +57,7 @@ //initialize second instance for another app synchronously var Countly2 = Countly.init({ app_key: "YOUR_APP_KEY2", //must have different APP key - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true }); @@ -94,7 +94,7 @@ //initialize third instance for another app asynchronously Countly.q.push(["init", { app_key: "YOUR_APP_KEY3", //must have different APP key - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true }]) @@ -128,7 +128,7 @@ //initialize fourth instance for another app asynchronously Countly.q.push(["init", { app_key: "YOUR_APP_KEY4", //must have different APP key - url: "https://your.domain.countly", + url: "https://your.domain.count.ly", test_mode: true }]) diff --git a/cypress/fixtures/referrer.html b/cypress/fixtures/referrer.html index 527414f1..5b94d0a5 100644 --- a/cypress/fixtures/referrer.html +++ b/cypress/fixtures/referrer.html @@ -4,7 +4,7 @@
-