Skip to content

Commit

Permalink
moved functionality to API specific file; more tests
Browse files Browse the repository at this point in the history
Front-end tests are fully implemented. Front-end code also works now!

API specific stuff has been moved to it's own file is tested.
  • Loading branch information
genejones committed Jan 28, 2018
1 parent 953d2f8 commit f1bd1e7
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 264 deletions.
55 changes: 55 additions & 0 deletions __mocks__/html-segments-for-frontend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
let modal = `
<div class="modal fade" tabindex="-1" role="dialog" id="adobe-instructions-modal">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">How to Obtain your Adobe Credentials</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<!-- add smallest transparent gif to the images, along with the actual source. Lazy load the images later -->
<span id="cred-instructions-0" data-current-instruction="true" data-next-step="cred-instructions-1"><h5>Find your user profile on the top menu</h5><i class="far fa-4x fa-spin fa-spinner"></i><img class="img-responsive img-thumbnail" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="0.jpg" /></span>
<span id="cred-instructions-1" data-prev-step="cred-instructions-0" data-next-step="cred-instructions-2" class="collapse"><h5>Click "Edit your profile"</h5><img class="img-responsive img-thumbnail" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="1.jpg" /></span>
<span id="cred-instructions-2" data-prev-step="cred-instructions-1" class="collapse"><h5>Scroll to "Web Service". Your credentials are located here.</h5><img class="img-responsive img-thumbnail" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="2.jpg" /></span>
</div>
<div class="modal-footer">
<nav aria-label="Instructions navigation">
<ul class="pagination justify-content-center">
<li class="page-item disabled previous"><a class="page-link" href="#"><span aria-hidden="true">&larr;</span> Previous Step</a></li>
<li class="page-item next"><a class="page-link" href="#">Next Step <span aria-hidden="true">&rarr;</span></a></li>
</ul>
</nav>
<button style="display:none;" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->`;

let modal_at_step_1 = `
<div class="modal fade" tabindex="-1" role="dialog" id="adobe-instructions-modal">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">How to Obtain your Adobe Credentials</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<!-- add smallest transparent gif to the images, along with the actual source. Lazy load the images later -->
<span id="cred-instructions-0" class="collapse"><h5>Find your user profile on the top menu</h5><img class="img-responsive img-thumbnail" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="0.jpg" /></span>
<span id="cred-instructions-1" data-current-instruction="true" data-prev-step="cred-instructions-0" data-next-step="cred-instructions-2" data-next-step="cred-instructions-2"><h5>Click "Edit your profile"</h5><img class="img-responsive img-thumbnail" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="1.jpg" /></span>
<span id="cred-instructions-2" data-prev-step="cred-instructions-1"><h5>Scroll to "Web Service". Your credentials are located here.</h5><img class="img-responsive img-thumbnail" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="2.jpg" /></span>
</div>
<div class="modal-footer">
<nav aria-label="Instructions navigation">
<ul class="pagination justify-content-center">
<li class="page-item disabled previous"><a class="page-link" href="#"><span aria-hidden="true">&larr;</span> Previous Step</a></li>
<li class="page-item next"><a class="page-link" href="#">Next Step <span aria-hidden="true">&rarr;</span></a></li>
</ul>
</nav>
<button style="display:none;" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->`;

module.exports = {modal, modal_at_step_1};
4 changes: 3 additions & 1 deletion __mocks__/wsse-creds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ global.window = global.windows || {};
window.fileName = 'testing-123.xlsx';
window.username = 'user:company';
window.pass = 'supersecretstuff';
window.dataLayer = [];
window.dataLayer = [];
window.omnibus = window.omnibus || {};
window.omnibus.front = {imagesLoaded: false};
153 changes: 125 additions & 28 deletions adobe-api-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var currentTokenWSSE = '';
var wsse = require('wsse');
var request = require('browser-request');

