Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('returns the document instance if it exists', () => {
const collectionName = 'foobar';
const documentId = 'foo';
const criteria = `_id = :id`;
const expected = { _id: documentId, name: 'bar' };
const schema = 'baz';
const session = 'qux';
td.when(execute(td.callback(expected))).thenResolve();
td.when(bind('id', documentId)).thenReturn({ execute });
td.when(collectionFind(session, schema, collectionName, criteria)).thenReturn({ bind });
collection = require('../../../lib/DevAPI/Collection');
const instance = collection(session, schema, collectionName);
return instance.getOne(documentId)
.then(actual => expect(actual).to.deep.equal(expected));
});
it('calls a handlers provided as an `execute` object argument', () => {
const query = sqlExecute({ _client: { sqlStmtExecute } });
const meta = ['bar'];
td.when(sqlStmtExecute(td.matchers.anything(), td.callback('foo'), td.callback([meta]))).thenResolve();
return query.execute({
row (actual) {
expect(actual).to.equal('foo');
},
meta (actual) {
expect(actual).to.deep.equal([new Column(meta)]);
}
});
});
it('wraps an operation with a cursor in a preparable instance', () => {
const execute = td.function();
const session = 'foo';
const expected = ['bar'];
const state = { warnings: expected };
td.when(execute(td.matchers.isA(Function), td.matchers.isA(Function))).thenResolve(state);
td.when(preparing({ session })).thenReturn({ execute });
return collectionFind(session).execute(td.callback())
.then(actual => expect(actual.getWarnings()).to.deep.equal(expected));
});
});