Skip to content

Commit

Permalink
change in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-rudder committed Sep 30, 2019
1 parent 7e03cdc commit 06f2973
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 15 deletions.
64 changes: 62 additions & 2 deletions rudder-client-javascript/test/dist/browser.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,86 @@
var analytics = (function (exports) {
'use strict';

function getJSONTrimmed(url, callback) {
//server-side integration, XHR is node module
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);

xhr.onload = function () {
var status = xhr.status;

if (status == 200) {
console.log("status 200");
callback(200, xhr.responseText);
} else {
callback(status);
}

console.log("in response process");
};

console.log("before send");
xhr.send();
console.log("after send");
}

const CONFIG_URL = "https://api.rudderlabs.com";
/* module.exports = {
MessageType: MessageType,
ECommerceParamNames: ECommerceParamNames,
ECommerceEvents: ECommerceEvents,
RudderIntegrationPlatform: RudderIntegrationPlatform,
BASE_URL: BASE_URL,
CONFIG_URL: CONFIG_URL,
FLUSH_QUEUE_SIZE: FLUSH_QUEUE_SIZE
}; */

class test {
constructor() {
this.prop1 = "val1";
this.prop2 = "val2";
this.ready = false;
}

page() {
console.log("page called " + this.prop1);
//if (this.ready) {
console.log("page called " + this.prop1); //}
}

track() {
console.log("track called " + this.prop2);
//if (this.ready) {
console.log("track called " + this.prop2); //}
}

load(writeKey) {
console.log("inside load " + this.prop1);
getJSONTrimmed(CONFIG_URL + "/source-config?write_key=" + writeKey, (status, response) => {
console.log("from callback " + this.prop1);
console.log(response);
this.ready = true;
});
/* setTimeout(() => {
this.ready = true;
}, 5000); */
}

}

let instance = new test();

if (window) {
console.log("is present? " + !!window.analytics);
let methodArg = window.analytics[0];
instance[methodArg[0]](methodArg[1]);
let methodArgNext = window.analytics[1];
instance[methodArgNext[0]]();
}

let page = instance.page.bind(instance);
let track = instance.track.bind(instance);
let load = instance.load.bind(instance);

exports.load = load;
exports.page = page;
exports.track = track;

Expand Down
64 changes: 62 additions & 2 deletions rudder-client-javascript/test/dist/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,85 @@

Object.defineProperty(exports, '__esModule', { value: true });

function getJSONTrimmed(url, callback) {
//server-side integration, XHR is node module
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);

xhr.onload = function () {
var status = xhr.status;

if (status == 200) {
console.log("status 200");
callback(200, xhr.responseText);
} else {
callback(status);
}

console.log("in response process");
};

console.log("before send");
xhr.send();
console.log("after send");
}

const CONFIG_URL = "https://api.rudderlabs.com";
/* module.exports = {
MessageType: MessageType,
ECommerceParamNames: ECommerceParamNames,
ECommerceEvents: ECommerceEvents,
RudderIntegrationPlatform: RudderIntegrationPlatform,
BASE_URL: BASE_URL,
CONFIG_URL: CONFIG_URL,
FLUSH_QUEUE_SIZE: FLUSH_QUEUE_SIZE
}; */

class test {
constructor() {
this.prop1 = "val1";
this.prop2 = "val2";
this.ready = false;
}

page() {
console.log("page called " + this.prop1);
//if (this.ready) {
console.log("page called " + this.prop1); //}
}

track() {
console.log("track called " + this.prop2);
//if (this.ready) {
console.log("track called " + this.prop2); //}
}

load(writeKey) {
console.log("inside load " + this.prop1);
getJSONTrimmed(CONFIG_URL + "/source-config?write_key=" + writeKey, (status, response) => {
console.log("from callback " + this.prop1);
console.log(response);
this.ready = true;
});
/* setTimeout(() => {
this.ready = true;
}, 5000); */
}

}

let instance = new test();

if (window) {
console.log("is present? " + !!window.analytics);
let methodArg = window.analytics[0];
instance[methodArg[0]](methodArg[1]);
let methodArgNext = window.analytics[1];
instance[methodArgNext[0]]();
}

let page = instance.page.bind(instance);
let track = instance.track.bind(instance);
let load = instance.load.bind(instance);

exports.load = load;
exports.page = page;
exports.track = track;
19 changes: 17 additions & 2 deletions rudder-client-javascript/test/dist/test_browser.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<html>
<head> </head>
<script src="../dist/browser.js"></script>
<body>
<h1>Page Loaded</h1>

<script type="text/javascript">
analytics = window.analytics = [];
analytics.page = function() {
analytics.push(["page", "value from array"]);
};

analytics.load = function(writeKey) {
analytics.push(["load", writeKey]);
};

analytics.load("1QbNPCBQp2RFWolFj2ZhXi2ER6a");
analytics.page();
</script>

<script src="../dist/browser.js"></script>

<script type="text/javascript">
//var testObj = new analytics.test();
//testObj.track();
//testObj.page();

//analytics.load("1QbNPCBQp2RFWolFj2ZhXi2ER6a");
analytics.page();
analytics.track();
</script>
Expand Down
36 changes: 35 additions & 1 deletion rudder-client-javascript/test/test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
import { getJSONTrimmed } from "../utils/utils";
import { CONFIG_URL } from "../utils/constants";

class test {
constructor() {
this.prop1 = "val1";
this.prop2 = "val2";
this.ready = false;
}

page() {
//if (this.ready) {
console.log("page called " + this.prop1);
//}
}

track() {
//if (this.ready) {
console.log("track called " + this.prop2);
//}
}

load(writeKey) {
console.log("inside load " + this.prop1);
getJSONTrimmed(
CONFIG_URL + "/source-config?write_key=" + writeKey,
(status, response) => {
console.log("from callback " + this.prop1);
console.log(response);
this.ready = true;
}
);
/* setTimeout(() => {
this.ready = true;
}, 5000); */
}
}

let instance = new test();

if (window) {
console.log("is present? " + !!window.analytics);
let methodArg = window.analytics[0];
instance[methodArg[0]](methodArg[1]);

let methodArgNext = window.analytics[1];
instance[methodArgNext[0]]();
}

let page = instance.page.bind(instance);
let track = instance.track.bind(instance);
let load = instance.load.bind(instance);

export { page, track };
export { page, track, load };
13 changes: 11 additions & 2 deletions rudder-client-javascript/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ const CONFIG_URL = "https://api.rudderlabs.com";

const FLUSH_QUEUE_SIZE = 30;

module.exports = {
export {
MessageType,
ECommerceParamNames,
ECommerceEvents,
RudderIntegrationPlatform,
BASE_URL,
CONFIG_URL,
FLUSH_QUEUE_SIZE
};
/* module.exports = {
MessageType: MessageType,
ECommerceParamNames: ECommerceParamNames,
ECommerceEvents: ECommerceEvents,
RudderIntegrationPlatform: RudderIntegrationPlatform,
BASE_URL: BASE_URL,
CONFIG_URL: CONFIG_URL,
FLUSH_QUEUE_SIZE: FLUSH_QUEUE_SIZE
};
}; */
28 changes: 22 additions & 6 deletions rudder-client-javascript/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,25 @@ function getJSON(url, wrappers, isLoaded, callback) {
console.log("after send");
}

module.exports = {
replacer: replacer,
generateUUID: generateUUID,
getCurrentTimeFormatted: getCurrentTimeFormatted,
getJSON: getJSON
};
//Utility function to retrieve configuration JSON from server
function getJSONTrimmed(url, callback) {
//server-side integration, XHR is node module

var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
console.log("status 200");
callback(200, xhr.responseText);
} else {
callback(status);
}
console.log("in response process");
};
console.log("before send");
xhr.send();
console.log("after send");
}

export { replacer, generateUUID, getCurrentTimeFormatted, getJSONTrimmed };

0 comments on commit 06f2973

Please sign in to comment.