GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 91e54142 authored by Maxime Chaillet's avatar Maxime Chaillet

Remove warnings from the console. It fixes icat/doi-landing-page#65.

parent fe6686c3
......@@ -28,7 +28,7 @@
"watchify": "^3.11.0"
},
"scripts": {
"test": "./node_modules/jest/bin/jest.js"
"test": "karma start"
},
"repository": {
"type": "git",
......
......@@ -17,14 +17,9 @@ function Citation(doiData) {
}
/**
* Construct the author list for the citation. Authors name are composed of the
* familyName in titleCase followed by the first letter of the first name
*
* @param {arrayOrObj}
* The creator(s). When there is a single author, it is an
* object. When there are several authors, it is an array.
* @return {string} The formated list of authors to be used for the citation. An
* empty string when the list could not be generated.
* Construct the author list for the citation. Authors name are composed of the familyName in titleCase followed by the first letter of the first name
* @param {arrayOrObj} theCreator(s). When there is a single author, it is an object. When there are several authors, it is an array.
* @return {string} The formated list of authors to be used for the citation. An empty string when the list could not be generated.
*/
Citation.prototype.getAuthorsForCitation = function (creator) {
if (this.isBuildable) {
......@@ -67,6 +62,11 @@ Citation.prototype.getAuthorsForCitation = function (creator) {
}
};
/**
* Get the DOI registration year
* @param doiData doimetadata as constructed by the json exctrator
* @returns registration year. Empty string when t is not available.
*/
Citation.prototype.getDOIRegistrationYear = function (doiData) {
if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
return moment(doiData.sessionDate).year();
......
......@@ -177,8 +177,9 @@ DOIController.prototype.getDataForGoogleSearch = function (doi) {
success: function (data) {
if (data) {
_this.view.addDOIMetadataToHead(data);
} else{
console.log("[GOOGLE SEARCH INDEXING] - No metadata recieved from datacite.");
}
console.log("[GOOGLE SEARCH INDEXING] - No metadata recieved from datacite.");
},
error: function (error) {
console.log("[GOOGLE SEARCH INDEXING] - Failed getting metadata from datacite.");
......
......@@ -149,6 +149,8 @@ DOIView.prototype.renderBadges = function (data) {
DOIView.prototype.renderMetadata = function (data) {
if (data) {
var _this = this;
data.sessionDate = moment(data.sessionDate).format('YYYY-M-D');
dust.render('metadata_tpl', {
data: data,
constants: CONSTANTS
......
......@@ -107,19 +107,6 @@ JsonExtractor.prototype.getInvestigationId = function (data) {
return null;
};
/**
* Extract field value (beamline, proposal number and proposal type) from the
* data json object. Returns null if the field is not found.
......@@ -168,12 +155,11 @@ JsonExtractor.prototype.getSessionDate = function (data) {
var sessionDate = _.find(data.dates, function (item) {
if (item.dateType) {
return item.dateType.toLowerCase() === "collected";
}
});
if (sessionDate && sessionDate.date) {
return moment(sessionDate.date).format('YYYY-M-D');
return moment(sessionDate.date).format('YYYY-MM-DD');
}
}
}
......
import Citation from '../src/citation';
describe('citation', () => {
describe('getDOIRegistrationYear', () => {
it('Returns the year for experimental session', () => {
let actualDoiData = {
resourceType: "experimental session resource type",
sessionDate="2017-12-31",
publiclyAccessibleYear = "2018"
};
let expectedYear = 2017;
let myCitation = new Citation();
expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual(expectedYear);
})
it('Returns the year for datacollection session', () => {
// thre is no sessionDate for this kind of DOI
let actualDoiData = {
resourceType: "dataset collection resource type",
publiclyAccessibleYear = "2018"
};
let expectedYear = 2018;
let myCitation = new Citation();
expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual(expectedYear);
})
it('Returns an empty string when sessionDate is not provided', () => {
let actualDoiData = {
};
let expectedYear = "";
let myCitation = new Citation();
expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual(expectedYear);
})
})
})
\ No newline at end of file
......@@ -116,7 +116,7 @@ describe("jsonExtractor", () => {
describe('getSessionDate', () => {
it("returns the session date when the doi resource type is 'experiment session'", () => {
let actualDoiData = require('./resources/doi_ES.js')
let expectedSessionDate = moment('2018-03-26').format('YYYY-M-D');
let expectedSessionDate = '2018-03-26';
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getSessionDate(actualDoiData)).toEqual(expectedSessionDate);
......
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