From 2acd55af47db84a83077a311f46f07070a7fc0c7 Mon Sep 17 00:00:00 2001 From: Andrew Brazzatti Date: Tue, 21 May 2024 03:13:08 +0000 Subject: [PATCH] Added env var option for DOI tests to be able to easily disable it in the CI environment when there are issues with Fabrica --- test/unit/services/DOIService.test.js | 148 +++++++++++++------------- 1 file changed, 76 insertions(+), 72 deletions(-) diff --git a/test/unit/services/DOIService.test.js b/test/unit/services/DOIService.test.js index eef428b7e8..fae9e47eb0 100644 --- a/test/unit/services/DOIService.test.js +++ b/test/unit/services/DOIService.test.js @@ -1,34 +1,38 @@ describe('The DOI Service', function () { before(function (done) { if ( - !sails.config.datacite.username || - !sails.config.datacite.password || - !sails.config.datacite.doiPrefix + !sails.config.datacite.username || + !sails.config.datacite.password || + !sails.config.datacite.doiPrefix ) { this.skip(); } else { - done(); + if (process.env.SKIP_DOI_TESTS === 'true') { + this.skip(); + } else { + done(); + } } }); - let createdDoi = null - let oid = "xxxxxxxxx"; - let record = { - metadata: { - citation_publication_date: '2021', - citation_title: 'New Test Publication', - citation_publisher: 'Research Labs GMBH', - creators: [{ - given_name: "Test", - family_name: "Researcher" - }, - { - given_name: "Test", - family_name: "Student" - } - ] - } - } + let createdDoi = null + let oid = "xxxxxxxxx"; + let record = { + metadata: { + citation_publication_date: '2021', + citation_title: 'New Test Publication', + citation_publisher: 'Research Labs GMBH', + creators: [{ + given_name: "Test", + family_name: "Researcher" + }, + { + given_name: "Test", + family_name: "Student" + } + ] + } + } it("Should create a DOI", function (done) { this.timeout(25000); @@ -74,58 +78,58 @@ describe('The DOI Service', function () { }); }); - it("Should create a draft DOI", function (done) { - this.timeout(25000); - sails.services.doiservice.publishDoi(oid, record, 'draft').then(result => { - sails.log.debug("DOI result: ") - sails.log.debug(result) - expect(result).to.not.be.null; - createdDoi = result - done() - }).catch(error => { - fail("Exception thrown"); - sails.log.error(error); - done(); - }); - }); + it("Should create a draft DOI", function (done) { + this.timeout(25000); + sails.services.doiservice.publishDoi(oid, record, 'draft').then(result => { + sails.log.debug("DOI result: ") + sails.log.debug(result) + expect(result).to.not.be.null; + createdDoi = result + done() + }).catch(error => { + fail("Exception thrown"); + sails.log.error(error); + done(); + }); + }); - it("Should register a DOI", function (done) { - this.timeout(25000); - sails.log.debug("Registering the created DOI: " + createdDoi) - sails.services.doiservice.changeDoiState(createdDoi,'register').then(result => { - expect(result).to.eq(true) - done() - }).catch(error => { - fail("Exception thrown"); - sails.log.error(error); - done(); - }); - }); + it("Should register a DOI", function (done) { + this.timeout(25000); + sails.log.debug("Registering the created DOI: " + createdDoi) + sails.services.doiservice.changeDoiState(createdDoi, 'register').then(result => { + expect(result).to.eq(true) + done() + }).catch(error => { + fail("Exception thrown"); + sails.log.error(error); + done(); + }); + }); - it("Should publish a DOI", function (done) { - this.timeout(25000); - sails.log.debug("Publishing the registered DOI: " + createdDoi) - sails.services.doiservice.changeDoiState(createdDoi,'publish').then(result => { - expect(result).to.eq(true) - done() - }).catch(error => { - fail("Exception thrown"); - sails.log.error(error); - done(); - }); - }); + it("Should publish a DOI", function (done) { + this.timeout(25000); + sails.log.debug("Publishing the registered DOI: " + createdDoi) + sails.services.doiservice.changeDoiState(createdDoi, 'publish').then(result => { + expect(result).to.eq(true) + done() + }).catch(error => { + fail("Exception thrown"); + sails.log.error(error); + done(); + }); + }); - it("Should hide a DOI", function (done) { - this.timeout(25000); - sails.log.debug("Hiding the published DOI: " + createdDoi) - sails.services.doiservice.changeDoiState(createdDoi,'hide').then(result => { - expect(result).to.eq(true) - done() - }).catch(error => { - fail("Exception thrown"); - sails.log.error(error); - done(); - }); - }); + it("Should hide a DOI", function (done) { + this.timeout(25000); + sails.log.debug("Hiding the published DOI: " + createdDoi) + sails.services.doiservice.changeDoiState(createdDoi, 'hide').then(result => { + expect(result).to.eq(true) + done() + }).catch(error => { + fail("Exception thrown"); + sails.log.error(error); + done(); + }); + }); });