var constructRequestBodyRSID = function(report_suites){
//posting this over AJAX makes things picky for some reason.
Expand All @@ -21,43 +22,139 @@ var constructRequestBodyRSID = function(report_suites){
return stringList;
};

var getNewAuthToken = function() {
var token = wsse({username:window.username, password:window.pass});
let username = '';
let password = '';
function setCredentials (userInput, passInput){
username = userInput;
password = passInput;
}
function getCredentials (){
return {username, password};
}

function getNewAuthToken () {
var token = wsse(getCredentials());
currentTokenWSSE = token.getWSSEHeader({ nonceBase64: true });
console.debug(currentTokenWSSE);
return currentTokenWSSE;
};

var getHeaders = function(){
getNewAuthToken();
function getHeaders (){
let currentTokenWSSE = getNewAuthToken();
return {
'Content-Type': 'application/x-www-form-urlencoded',
'X-WSSE': currentTokenWSSE
};
};

var getListOfReportSuites = function(callback){
var options = {
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=Company.GetReportSuites',
body: "search=&types=standard",
method: 'POST',
json: true
};
request(options, function (err, res, body) {
if (!err){
console.log(body);
report_suites = body.report_suites;
callback(false, report_suites);
}
else{
console.log(res.statusCode);
callback(err, null);
function constructRequestBodyRSID (report_suites) {
//posting this over AJAX makes things picky for some reason.
//this function manually constructs the POST body to make Adobe happy
//because all my earlier attempts to use querystring or other methods failed.
window.rsid_list = {
"rsid_list": []
};
var stringList = '{"rsid_list":[';
for (var i = 0; i < report_suites.length; i++) {
stringList = stringList + '"' + report_suites[i] + '"';
if (i < report_suites.length - 1) {
stringList = stringList + ",";
}
}
stringList = stringList + ']}';
return stringList;
};

function getListOfReportSuites (callback) {
var options = {
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=Company.GetReportSuites',
body: "search=&types=standard",
method: 'POST',
json: true
};
request(options, function (err, res, body) {
if (!err) {
report_suites = body.report_suites;
callback(report_suites);
}
else {
console.log(res.statusCode);
displayError(err);
}
});
};

function getListOfEvars (form, callback) {
getNewAuthToken();
request({
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetEvars',
body: form,
method: 'POST'
}, function (err, res, body) {
if (!err) {
var evarsRaw = body;
let evars = JSON.parse(evarsRaw);
callback(evars);
}
else {
console.log(res.statusCode);
displayError(err);
console.log(body);
}
});
};

function getListOfProps (form, callback) {
getNewAuthToken();
request({
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetProps',
body: form,
method: 'POST'
}, function (err, res, body) {
if (!err) {
var propsRaw = body;
let props = JSON.parse(propsRaw);
callback(props);
}
else {
console.log(res.statusCode);
displayError(err);
console.log(body);
}
});
};

function getListOfEvents (form, callback) {
request({
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetEvents',
body: form,
method: 'POST'
}, function (err, res, body) {
if (!err) {
var eventsRaw = body;
let events = JSON.parse(eventsRaw);
callback(events)
}

});
else {
console.log(res.statusCode);
displayError(err);
console.log(body);
}
});
};

var exports = module.exports = {};
exports.getHeaders = getHeaders;
exports.getNewAuthToken = getNewAuthToken;
exports.getListOfReportSuites = getListOfReportSuites;
var exports = module.exports = {
constructRequestBodyRSID,
setCredentials,
getHeaders,
getNewAuthToken,
getListOfReportSuites,
getListOfEvents,
getListOfEvars,
getListOfProps,
_currentTokenWSSE : function(){return currentTokenWSSE;},
request
};
51 changes: 51 additions & 0 deletions adobe-api-helpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var adobe_api = require('./adobe-api-helpers.js');
var expectedValues = require('./__mocks__/expected-values.js').modules;
var htmlSnippets = require('./__mocks__/html-segments-for-client.js');

test("wsse creates and updates value", () => {
adobe_api.getNewAuthToken();
let oldToken = adobe_api.getNewAuthToken();
expect(oldToken).not.toBe('');
//verify that update works
let newToken = adobe_api.getNewAuthToken();
expect(newToken).not.toBe(oldToken);
});

test("reportsuite API request", done => {
function callback(reportsuites){
expect(reportsuites).toEqual(expectedValues.reportsuitesRequest.report_suites);
done();
}

adobe_api.getListOfReportSuites(callback);
});

test("evars API request", done => {
document.body.innerHTML = htmlSnippets.displaySystem + htmlSnippets.progressDisplay;
function callback(evars){
expect(evars).toEqual(expectedValues.evars);
done();
}

adobe_api.getListOfEvars(expectedValues.selectedFormDataAll, callback);
});

test("props API request", done => {
document.body.innerHTML = htmlSnippets.displaySystem + htmlSnippets.progressDisplay;
function callback(evars){
expect(evars).toEqual(expectedValues.props);
done();
}

adobe_api.getListOfProps(expectedValues.selectedFormDataAll, callback);
});

test("events API request", done => {
document.body.innerHTML = htmlSnippets.displaySystem + htmlSnippets.progressDisplay;
function callback(evars){
expect(evars).toEqual(expectedValues.events);
done();
}

adobe_api.getListOfEvents(expectedValues.selectedFormDataAll, callback);
});
Loading

0 comments on commit f1bd1e7

Please sign in to comment.