Commit 265cd582 authored by Maxime Chaillet's avatar Maxime Chaillet

Use sessionDate and publication year to infere the publication date. Fix bug...

Use sessionDate and publication year to infere the publication date. Fix bug regarding the display of publication year. write tests. It fixes #68.
parent 59838ab0
......@@ -20,11 +20,13 @@ module.exports = function (config) {
'src/constants.js',
'src/doicontroller.js',
'src/doiview.js',
'src/doiData.js',
'src/experimentalreportcontroller.js',
'src/event.js',
'src/jsonextractor.js',
'tests/jsonExtractor.test.js',
'tests/doiController.test.js',
'tests/doiData.test.js',
'bower_components/lodash/lodash.js',
'bower_components/moment/moment.js'
......
This diff is collapsed.
This diff is collapsed.
function DoiData(doi, dataciteLink, publisher, creator, publication_year) {
this.doi = doi;
this.dataciteLink = dataciteLink;
this.publisher = publisher;
this.creator = creator;
this.publiclyAccessibleYear = publication_year;
function DoiData() {
}
/**
......@@ -20,7 +15,8 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate,
if (resourceType) {
if (resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
if (publiclyAccessibleYear && sessionDate) {
var publiclyAvailableDate = moment(publiclyAccessibleYear, "YYYY");
// take day and month of sessionDate and year of publiclyAccessibleYear
var publiclyAvailableDate = moment(sessionDate).year(parseInt(publiclyAccessibleYear));
var now = moment();
if (now > publiclyAvailableDate) {
......@@ -29,7 +25,7 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate,
return "Restricted access";
}
}
} else if (resourceType === CONSTANTS.DC_RESOURCE_TYPE){
} else if (resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
return "Open access";
}
}
......
......@@ -40,10 +40,7 @@ DOIController.prototype.render = function (doi, data) {
} else {
// Extract data and fill doiData with it
var doiData = new DoiData();
// var doiData = new DoiData(data.doi.toUpperCase(), _this.doiServer + doi, data.publisher, data.creator, data.publication_year);
var jsonExtractor = new JsonExtractor();
doiData.title = jsonExtractor.getTitle(data);
......@@ -53,6 +50,8 @@ DOIController.prototype.render = function (doi, data) {
doiData.creators = jsonExtractor.getCreators(data);
doiData.publiclyAccessibleYear = jsonExtractor.getPubliclyAccessibleYear(data);
console.log(doiData.publiclyAccessibleYear );
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.getInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data);
......
......@@ -17,11 +17,11 @@
<div class="col-6 col-md">
<div class="myBorder-left">
<label> Publication year </label>
{?data.mintingYear}
<div class="padding-left-15">{data.mintingYear}</div>
{?data.publiclyAccessibleYear}
<div class="padding-left-15">{data.publiclyAccessibleYear}</div>
{:else}
<div class="padding-left-15"> Not available</div>
{/data.mintingYear}
{/data.publiclyAccessibleYear}
</div>
</div>
......
describe('DoiData', () => {
describe('getAccessibilityStatus', () => {
it('Returns open access when today is after publication date', () => {
let doiData = new DoiData();
let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE;
let actualSessionDate = "2017-01-01"
let actualPubliclyAccessibleYear = "2018"
expect(doiData.getAccessibilityStatus(actualReourceType, actualSessionDate, actualPubliclyAccessibleYear)).toEqual("Open access");
})
it('Returns Restricted access when today is before publication date', () => {
let doiData = new DoiData();
let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE;
let actualSessionDate = "2017-01-01"
let actualPubliclyAccessibleYear = "2020"
expect(doiData.getAccessibilityStatus(actualReourceType, actualSessionDate, actualPubliclyAccessibleYear)).toEqual("Restricted access");
})
})
})
\ No newline at end of file
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