update toJSON, add tests, remove unused var
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import events from 'events';
|
||||
import { isPlainObject } from 'lodash';
|
||||
import { omit, values } from 'lodash';
|
||||
import { omit } from 'lodash';
|
||||
import logger from './helpers/logger';
|
||||
import { jobStatuses } from './helpers/constants';
|
||||
import createIndex from './helpers/create_index';
|
||||
@@ -80,7 +80,7 @@ export default class Job extends events.EventEmitter {
|
||||
type: this.type,
|
||||
payload: this.payload,
|
||||
timeout: this.timeout,
|
||||
maxAttempts: this.maxAttempts,
|
||||
max_attempts: this.maxAttempts,
|
||||
priority: this.priority,
|
||||
}, omit(this.document, ['version']));
|
||||
}
|
||||
|
||||
@@ -148,11 +148,6 @@ describe('Job Class', function () {
|
||||
beforeEach(function () {
|
||||
type = 'type2';
|
||||
payload = { id: '123' };
|
||||
options = {
|
||||
timeout: 4567,
|
||||
max_attempts: 9,
|
||||
};
|
||||
sinon.spy(client, 'index');
|
||||
});
|
||||
|
||||
it('should return the job document', function () {
|
||||
@@ -171,4 +166,37 @@ describe('Job Class', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('toJSON method', function () {
|
||||
beforeEach(function () {
|
||||
type = 'type2';
|
||||
payload = { id: '123' };
|
||||
options = {
|
||||
timeout: 4567,
|
||||
max_attempts: 9,
|
||||
priority: 8,
|
||||
};
|
||||
});
|
||||
|
||||
it('should return false if no elasticsearch document', function () {
|
||||
const job = new Job(client, index, 'test', {});
|
||||
// same tick, document promise has not resolved
|
||||
expect(job.toJSON()).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return the static information about the job', function () {
|
||||
const job = new Job(client, index, type, payload, options);
|
||||
// toJSON is sync, but only works once the document has been written
|
||||
return job.ready.then(() => {
|
||||
const doc = job.toJSON();
|
||||
expect(doc).to.have.property('index', index);
|
||||
expect(doc).to.have.property('type', type);
|
||||
expect(doc).to.have.property('timeout', options.timeout);
|
||||
expect(doc).to.have.property('max_attempts', options.max_attempts);
|
||||
expect(doc).to.have.property('priority', options.priority);
|
||||
expect(doc).to.have.property('id');
|
||||
expect(doc).to.not.have.property('version');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user