Skip to content

Commit

Permalink
added navigator tests for orcid redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
aholachek committed Dec 18, 2015
1 parent 1b9d869 commit 47dce0c
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 60 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,14 @@ module.exports = function(grunt) {
'http://localhost:<%= local.port || 8000 %>/test/mocha/coverage.html?bbbSuite=discovery-suite'
],
threshold : 0,
globalThreshold : 77,
globalThreshold : 75,
log : true,
logErrors: true,
moduleThreshold : 80,
modulePattern : "../../js/(.*)",
customModuleThreshold: {

"apps/discovery/navigator.js": 20,
"widgets/alerts/widget.js" : 73,
"apps/discovery/router.js": 39,
"widgets/facet/graph-facet/h_index_graph.js":2,
Expand Down
23 changes: 12 additions & 11 deletions src/js/apps/discovery/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,14 @@ define([
this.set('orcid-page', function(view, targetRoute) {

var orcidApi = app.getService('OrcidApi');
var storage = app.getService('PersistentStorage');
var persistentStorage = app.getService('PersistentStorage');
var appStorage = app.getObject('AppStorage');

// traffic from Orcid - user has authorized our access
if (orcidApi.hasExchangeCode() && !orcidApi.hasAccess()) {
if (!orcidApi.hasAccess() && orcidApi.hasExchangeCode()) {
//since app will exit, store the information that we're authenticating
if (storage){
storage.set("orcidAuthenticating", true);
if (persistentStorage){
persistentStorage.set("orcidAuthenticating", true);
}
else {
console.warn("no persistent storage service available");
Expand Down Expand Up @@ -589,19 +590,20 @@ define([

if (orcidApi.hasAccess()) {

if (storage.get("orcidAuthenticating")){
if (persistentStorage.get("orcidAuthenticating")){

storage.remove("orcidAuthenticating");
persistentStorage.remove("orcidAuthenticating");
// check if we need to trigger modal alert to ask user to fill in necessary data
//we only want to show this immediately after user has authenticated with orcid
orcidApi.getADSUserData().done(function (data) {
if (!data.hasOwnProperty("authorizedUser")) {
//don't show modal if we're just going to redirect to the ads-orcid form anyway
if (!data.hasOwnProperty("authorizedUser") && JSON.stringify(appStorage.get("stashedNav")) !== '["UserPreferences",{"subView":"orcid"}]') {
//the form has yet to be filled out by the user
//now tailor the message depending on whether they are signed in to ADS or not
var alerter = app.getController('AlertsController');
alerter.alert(new ApiFeedback({
code: ApiFeedback.CODES.ALERT,
msg: OrcidModalTemplate({adsLoggedIn: self.getBeeHive().getObject("User").isLoggedIn()}),
msg: OrcidModalTemplate({adsLoggedIn: app.getObject("User").isLoggedIn()}),
type: "success",
title: "You are now logged in to ORCID",
modal: true
Expand All @@ -613,14 +615,13 @@ define([
});
}
//should we redirect back to a certain page now that orcid is authenticated?
var appStorage = self.getBeeHive().getObject('AppStorage');
//the stashed nav in question currently would only belong to orcid form on user page
//calling this function executes it
if (!appStorage.executeStashedNav()) {
//go to the orcidbigwidget
this.route = '#user/orcid';
app.getWidget('OrcidBigWidget').done(function (orcidWidget) {
app.getObject('MasterPageManager').show('OrcidPage',
['OrcidBigWidget', 'SearchWidget']);
});
}
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/js/apps/discovery/templates/orcid-modal-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{{#if adsLoggedIn}}

<p>
If you <strong>wish for your ORCID claims to be accessible in the ADS,</strong> please
<br><br> <a href="#user/settings/orcid">fill out this brief form. </a> <br><br>
If you <strong>wish for your ORCID claims to be accessible in the ADS,</strong> please first
<a href="#user/settings/orcid">fill out this brief form. </a>
</p>

<p>
Expand Down
1 change: 1 addition & 0 deletions test/mocha/core-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ define([], function() {

var tests = [
'/apps/discovery/router.spec.js',
'/apps/discovery/navigator.spec.js',

'/components/app_storage.spec.js',
'/components/csrf_manager.spec.js',
Expand Down
164 changes: 164 additions & 0 deletions test/mocha/js/apps/discovery/navigator.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
define([
'js/apps/discovery/navigator',
'js/bugutils/minimal_pubsub',
'js/components/api_feedback',
], function(
Navigator,
Minsub,
ApiFeedback
){

describe("Navigator", function(){

it("should handle the orcid endpoint and authenticating if code is provided", function(){

var n = new Navigator();

var minsub = new Minsub();

//fake Services

var orcidApi = {
//only testing after orcid access has been provided
hasAccess : function(){
return true
},
getADSUserData : function(){
var d = $.Deferred();
//pretending user hasnt filled in data yet
d.resolve({});
return d.promise();
}
};
var storage = {
get : function(val){
if (val == "orcidAuthenticating"){
return true;
}
},
remove : sinon.spy(function(val){
})
};

var appStorage = {
executeStashedNav : sinon.spy(function(){
return true;
}),

get : function(a){
if (a == "stashedNav") return ["UserPreferences", {"subView":"orcid"}];
}
};

var AlertsController = {
alert : sinon.spy()
};

var MasterPageManager = {
show: sinon.spy(function () {
})
};

var app = {

getService: function (obj) {
if (obj == "OrcidApi") {
return orcidApi
}
else if (obj == "PersistentStorage") {
return storage
}
},
getObject: function (obj) {
if (obj == "AppStorage") {
return appStorage;
}
else if (obj == "User") {
return {
isLoggedIn: function () {
return true
}
}
}
else if (obj === "MasterPageManager") {
return MasterPageManager;
}
},

getController: function (obj) {
if (obj == "AlertsController") {
return AlertsController
}
},

getWidget : function(obj){
if (obj === "OrcidBigWidget"){
return sinon.spy(function(){
var d = $.Deferred();
d.resolve();
return d;
})
}
}
};


n.start(app);

//1. dont show the modal

// n.catalog.get("orcid-page").execute();
//
// //remove this flag that lets us know to show a special modal when user goes to #orcid-page
// expect(storage.remove.args[0][0]).to.eql("orcidAuthenticating");
//
// //modal wasn't called
// expect(AlertsController.alert.callCount).to.eql(0);
//
// //executestashednav returned true
// expect( n.catalog.get("orcid-page").route).to.be.false;
//
//expect(MasterPageManager.show.callCount).to.eql(0);

//2. show the modal and redirect to orcidbigwidget

var appStorage = {
executeStashedNav : sinon.spy(function(){
return false;
}),

get : function(a){
if (a == "stashedNav") return undefined;
}
};

n.catalog.get("orcid-page").execute();

expect(AlertsController.alert.callCount).to.eql(1);
expect(AlertsController.alert.args[0][0]).to.be.instanceof(ApiFeedback);
expect(AlertsController.alert.args[0][0].title).to.eql("You are now logged in to ORCID");

//remove this flag that lets us know to show a special modal when user goes to #orcid-page
expect(storage.remove.args[0][0]).to.eql("orcidAuthenticating");

//executestashednav returned true
expect( n.catalog.get("orcid-page").route).to.eql("#user/orcid");

expect(MasterPageManager.show.callCount).to.eql(1);

expect(MasterPageManager.show.args[0][0]).to.eql("OrcidPage");








});



});

});
3 changes: 0 additions & 3 deletions test/mocha/js/apps/discovery/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ define([
]
});


fakePubSub.publish(fakePubSub.pubSubKey, fakePubSub.NAVIGATE, "results-page");

expect(fakePubSub.publish.args[2][1]).to.eql("[Router]-Navigate-With-Trigger");
expect(fakePubSub.publish.args[2][2]).to.eql("show-metrics");



})


Expand Down
25 changes: 0 additions & 25 deletions test/mocha/js/apps/todo/app.spec.js

This file was deleted.

18 changes: 0 additions & 18 deletions test/mocha/js/apps/todo/router.spec.js

This file was deleted.

0 comments on commit 47dce0c

Please sign in to comment.