Commit 459a58d1 authored by Maxime Chaillet's avatar Maxime Chaillet

install jest for tests

parent 08d84431
{
"name": "doi-landing-page",
"version": "0.0.0",
"description": "",
"main": "Gruntfile.js",
"dependencies": {
"grunt": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^3.2.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-dust": "^0.9.4",
"grunt-dustjs": "^1.4.0",
"grunt-wiredep": "^3.0.1"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-include-source": "^1.1.0",
"grunt-plato": "^1.4.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@gitlab.esrf.fr:icat/doi-landing-page.git"
},
"author": "",
"license": "ISC"
}
"name": "doi-landing-page",
"jest": {
"rootDir": "tests"
},
"version": "0.0.0",
"description": "",
"main": "Gruntfile.js",
"dependencies": {
"grunt": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^3.2.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-dust": "^0.9.4",
"grunt-dustjs": "^1.4.0",
"grunt-wiredep": "^3.0.1"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-include-source": "^1.1.0",
"grunt-plato": "^1.4.0",
"jest": "^23.6.0"
},
"scripts": {
"test": "jest --watchAll"
},
"repository": {
"type": "git",
"url": "git@gitlab.esrf.fr:icat/doi-landing-page.git"
},
"author": "",
"license": "ISC"
}
\ No newline at end of file
function DOIController(view) {
var _this = this;
// doiServer = the server which provides doi details from a given doi name.
this.doiServer = "https://data.datacite.org/";
//this.doiServer = "https://data.datacite.org/";
this.doiServer = "https://api.test.datacite.org/"
// 10.5072 is the test esrf doi prefix;
// 10.15151 is the production esrf doi prefix;
......@@ -48,8 +50,9 @@ DOIController.prototype.getData = function(doi) {
timeout : 15000, // triggers timeout when request pends longer than
// 5000ms
url : this.doiServer + doi,
beforeSend : function() {
beforeSend : function(xhr) {
_this.view.setLoading("Retrieving data from Server");
xhr.setRequestHeader ("Authorization", "Basic " + btoa("DATACITE.ESRF" + ":" + "datacyte1")); // to be removed as well as the parameter
},
complete : function() {
_this.view.setLoading(false);
......
function JsonExtractor( json ) {
function JsonExtractor(json) {
}
/**
......@@ -10,26 +11,26 @@ function JsonExtractor( json ) {
* @return {string}
* investigationId The investigationID requested for accessing data in ICAT.
*/
JsonExtractor.prototype.extractInvestigationId = function( data ) {
var regExp = RegExp( /\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/ );
return regExp.exec( data.doi )[1];
JsonExtractor.prototype.extractInvestigationId = function (data) {
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
//return regExp.exec( data.doi )[1];
return "investigationId"
};
/**
* Extract field value (beamline, proposal number and proposal type) from the
* data json object. Returns null if the field is not found.
*
* @param {array}
* subject The array containing objects of interest template
* @param {string}
* field The text field which is searched
* @param {array} subject The array containing objects of interest template
* @param {string} field The text field which is searched
* @returns {array} the found field in an array. When the field is string composed of coma separated items, each item is returned in the array. When there is no text, an empty array is returned
*/
JsonExtractor.prototype.getFieldFromSubject = function( subject, field ) {
if ( subject ) {
if ( subject[0] ) {
for ( var i = 0; i < subject[0].length; i++ ) {
if ( subject[0][i].subject_scheme === field ) {
return subject[0][i].text;
JsonExtractor.prototype.getFieldFromSubject = function (subject, field) {
if (subject) {
if (subject[0]) {
for (var i = 0; i < subject[0].length; i++) {
if (subject[0][i].subject_scheme === field) {
return _.split(subject[0][i].text, ',');
}
}
}
......@@ -45,10 +46,10 @@ JsonExtractor.prototype.getFieldFromSubject = function( subject, field ) {
* @return {string}
* The minting year. Null if it does not exist.
*/
JsonExtractor.prototype.getMintingYear = function( data ) {
if ( data ) {
if ( data.date_registered && data.date_registered != null ) {
return moment( data.date_registered ).year();
JsonExtractor.prototype.getMintingYear = function (data) {
if (data) {
if (data.date_registered && data.date_registered != null) {
return moment(data.date_registered).year();
}
}
return null;
......@@ -62,10 +63,10 @@ JsonExtractor.prototype.getMintingYear = function( data ) {
* @return {string}
* The formatted (YYY-M-D) session date. Null if it does not exist.
*/
JsonExtractor.prototype.getSessionDate = function( data ) {
if ( data ) {
if ( data.date_collected && data.date_collected != null ) {
return moment( data.date_collected ).format( 'YYYY-M-D' );
JsonExtractor.prototype.getSessionDate = function (data) {
if (data) {
if (data.date_collected && data.date_collected != null) {
return moment(data.date_collected).format('YYYY-M-D');
}
}
return null;
......@@ -79,8 +80,8 @@ JsonExtractor.prototype.getSessionDate = function( data ) {
* @return {string}
* The resource tyoe general. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceTypeGeneral = function( data ) {
if ( data && data.resource_type_general ) {
JsonExtractor.prototype.getResourceTypeGeneral = function (data) {
if (data && data.resource_type_general) {
return data.resource_type_general;
}
return null;
......@@ -93,8 +94,8 @@ JsonExtractor.prototype.getResourceTypeGeneral = function( data ) {
* @return {string}
* The resource tyoe. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceType = function( data ) {
if ( data && data.resource_type ) {
JsonExtractor.prototype.getResourceType = function (data) {
if (data && data.resource_type) {
return data.resource_type;
}
return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment