|
| 1 | +/* eslint-disable cypress/no-unnecessary-waiting */ |
| 2 | +/* eslint-disable require-jsdoc */ |
| 3 | +var Countly = require("../../Countly.js"); |
| 4 | +var hp = require("../support/helper"); |
| 5 | + |
| 6 | +Countly.q = Countly.q || []; |
| 7 | + |
| 8 | +function initMain() { |
| 9 | + Countly.init({ |
| 10 | + app_key: "YOUR_APP_KEY", |
| 11 | + url: "https://your.domain.count.ly", |
| 12 | + test_mode_eq: true, |
| 13 | + test_mode: true |
| 14 | + }); |
| 15 | +} |
| 16 | + |
| 17 | +const userDetailObj = hp.userDetailObj; |
| 18 | + |
| 19 | +// an event object to use |
| 20 | +const eventObj = { |
| 21 | + key: "in_app_purchase", |
| 22 | + count: 3, |
| 23 | + sum: 2.97, |
| 24 | + dur: 300, |
| 25 | + segmentation: { |
| 26 | + app_version: "1.0", |
| 27 | + country: "Tahiti" |
| 28 | + } |
| 29 | +}; |
| 30 | +const custUP = { |
| 31 | + custom: { "name": "John Doe"} |
| 32 | +} |
| 33 | + |
| 34 | +describe("User properties order test", () => { |
| 35 | + it("User details order test", () => { |
| 36 | + hp.haltAndClearStorage(() => { |
| 37 | + initMain(); |
| 38 | + Countly.begin_session(); |
| 39 | + Countly.add_event(eventObj); |
| 40 | + Countly.user_details(userDetailObj); |
| 41 | + Countly.add_event(eventObj); |
| 42 | + Countly.add_event(eventObj); |
| 43 | + Countly.user_details(userDetailObj); |
| 44 | + cy.fetch_local_event_queue().then((eq) => { |
| 45 | + expect(eq.length).to.equal(0); |
| 46 | + }); |
| 47 | + cy.wait(500).then(() => { |
| 48 | + cy.fetch_local_request_queue(hp.appKey).then((rq) => { |
| 49 | + expect(rq.length).to.equal(5); |
| 50 | + cy.log(rq); |
| 51 | + cy.check_session(rq[0]); |
| 52 | + cy.check_event(JSON.parse(rq[1].events)[1], eventObj, undefined, false); |
| 53 | + cy.check_user_details(rq[2], userDetailObj); |
| 54 | + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); |
| 55 | + cy.check_event(JSON.parse(rq[3].events)[1], eventObj, undefined, false); |
| 56 | + cy.check_user_details(rq[4], userDetailObj); |
| 57 | + }); |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | + it("User details order test, async", () => { |
| 62 | + hp.haltAndClearStorage(() => { |
| 63 | + initMain(); |
| 64 | + Countly.q.push(['track_sessions']); |
| 65 | + Countly.q.push(['add_event', eventObj]); |
| 66 | + Countly.q.push(['user_details', userDetailObj]); |
| 67 | + Countly.q.push(['add_event', eventObj]); |
| 68 | + Countly.q.push(['add_event', eventObj]); |
| 69 | + Countly.q.push(['user_details', userDetailObj]); |
| 70 | + cy.fetch_local_event_queue().then((eq) => { |
| 71 | + expect(eq.length).to.equal(0); |
| 72 | + }); |
| 73 | + cy.wait(500).then(() => { |
| 74 | + cy.fetch_local_request_queue(hp.appKey).then((rq) => { |
| 75 | + expect(rq.length).to.equal(5); |
| 76 | + cy.log(rq); |
| 77 | + cy.check_session(rq[0]); |
| 78 | + cy.check_event(JSON.parse(rq[1].events)[1], eventObj, undefined, false); |
| 79 | + cy.check_user_details(rq[2], userDetailObj); |
| 80 | + cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); |
| 81 | + cy.check_event(JSON.parse(rq[3].events)[1], eventObj, undefined, false); |
| 82 | + cy.check_user_details(rq[4], userDetailObj); |
| 83 | + }); |
| 84 | + }); |
| 85 | + }); |
| 86 | + }); |
| 87 | + it("User data order test", () => { |
| 88 | + hp.haltAndClearStorage(() => { |
| 89 | + initMain(); |
| 90 | + Countly.userData.set("name", "John Doe"); |
| 91 | + Countly.begin_session(); |
| 92 | + Countly.userData.set("name", "John Doe"); |
| 93 | + Countly.add_event(eventObj); |
| 94 | + Countly.userData.set("name", "John Doe"); |
| 95 | + Countly.user_details(userDetailObj); |
| 96 | + cy.fetch_local_event_queue().then((eq) => { |
| 97 | + expect(eq.length).to.equal(0); |
| 98 | + }); |
| 99 | + cy.wait(500).then(() => { |
| 100 | + cy.fetch_local_request_queue(hp.appKey).then((rq) => { |
| 101 | + expect(rq.length).to.equal(6); |
| 102 | + cy.log(rq); |
| 103 | + cy.check_user_details(rq[0], custUP); |
| 104 | + cy.check_session(rq[1]); |
| 105 | + cy.check_user_details(rq[2], custUP); |
| 106 | + cy.check_event(JSON.parse(rq[3].events)[1], eventObj, undefined, false); |
| 107 | + cy.check_user_details(rq[4], custUP); |
| 108 | + cy.check_user_details(rq[5], userDetailObj); |
| 109 | + }); |
| 110 | + }); |
| 111 | + }); |
| 112 | + }); |
| 113 | + it("User data order test, async", () => { |
| 114 | + hp.haltAndClearStorage(() => { |
| 115 | + initMain(); |
| 116 | + Countly.q.push(['userData.set', "name", "John Doe"]); |
| 117 | + Countly.q.push(['track_sessions']); |
| 118 | + Countly.q.push(['userData.set', "name", "John Doe"]); |
| 119 | + Countly.q.push(['add_event', eventObj]); |
| 120 | + Countly.q.push(['userData.set', "name", "John Doe"]); |
| 121 | + Countly.q.push(['user_details', userDetailObj]); |
| 122 | + cy.fetch_local_event_queue().then((eq) => { |
| 123 | + expect(eq.length).to.equal(0); |
| 124 | + }); |
| 125 | + cy.wait(500).then(() => { |
| 126 | + cy.fetch_local_request_queue(hp.appKey).then((rq) => { |
| 127 | + expect(rq.length).to.equal(6); |
| 128 | + cy.log(rq); |
| 129 | + cy.check_user_details(rq[0], custUP); |
| 130 | + cy.check_session(rq[1]); |
| 131 | + cy.check_user_details(rq[2], custUP); |
| 132 | + cy.check_event(JSON.parse(rq[3].events)[1], eventObj, undefined, false); |
| 133 | + cy.check_user_details(rq[4], custUP); |
| 134 | + cy.check_user_details(rq[5], userDetailObj); |
| 135 | + }); |
| 136 | + }); |
| 137 | + }); |
| 138 | + }); |
| 139 | +}); |
0 commit comments