Made URL class warn on duplicate URLs in the test suite

refs: https://github.com/TryGhost/Toolbox/issues/389

Instead of logging errors, this will warn when adding a duplicate URL in the test environment.

At the moment, this is happening a lot in the test suite. While we also need to fix the root cause of this so we're not erroring in the product, it's a massive amount of spam in the logs when running the test suite which could prevent us from finding other errors which are causing issues.
This commit is contained in:
Sam Lord 2023-03-03 18:13:33 +00:00
parent 13b0f51b13
commit 472e52a536
2 changed files with 10 additions and 4 deletions

View File

@ -44,10 +44,18 @@ class Urls {
debug('cache', url);
if (this.urls[resource.data.id]) {
logging.error(new errors.InternalServerError({
const error = new errors.InternalServerError({
message: 'This should not happen.',
code: 'URLSERVICE_RESOURCE_DUPLICATE'
}));
});
if (process.env.NODE_ENV.startsWith('test')) {
logging.warn({
message: 'Duplicate URL',
err: error
});
} else {
logging.error(error);
}
this.removeResourceId(resource.data.id);
}

View File

@ -84,8 +84,6 @@ describe('Unit: services/url/Urls', function () {
},
generatorId: 1
});
loggingStub.calledOnce.should.eql(true);
loggingStub.firstCall.firstArg.should.have.property('code').eql('URLSERVICE_RESOURCE_DUPLICATE');
should.exist(eventsToRemember['url.added']);