Commit ccca407b authored by Maxime Chaillet's avatar Maxime Chaillet

Merge branch 'issue77' into 'master'

Issue77

Closes #77

See merge request !96
parents ef85b091 073eafdc
Pipeline #14578 passed with stages
in 46 seconds
......@@ -3,17 +3,13 @@
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'browserify'],
// list of files / patterns to load in the browser
files: [
'src/beamlineurl.js',
......@@ -24,53 +20,48 @@ module.exports = function (config) {
'src/experimentalreportcontroller.js',
'src/event.js',
'src/jsonextractor.js',
'src/googleMetadataObject.js',
'tests/jsonExtractor.test.js',
'tests/doiController.test.js',
'tests/doiData.test.js',
'tests/googleMetadataObject.test.js',
'bower_components/lodash/lodash.js',
'bower_components/moment/moment.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'tests/jsonExtractor.test.js': ['browserify']
'tests/jsonExtractor.test.js': ['browserify'],
'tests/googleMetadataObject.test.js': ['browserify']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox', 'Chrome'],
//browsers: ['Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
......
......@@ -172,15 +172,11 @@ DOIController.prototype.getDataForGoogleSearch = function (doi) {
//dataType: 'text', // don't convert JSON to Javascript object
success: function (data) {
if (data) {
// Here we add the 'description' field in the recieved object because 'name' and 'description' fields are required by google dataset search.
if (data.name) {
if (!data.description) {
data.description = data.name;
}
_this.view.addDOIMetadataToHead(JSON.stringify(data));
} else {
console.log("[GOOGLE SEARCH INDEXING] - The data required by Google is missing the 'name' field. This is required by Google for indexing.");
}
googleMetadataObject = new GoogleMetadataObject(data);
googleMetadataObject.setDescription();
googleMetadataObject.setLicense();
_this.view.addDOIMetadataToHead(JSON.stringify(googleMetadataObject.getMetadata()));
} else {
console.log("[GOOGLE SEARCH INDEXING] - No metadata recieved from datacite.");
}
......
/**
* This class corresponds to a Google metadata object
* @param {*} data
*/
function GoogleMetadataObject(data) {
this.data = JSON.parse(JSON.stringify(data)); //creates a copy of the data object
}
/**
* Get metadata
*/
GoogleMetadataObject.prototype.getMetadata = function () {
return this.data;
}
/**
* Set a license
*/
GoogleMetadataObject.prototype.setLicense = function () {
if (!this.data.license) {
this.data.license = "https://creativecommons.org/licenses/by/4.0"
}
}
/**
* Set a description.
*/
GoogleMetadataObject.prototype.setDescription = function () {
if (this.data.name) {
if (!this.data.description) {
this.data.description = this.data.name;
}
} else {
console.log("[GoogleMetadataObject] - The data required by Google is missing the 'name' field. This is required by Google for indexing.");
}
}
\ No newline at end of file
require('it-each')({ testPerIteration: true });
let resources = require('./resources/googleMetadataObject.resource');
describe("googleMetadataObject unit tests", () => {
describe("initialization", () => {
it.each(resources.initialization, '[initialization: %s ]', ['aboutThisTest'],
function (element, next) {
let gmo = new GoogleMetadataObject(element.data);
expect(gmo.getMetadata()).toEqual(element.expected);
next();
})
})
describe("setLicense", () => {
it.each(resources.setLicense, '[setLicense: %s ]', ['aboutThisTest'],
function (element, next) {
let gmo = new GoogleMetadataObject(element.data);
gmo.setLicense();
expect(gmo.getMetadata()).toEqual(element.expected);
next();
})
})
describe("setDescription", () => {
it.each(resources.setDescription, '[setDescription: %s ]', ['aboutThisTest'],
function (element, next) {
let gmo = new GoogleMetadataObject(element.data);
gmo.setDescription();
expect(gmo.getMetadata()).toEqual(element.expected);
next();
})
})
})
\ No newline at end of file
module.exports = {
googleMetadata1: {
"@context": "http://schema.org",
"@type": "Dataset",
"@id": "https://doi.org/10.15151/esrf-es-47877949",
"identifier": {
"@type": "PropertyValue",
"propertyID": "DOI",
"value": "https://doi.org/10.15151/esrf-es-47877949"
},
"url": "https://doi.esrf.fr/10.15151/ESRF-ES-47877949",
"additionalType": "Experiment Session",
"name": "Nanoscopic Metal Composition of Phagosomal Compartments during Engulfment of E. coli by Professional Phagocytes.",
"author": [
{
"name": "Björn DE SAMBER",
"givenName": "Björn DE",
"familyName": "SAMBER",
"@type": "Person"
},
{
"name": "Constantin URBAN",
"givenName": "Constantin",
"familyName": "URBAN",
"@type": "Person"
},
{
"name": "Bart VEKEMANS",
"givenName": "Bart",
"familyName": "VEKEMANS",
"@type": "Person"
},
{
"name": "Gerald FALKENBERG",
"givenName": "Gerald",
"familyName": "FALKENBERG",
"@type": "Person"
},
{
"name": "Ella DE PAUW",
"givenName": "Ella DE",
"familyName": "PAUW",
"@type": "Person"
}
],
"keywords": "Life Sciences, LS-2550, id16a",
"inLanguage": "eng",
"datePublished": "2020",
"schemaVersion": "http://datacite.org/schema/kernel-3",
"publisher": {
"@type": "Organization",
"name": "European Synchrotron Radiation Facility"
},
"provider": {
"@type": "Organization",
"name": "DataCite"
}
}
}
\ No newline at end of file
let library = require('./googleMetadataLibrary.resource');
module.exports = {
initialization: [
{
aboutThisTest: 'initialization',
data: library.googleMetadata1,
expected: library.googleMetadata1
}
],
setLicense: [
{
aboutThisTest: 'it sets the expected license',
data: library.googleMetadata1,
expected: {
"@context": "http://schema.org",
"@type": "Dataset",
"@id": "https://doi.org/10.15151/esrf-es-47877949",
"identifier": {
"@type": "PropertyValue",
"propertyID": "DOI",
"value": "https://doi.org/10.15151/esrf-es-47877949"
},
"url": "https://doi.esrf.fr/10.15151/ESRF-ES-47877949",
"additionalType": "Experiment Session",
"name": "Nanoscopic Metal Composition of Phagosomal Compartments during Engulfment of E. coli by Professional Phagocytes.",
"author": [
{
"name": "Björn DE SAMBER",
"givenName": "Björn DE",
"familyName": "SAMBER",
"@type": "Person"
},
{
"name": "Constantin URBAN",
"givenName": "Constantin",
"familyName": "URBAN",
"@type": "Person"
},
{
"name": "Bart VEKEMANS",
"givenName": "Bart",
"familyName": "VEKEMANS",
"@type": "Person"
},
{
"name": "Gerald FALKENBERG",
"givenName": "Gerald",
"familyName": "FALKENBERG",
"@type": "Person"
},
{
"name": "Ella DE PAUW",
"givenName": "Ella DE",
"familyName": "PAUW",
"@type": "Person"
}
],
"keywords": "Life Sciences, LS-2550, id16a",
"inLanguage": "eng",
"datePublished": "2020",
"schemaVersion": "http://datacite.org/schema/kernel-3",
"publisher": {
"@type": "Organization",
"name": "European Synchrotron Radiation Facility"
},
"provider": {
"@type": "Organization",
"name": "DataCite"
},
"license": "https://creativecommons.org/licenses/by/4.0"
}
}
],
setDescription: [
{
aboutThisTest: 'description is a copy of the name',
data: library.googleMetadata1,
expected: {
"@context": "http://schema.org",
"@type": "Dataset",
"@id": "https://doi.org/10.15151/esrf-es-47877949",
"identifier": {
"@type": "PropertyValue",
"propertyID": "DOI",
"value": "https://doi.org/10.15151/esrf-es-47877949"
},
"url": "https://doi.esrf.fr/10.15151/ESRF-ES-47877949",
"additionalType": "Experiment Session",
"name": "Nanoscopic Metal Composition of Phagosomal Compartments during Engulfment of E. coli by Professional Phagocytes.",
"author": [
{
"name": "Björn DE SAMBER",
"givenName": "Björn DE",
"familyName": "SAMBER",
"@type": "Person"
},
{
"name": "Constantin URBAN",
"givenName": "Constantin",
"familyName": "URBAN",
"@type": "Person"
},
{
"name": "Bart VEKEMANS",
"givenName": "Bart",
"familyName": "VEKEMANS",
"@type": "Person"
},
{
"name": "Gerald FALKENBERG",
"givenName": "Gerald",
"familyName": "FALKENBERG",
"@type": "Person"
},
{
"name": "Ella DE PAUW",
"givenName": "Ella DE",
"familyName": "PAUW",
"@type": "Person"
}
],
"keywords": "Life Sciences, LS-2550, id16a",
"inLanguage": "eng",
"datePublished": "2020",
"schemaVersion": "http://datacite.org/schema/kernel-3",
"publisher": {
"@type": "Organization",
"name": "European Synchrotron Radiation Facility"
},
"provider": {
"@type": "Organization",
"name": "DataCite"
},
"description": "Nanoscopic Metal Composition of Phagosomal Compartments during Engulfment of E. coli by Professional Phagocytes.",
}
}
]
};
\ 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