Skip to content

Commit 17eab57

Browse files
committed
Added refresh
1 parent 7cb94a5 commit 17eab57

File tree

6 files changed

+493
-85
lines changed

6 files changed

+493
-85
lines changed

cypress/e2e/device_id_init_scenarios.cy.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,19 @@ function checkRequestsForT(queue, expectedInternalType) {
115115
expect(queue[i].t).to.eq(expectedInternalType);
116116
}
117117
}
118-
function checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType, temp) {
118+
function checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType, temp, afterOffline) {
119119
var directReqs = Countly._internals.testingGetRequests(); // get direct requests
120120
cy.log("Requests: " + JSON.stringify(directReqs));
121121

122-
expect(directReqs.length).to.eq(temp ? 0 : 2);
122+
expect(directReqs.length).to.eq(temp ? 0 : afterOffline?4:3);
123123
for (var i = 0; i < directReqs.length; i++) {
124-
expect(directReqs[i].params.device_id).to.eq(afterInitDeviceId);
125-
expect(directReqs[i].params.t).to.eq(afterInitDeviceIdType);
124+
if (afterOffline && directReqs[i].functionName == "server_config" && i == directReqs.length - 1) {
125+
expect(directReqs[i].params.device_id).to.be.oneOf(["id_2", "storedID", "newID"]);
126+
expect(directReqs[i].params.t).to.eq(DeviceIdTypeInternalEnumsTest.DEVELOPER_SUPPLIED);
127+
} else {
128+
expect(directReqs[i].params.device_id).to.eq(afterInitDeviceId);
129+
expect(directReqs[i].params.t).to.eq(afterInitDeviceIdType);
130+
}
126131
}
127132
}
128133
function checkEachStoredReqForIDandT(afterInitDeviceId, afterInitDeviceIdType) {
@@ -253,7 +258,7 @@ function changeIDTests(afterInitDeviceId, afterInitDeviceIdType, afterOffline) {
253258
// wait for things to resolve
254259
cy.wait(550).then(() => {
255260
// direct requests would have the old device id (hc and session)
256-
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType);
261+
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType, false, true);
257262

258263
// after ID events
259264
checkStoredReqQueueAfterIDChange(changedID2, changedIDType2, afterOffline? 3 : 2); // no end and begin session in offline mode => device id change scenario
@@ -459,7 +464,7 @@ describe("Device Id tests during first init", ()=>{
459464
// wait for things to resolve
460465
cy.wait(550).then(() => {
461466
// direct requests would have the old device id (hc and session)
462-
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType);
467+
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType, false, true);
463468

464469
// after ID events
465470
checkStoredReqQueueAfterIDChange(changedID, changedIDType, true); // no end and begin session in offline mode => device id change scenario
@@ -535,7 +540,7 @@ describe("Device Id tests during first init", ()=>{
535540
// wait for things to resolve
536541
cy.wait(550).then(() => {
537542
// direct requests would have the old device id (hc and session)
538-
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType);
543+
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType, false, true);
539544

540545
// after ID events
541546
checkStoredReqQueueAfterIDChange(changedID, changedIDType, true);
@@ -687,7 +692,7 @@ describe("Device Id tests during first init", ()=>{
687692
// wait for things to resolve
688693
cy.wait(550).then(() => {
689694
// direct requests would have the old device id (hc and session)
690-
checkEachDirectReqForIDandT(afterInitDeviceId, DeviceIdTypeInternalEnumsTest.URL_PROVIDED);
695+
checkEachDirectReqForIDandT(afterInitDeviceId, DeviceIdTypeInternalEnumsTest.URL_PROVIDED, false, true);
691696

692697
// after ID events
693698
checkStoredReqQueueAfterIDChange(changedID, changedIDType, true);
@@ -1756,7 +1761,7 @@ describe("Device Id tests during first init", ()=>{
17561761
// wait for things to resolve
17571762
cy.wait(550).then(() => {
17581763
// direct requests would have the old device id (hc and session)
1759-
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType);
1764+
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType, false, true);
17601765

17611766
// after ID events
17621767
checkStoredReqQueueAfterIDChange(changedID, changedIDType, true); // no end and begin session in offline mode => device id change scenario
@@ -1832,7 +1837,7 @@ describe("Device Id tests during first init", ()=>{
18321837
// wait for things to resolve
18331838
cy.wait(550).then(() => {
18341839
// direct requests would have the old device id (hc and session)
1835-
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType);
1840+
checkEachDirectReqForIDandT(afterInitDeviceId, afterInitDeviceIdType, false, true);
18361841

18371842
// after ID events
18381843
checkStoredReqQueueAfterIDChange(changedID, changedIDType, true);
@@ -1984,7 +1989,7 @@ describe("Device Id tests during first init", ()=>{
19841989
// wait for things to resolve
19851990
cy.wait(550).then(() => {
19861991
// direct requests would have the old device id (hc and session)
1987-
checkEachDirectReqForIDandT(afterInitDeviceId, DeviceIdTypeInternalEnumsTest.URL_PROVIDED);
1992+
checkEachDirectReqForIDandT(afterInitDeviceId, DeviceIdTypeInternalEnumsTest.URL_PROVIDED, false, true);
19881993

19891994
// after ID events
19901995
checkStoredReqQueueAfterIDChange(changedID, changedIDType, true);

cypress/e2e/integration.cy.js

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,14 @@ function initMain() {
1616
describe("Integration test", () => {
1717
it("int, no consent, no offline_mode", () => {
1818
initMain();
19-
const idType = Countly.get_device_id_type();
20-
const id = Countly.get_device_id();
21-
const consentStatus = Countly.check_any_consent();
22-
Countly.remove_consent();
23-
Countly.disable_offline_mode();
24-
Countly.add_event({ key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } });
25-
Countly.start_event("test");
26-
Countly.cancel_event("gobbledygook");
27-
Countly.end_event("test");
28-
Countly.report_conversion("camp_id", "camp_user_id");
29-
Countly.recordDirectAttribution("camp_id", "camp_user_id");
30-
Countly.user_details({ name: "name" });
31-
Countly.userData.set("set", "set");
32-
Countly.userData.save();
33-
Countly.report_trace({ name: "name", stz: 1, type: "type" });
34-
Countly.log_error({ error: "error", stack: "stack" });
35-
Countly.add_log("error");
36-
Countly.fetch_remote_config();
37-
Countly.enrollUserToAb();
38-
const remote = Countly.get_remote_config();
39-
Countly.track_sessions();
40-
Countly.track_pageview();
41-
Countly.track_errors();
42-
Countly.track_clicks();
43-
Countly.track_scrolls();
44-
Countly.track_links();
45-
Countly.track_forms();
46-
Countly.collect_from_forms();
47-
Countly.collect_from_facebook();
48-
Countly.opt_in();
49-
// TODO: widgets
50-
// TODO: make better
19+
var consentStatus = Countly.check_any_consent();
20+
var remote = Countly.get_remote_config();
21+
var id = Countly.get_device_id();
22+
var idType = Countly.get_device_id_type();
23+
hp.integrationMethods();
5124
cy.fetch_local_request_queue().then((rq) => {
5225
cy.log(rq);
53-
hp.testNormalFlow(rq, "/__cypress/iframes/cypress%5Ce2e%5Cintegration.cy.js", hp.appKey);
26+
hp.testNormalFlowInt(rq, "/__cypress/iframes/cypress%5Ce2e%5Cintegration.cy.js", hp.appKey);
5427
expect(consentStatus).to.equal(true); // no consent necessary
5528
expect(remote).to.eql({}); // deepEqual
5629
expect(rq[0].device_id).to.equal(id);

cypress/e2e/remaining_requests.cy.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ describe("Remaining requests tests ", () => {
2828
expect(JSON.parse(queues.requestQ[2]["events"])[0].key).to.equal("[CLY]_orientation");
2929

3030
var requests = Countly._internals.testingGetRequests();
31-
expect(requests.length).to.equal(2);
31+
expect(requests.length).to.equal(3);
3232
expect(requests[0].params["rr"]).to.equal(undefined);
33-
expect(requests[1].params["rr"]).to.equal(3);
34-
expect(requests[1].params["av"]).to.equal(av);
33+
expect(requests[1].params["rr"]).to.equal(undefined);
34+
expect(requests[2].params["rr"]).to.equal(3);
35+
expect(requests[2].params["av"]).to.equal(av);
3536
});
3637
});
3738
});

cypress/e2e/sdk_behavior.cy.js

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
/* eslint-disable require-jsdoc */
2+
var Countly = require("../../Countly.js");
3+
var hp = require("../support/helper");
4+
5+
function initMain(val) {
6+
Countly.init({
7+
app_key: "spp",
8+
url: "https://hey.some.ly",
9+
debug: true,
10+
behavior_settings: val
11+
});
12+
}
13+
14+
function sentReqList(size, expectedKeywords, nonexistingKeywords) {
15+
var directReqs = Countly._internals.testingGetRequests(); // get direct requests
16+
var functionNames = directReqs.map((item) => item.functionName);
17+
cy.log("Direct Requests: " + JSON.stringify(directReqs));
18+
19+
if (typeof size !== 'undefined') {
20+
expect(directReqs.length).to.eq(size);
21+
}
22+
if (expectedKeywords) {
23+
for (var i = 0; i < expectedKeywords.length; i++) {
24+
expect(functionNames.includes(expectedKeywords[i])).to.be.true;
25+
}
26+
}
27+
if (nonexistingKeywords) {
28+
for (var j = 0; j < nonexistingKeywords.length; j++) {
29+
expect(functionNames.includes(nonexistingKeywords[j])).to.be.false;
30+
}
31+
}
32+
}
33+
function queues(eqsize, rqsize, expectedKeywords, nonexistingKeywords) {
34+
var queues = Countly._internals.getLocalQueues(); // get local queues
35+
const allKeysE = queues.eventQ.flatMap(item => Object.keys(item));
36+
const allKeysQ = queues.requestQ.flatMap(item => Object.keys(item));
37+
const uniqueKeys = [...new Set(allKeysE), ...new Set(allKeysQ)];
38+
39+
const allValuesE = queues.eventQ.flatMap(item => Object.values(item));
40+
const allValuesQ = queues.requestQ.flatMap(item => Object.values(item));
41+
const uniqueValues = [...new Set(allValuesE), ...new Set(allValuesQ)];
42+
43+
cy.log("Unique Keys: " + JSON.stringify(uniqueKeys));
44+
cy.log("Queues: " + JSON.stringify(queues));
45+
46+
if (typeof eqsize !== 'undefined') {
47+
expect(queues.eventQ.length).to.eq(eqsize);
48+
}
49+
if (typeof rqsize !== 'undefined') {
50+
expect(queues.requestQ.length).to.eq(rqsize);
51+
}
52+
if (expectedKeywords) {
53+
for (var i = 0; i < expectedKeywords.length; i++) {
54+
expect(uniqueKeys.includes(expectedKeywords[i])).to.be.true;
55+
}
56+
}
57+
if (nonexistingKeywords) {
58+
for (var j = 0; j < nonexistingKeywords.length; j++) {
59+
expect(uniqueValues.includes(nonexistingKeywords[j])).to.be.false;
60+
}
61+
}
62+
}
63+
64+
const waitT = 2000;
65+
66+
describe("SDK Behavior test", () => {
67+
it("Basic initialization with default config", () => {
68+
hp.haltAndClearStorage(() => {
69+
initMain();
70+
cy.wait(waitT).then(() => {
71+
cy.fetch_local_request_queue().then((rq) => {
72+
cy.log("Request Queue: " + JSON.stringify(rq));
73+
sentReqList(2, ["server_config", "[healthCheck]"]);
74+
queues(0, 0);
75+
});
76+
});
77+
});
78+
});
79+
80+
it("Initialization with default config and integration methods", () => {
81+
hp.haltAndClearStorage(() => {
82+
initMain();
83+
hp.integrationMethods();
84+
cy.wait(waitT).then(() => {
85+
cy.fetch_local_request_queue().then((rq) => {
86+
cy.log("Request Queue: " + JSON.stringify(rq));
87+
sentReqList(9, ["server_config", "[healthCheck]", "enrollUserToAb", "fetch_remote_config_explicit", "send_request_queue", "get_available_feedback_widgets,"]);
88+
queues(0, 15);
89+
});
90+
});
91+
});
92+
});
93+
94+
it("Config with networking disabled", () => {
95+
hp.haltAndClearStorage(() => {
96+
var settings = {};
97+
settings.c = {
98+
networking: false
99+
};
100+
initMain(settings);
101+
hp.integrationMethods();
102+
cy.wait(waitT).then(() => {
103+
cy.fetch_local_request_queue().then((rq) => {
104+
cy.log("Request Queue: " + JSON.stringify(rq));
105+
sentReqList(1, ["server_config"]);
106+
queues(0, 15);
107+
});
108+
});
109+
});
110+
});
111+
112+
it("Config with tracking disabled", () => {
113+
hp.haltAndClearStorage(() => {
114+
var settings = {};
115+
settings.c = {
116+
tracking: false
117+
};
118+
initMain(settings);
119+
hp.integrationMethods();
120+
cy.wait(waitT).then(() => {
121+
cy.fetch_local_request_queue().then((rq) => {
122+
cy.log("Request Queue: " + JSON.stringify(rq));
123+
sentReqList(8, ["server_config", "[healthCheck]", "enrollUserToAb", "fetch_remote_config_explicit", "get_available_feedback_widgets,"]);
124+
queues(0,0);
125+
});
126+
});
127+
});
128+
});
129+
130+
it("Config with both tracking and networking disabled", () => {
131+
hp.haltAndClearStorage(() => {
132+
var settings = {};
133+
settings.c = {
134+
tracking: false,
135+
networking: false
136+
};
137+
initMain(settings);
138+
hp.integrationMethods();
139+
cy.wait(waitT).then(() => {
140+
cy.fetch_local_request_queue().then((rq) => {
141+
cy.log("Request Queue: " + JSON.stringify(rq));
142+
sentReqList(1, ["server_config"]);
143+
queues(0,0);
144+
});
145+
});
146+
});
147+
});
148+
149+
it("Config with consent required true", () => {
150+
hp.haltAndClearStorage(() => {
151+
var settings = {};
152+
settings.c = {
153+
cr: true
154+
};
155+
initMain(settings);
156+
hp.integrationMethods();
157+
cy.wait(waitT).then(() => {
158+
cy.fetch_local_request_queue().then((rq) => {
159+
cy.log("Request Queue: " + JSON.stringify(rq));
160+
sentReqList(4, ["server_config", "[healthCheck]", "enrollUserToAb", "send_request_queue"]); // device id change sent
161+
queues(0, 2, ["old_device_id", "consent"]);
162+
});
163+
});
164+
});
165+
});
166+
167+
it("Limited queue sizes with networking disabled", () => {
168+
hp.haltAndClearStorage(() => {
169+
var settings = {};
170+
settings.c = {
171+
rqs: 1,
172+
eqs: 1,
173+
networking: false,
174+
};
175+
initMain(settings);
176+
Countly.add_event({key: "test_1"});
177+
Countly.add_event({key: "test_2"});
178+
Countly.add_event({key: "test_3"});
179+
Countly.add_event({key: "test_4"});
180+
Countly.add_event({key: "test_5"});
181+
cy.wait(3000).then(() => {
182+
cy.fetch_local_request_queue().then((rq) => {
183+
cy.log("Request Queue: " + JSON.stringify(rq));
184+
sentReqList(1, ["server_config"]);
185+
queues(0, 2, ["events"], ["test_1", "test_2", "test_3"]); // 1+1
186+
});
187+
});
188+
});
189+
});
190+
191+
it("Session update interval configuration", () => {
192+
hp.haltAndClearStorage(() => {
193+
var settings = {};
194+
settings.c = {
195+
sui: 1,
196+
};
197+
initMain(settings);
198+
Countly.track_sessions();
199+
cy.wait(4000).then(() => {
200+
cy.fetch_local_request_queue().then((rq) => {
201+
cy.log("Request Queue: " + JSON.stringify(rq));
202+
sentReqList(3, ["server_config", "[healthCheck]", "send_request_queue"]);
203+
queues(0, 4, ["session_duration", "begin_session"], ["session_end"]);
204+
});
205+
});
206+
});
207+
});
208+
209+
it("Disabled tracking types configuration", () => {
210+
hp.haltAndClearStorage(() => {
211+
var settings = {};
212+
settings.c = {
213+
st: false,
214+
crt: false,
215+
lt: false,
216+
vt: false,
217+
cet: false,
218+
};
219+
initMain(settings);
220+
Countly.track_sessions();
221+
Countly.add_event({key: "test_1"});
222+
Countly.track_pageview();
223+
Countly.log_error({message: "test"});
224+
cy.wait(4000).then(() => {
225+
cy.fetch_local_request_queue().then((rq) => {
226+
cy.log("Request Queue: " + JSON.stringify(rq));
227+
sentReqList(2, ["server_config", "[healthCheck]"]);
228+
queues(0, 0);
229+
});
230+
});
231+
});
232+
});
233+
});

0 commit comments

Comments
 (0)