File: cypress/integration/remaining_requests.js

Recommend this page to a friend!
  Classes of Arturs Sosins   Countly Web SDK   cypress/integration/remaining_requests.js   Download  
File: cypress/integration/remaining_requests.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: 6 months ago
Size: 4,069 bytes
 

Contents

Class file image Download
/* eslint-disable require-jsdoc */ var Countly = require("../../lib/countly"); var hp = require("../support/helper"); function initMain(shouldStopRequests) { Countly.init({ app_key: "YOUR_APP_KEY", url: "https://your.domain.countly", app_version: "1.0", // would prevent requests from being sent to the server if true test_mode: shouldStopRequests }); } const av = "1.0"; describe("Remaining requests tests ", () => { it("Checks the requests for rr", () => { hp.haltAndClearStorage(() => { initMain(false); // We will expect 4 requests: health check, begin_session, end_session, orientation hp.interceptAndCheckRequests(undefined, undefined, undefined, "?hc=*", "hc", (requestParams) => { const params = JSON.parse(requestParams.get("hc")); assert.isTrue(typeof params.el === "number"); assert.isTrue(typeof params.wl === "number"); assert.isTrue(typeof params.sc === "number"); assert.isTrue(typeof params.em === "string"); expect(requestParams.get("rr")).to.equal(null); }); cy.wait(1000).then(() => { // Create a session Countly.begin_session(); hp.interceptAndCheckRequests(undefined, 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) => { 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) => { 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); }); cy.wait(100).then(() => { cy.fetch_local_request_queue().then((rq) => { expect(rq.length).to.equal(0); }); }); }); }); }); it("No rr if no request was made to the server", () => { hp.haltAndClearStorage(() => { initMain(true); // Create a session and end it Countly.begin_session(); Countly.end_session(undefined, true); cy.fetch_local_request_queue().then((rq) => { // We expect 3 requests in queue: begin_session, end_session, orientation. health check was not in the queue expect(rq.length).to.equal(3); expect(rq[0].rr).to.equal(3); expect(rq[1].rr).to.equal(undefined); expect(rq[2].rr).to.equal(undefined); // Change ID Countly.change_id("newID"); cy.fetch_local_request_queue().then((rq2) => { // We expect 4 requests in queue: begin_session, end_session, orientation and change ID cy.log(rq2); expect(rq2.length).to.equal(4); expect(rq2[0].rr).to.equal(3); // still 3 as it was assigned at the time of the first request creation expect(rq2[1].rr).to.equal(undefined); expect(rq2[2].rr).to.equal(undefined); expect(rq2[3].rr).to.equal(undefined); }); }); }); }); });