add tests for optional fields to get and toJSON methods

This commit is contained in:
2016-05-16 15:04:35 -07:00
parent be1eb81059
commit 4472e725fa

View File

@@ -200,6 +200,7 @@ describe('Job Class', function () {
expect(doc).to.have.property('type', jobDoc.type);
expect(doc).to.have.property('id', jobDoc.id);
expect(doc).to.have.property('version', jobDoc.version);
expect(doc).to.have.property('created_by', defaultCreatedBy);
expect(doc).to.have.property('payload');
expect(doc).to.have.property('jobtype');
@@ -207,6 +208,25 @@ describe('Job Class', function () {
expect(doc).to.have.property('timeout');
});
});
it('should contain optional data', function () {
const optionals = {
created_by: 'some_ident'
};
const job = new Job(client, index, type, payload, optionals);
return Promise.resolve(client.get({}, optionals))
.then((doc) => {
console.log('mocked doc', doc);
sinon.stub(client, 'get').returns(Promise.resolve(doc));
})
.then(() => {
return job.get()
.then((doc) => {
expect(doc).to.have.property('created_by', optionals.created_by);
});
});
});
});
describe('toJSON method', function () {
@@ -230,12 +250,23 @@ describe('Job Class', function () {
expect(doc).to.have.property('index', index);
expect(doc).to.have.property('type', DEFAULT_SETTING_DOCTYPE);
expect(doc).to.have.property('jobtype', type);
expect(doc).to.have.property('created_by', defaultCreatedBy);
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');
});
it('should contain optional data', function () {
const optionals = {
created_by: 'some_ident'
};
const job = new Job(client, index, type, payload, optionals);
const doc = job.toJSON();
expect(doc).to.have.property('created_by', optionals.created_by);
});
});
});