update toJSON, add tests, remove unused var
This commit is contained in:
@@ -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