File: cypress/integration/consents.js

Recommend this page to a friend!
  Classes of Arturs Sosins   Countly Web SDK   cypress/integration/consents.js   Download  
File: cypress/integration/consents.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change: New bundle (#456)

* new bundle

* read

* is

* reordered countly

* count.ly to countly

* re order features

* seperated elses

* function gap

* linter

* reverse linter

* gap

* more

* increased test robustness

* reminified

* removed mapping

* Update CHANGELOG.md

---------

Co-authored-by: Artūrs Kadiķis <kadikis.arturs@gmail.com>
fix and try countly removal (#455)
Date: 4 months ago
Size: 4,055 bytes
 

Contents

Class file image Download
/* eslint-disable cypress/no-unnecessary-waiting */ /* eslint-disable require-jsdoc */ var Countly = require("../../lib/countly"); var hp = require("../support/helper"); function initMain(consent) { Countly.init({ app_key: "YOUR_APP_KEY", url: "https://your.domain.countly", require_consent: consent, device_id: "György Ligeti", test_mode: true, test_mode_eq: true, debug: true }); } /** * Checks a queue object for valid/correct values/limits during consent tests * @param {Array} eq - events queue * @param {Array} eventArr - events array for the events to test * @param {boolean} custom - custom event check * @param {boolean} internalOnly - internal event check */ function consent_check(eq, eventArr, custom, internalOnly) { var i = 0; var b = i; var len = eventArr.length; if (custom) { len = 0; } if (internalOnly) { b = i + 1; len = eventArr.length - 1; } while (i < len) { expect(eq[i].key).to.equal(eventArr[b].key); expect(eq[i].count).to.equal(eventArr[b].count); expect(eq[i].segmentation[eventArr[b].count]).to.equal(eventArr[b].segmentation[eventArr[b].count]); i++; b++; } } // tests describe("Consent tests", () => { it("Only custom event should be sent to the queue", () => { hp.haltAndClearStorage(() => { initMain(true); Countly.add_consent(["events"]); hp.events(); cy.fetch_local_event_queue().then((eq) => { expect(eq.length).to.equal(1); consent_check(eq, hp.eventArray, true); }); }); }); it("All but custom event should be sent to the queue", () => { hp.haltAndClearStorage(() => { initMain(true); Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]); hp.events(); cy.fetch_local_event_queue().then((eq) => { expect(eq.length).to.equal(6); consent_check(eq, hp.eventArray, false, true); }); }); }); it("All consents given and all events should be recorded", () => { hp.haltAndClearStorage(() => { initMain(true); Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "events", "push", "clicks"]); hp.events(); cy.fetch_local_event_queue().then((eq) => { expect(eq.length).to.equal(7); consent_check(eq, hp.eventArray, false, false); }); }); }); it("No consent required and all events should be recorded", () => { hp.haltAndClearStorage(() => { initMain(false); hp.events(); cy.fetch_local_event_queue().then((eq) => { expect(eq.length).to.equal(7); consent_check(eq, hp.eventArray, false, false); }); }); }); it("Non-merge ID change should reset all consents", () => { hp.haltAndClearStorage(() => { initMain(true); Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]); Countly.change_id("Richard Wagner II", false); hp.events(); cy.fetch_local_event_queue().then((eq) => { expect(eq.length).to.equal(0); }); }); }); it("Merge ID change should not reset consents", () => { hp.haltAndClearStorage(() => { initMain(true); Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]); Countly.change_id("Richard Wagner the second", true); hp.events(); cy.fetch_local_event_queue().then((eq) => { expect(eq.length).to.equal(6); consent_check(eq, hp.eventArray, false, true); }); }); }); });