File: test/tests_device_id.js

Recommend this page to a friend!
  Classes of Arturs Sosins   Countly SDK for Node.js   test/tests_device_id.js   Download  
File: test/tests_device_id.js
Role: Auxiliary script
Content type: text/plain
Description: Configuration script
Class: Countly SDK for Node.js
Report events to be tracked with by Count.ly API
Author: By
Last change:
Date: Yesterday
Size: 3,277 bytes
 

Contents

Class file image Download
/* eslint-disable no-console */ var assert = require("assert"); var Countly = require("../lib/countly"); var cc = require("../lib/countly-common"); var hp = require("./helpers/helper_functions"); function initMain(deviceId, eraseID) { Countly.init({ app_key: "YOUR_APP_KEY", url: "https://try.count.ly", device_id: deviceId, max_events: -1, // debug: true, clear_stored_device_id: eraseID, }); } function validateSdkGeneratedId(providedDeviceId) { assert.ok(providedDeviceId); assert.equal(providedDeviceId.length, 36); assert.ok(cc.isUUID(providedDeviceId)); assert.equal(Countly.get_device_id(), providedDeviceId); assert.equal(Countly.get_device_id_type(), Countly.DeviceIdType.SDK_GENERATED); } function validateDeveloperSuppliedId(providedDeviceId) { assert.equal(Countly.get_device_id_type(), Countly.DeviceIdType.DEVELOPER_SUPPLIED); assert.equal(Countly.get_device_id(), providedDeviceId); } describe("Device ID tests", () => { beforeEach(async() => { await hp.clearStorage(); }); it("1- set_id with SDK generated to developer supplied", (done) => { // initialize SDK initMain(undefined); validateSdkGeneratedId(Countly.get_device_id()); var oldId = Countly.get_device_id(); Countly.set_id("ID"); validateDeveloperSuppliedId("ID"); setTimeout(() => { // validate that merge request is generated var RQ = hp.readRequestQueue(); assert.equal(RQ.length, 1); hp.requestBaseParamValidator(RQ[0]); assert.equal(RQ[0].old_device_id, oldId); done(); }, hp.sWait); }); it("2- set_id with developer supplied to developer supplied", (done) => { // initialize SDK initMain("ID2"); validateDeveloperSuppliedId("ID2"); Countly.set_id("ID"); validateDeveloperSuppliedId("ID"); setTimeout(() => { // validate that no merge request is generated and the existing request is begin session var RQ = hp.readRequestQueue(); assert.equal(RQ.length, 1); hp.sessionRequestValidator(RQ[0]); done(); }, hp.sWait); }); it("3- set_id with same custom id", (done) => { // initialize SDK initMain("ID"); validateDeveloperSuppliedId("ID"); Countly.set_id("ID"); validateDeveloperSuppliedId("ID"); done(); }); it("4- set_id with same sdk generated id", (done) => { // initialize SDK initMain(undefined); var id = Countly.get_device_id(); validateSdkGeneratedId(id); Countly.set_id(id); // so that the type is not converted to developer_supplied validateSdkGeneratedId(id); done(); }); it("5- set_id with invalid ids", (done) => { // initialize SDK initMain(undefined); var id = Countly.get_device_id(); validateSdkGeneratedId(id); Countly.set_id(undefined); validateSdkGeneratedId(id); Countly.set_id(null); validateSdkGeneratedId(id); Countly.set_id(""); validateSdkGeneratedId(id); done(); }); });