Refactored job manager tests

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

- A little cleanup before adding more edge case handling
This commit is contained in:
Naz 2022-07-28 17:30:21 +01:00
parent ee243f9ea3
commit 3092b62e10

View File

@ -12,6 +12,15 @@ const JobManager = require('../index');
const sandbox = sinon.createSandbox();
const jobModelInstance = {
id: 'unique',
get: (field) => {
if (field === 'status') {
return 'finished';
}
}
};
describe('Job Manager', function () {
beforeEach(function () {
sandbox.stub(logging, 'info');
@ -290,7 +299,7 @@ describe('Job Manager', function () {
it('does not add a job to the queue when it already exists', async function () {
const spy = sinon.spy();
const JobModel = {
findOne: sinon.stub().resolves({name: 'I am the only one'}),
findOne: sinon.stub().resolves(jobModelInstance),
add: sinon.stub().throws('should not be called')
};
@ -404,7 +413,7 @@ describe('Job Manager', function () {
it('does not add a job to the queue when it already exists', async function () {
const spy = sinon.spy();
const JobModel = {
findOne: sinon.stub().resolves({name: 'I am the only one'}),
findOne: sinon.stub().resolves(jobModelInstance),
add: sinon.stub().throws('should not be called')
};
@ -463,7 +472,7 @@ describe('Job Manager', function () {
findOne: sinon.stub()
.onCall(0)
.resolves(null)
.resolves({id: 'unique', name: 'failed-oneoff'}),
.resolves(jobModelInstance),
add: sinon.stub().resolves({name: 'failed-oneoff'}),
edit: sinon.stub().resolves({name: 'failed-oneoff'})
};