/
execute_legacy_operation.test.js
47 lines (37 loc) · 1.3 KB
/
execute_legacy_operation.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const expect = require('chai').expect;
const executeLegacyOperation = require('../../src/utils').executeLegacyOperation;
describe('executeLegacyOperation', function () {
it('should call callback with errors on throw errors, and rethrow error', function () {
const expectedError = new Error('THIS IS AN ERROR');
let callbackError, caughtError;
const topology = {
logicalSessionTimeoutMinutes: null
};
const operation = () => {
throw expectedError;
};
const callback = err => (callbackError = err);
const options = { skipSessions: true };
try {
executeLegacyOperation(topology, operation, [{}, callback], options);
} catch (e) {
caughtError = e;
}
expect(callbackError).to.equal(expectedError);
expect(caughtError).to.equal(expectedError);
});
it('should reject promise with errors on throw errors, and rethrow error', function () {
const expectedError = new Error('THIS IS AN ERROR');
const topology = {
logicalSessionTimeoutMinutes: null
};
const operation = () => {
throw expectedError;
};
const options = { skipSessions: true };
return executeLegacyOperation(topology, operation, [{}, null], options).then(null, err => {
expect(err).to.equal(expectedError);
});
});
});