|
7 | 7 | import expect from '@kbn/expect'; |
8 | 8 | import sinon from 'sinon'; |
9 | 9 | import { CancellationToken } from '../../../../common'; |
10 | | -import { LevelLogger } from '../../../lib'; |
| 10 | +import { createMockLevelLogger } from '../../../test_helpers/create_mock_levellogger'; |
11 | 11 | import { ScrollConfig } from '../../../types'; |
12 | 12 | import { createHitIterator } from './hit_iterator'; |
13 | 13 |
|
14 | | -const mockLogger = { |
15 | | - error: new Function(), |
16 | | - debug: new Function(), |
17 | | - warning: new Function(), |
18 | | -} as LevelLogger; |
| 14 | +const mockLogger = createMockLevelLogger(); |
19 | 15 | const debugLogStub = sinon.stub(mockLogger, 'debug'); |
20 | | -const warnLogStub = sinon.stub(mockLogger, 'warning'); |
| 16 | +const warnLogStub = sinon.stub(mockLogger, 'warn'); |
21 | 17 | const errorLogStub = sinon.stub(mockLogger, 'error'); |
22 | 18 | const mockCallEndpoint = sinon.stub(); |
23 | 19 | const mockSearchRequest = {}; |
@@ -134,4 +130,30 @@ describe('hitIterator', function () { |
134 | 130 | expect(errorLogStub.callCount).to.be(1); |
135 | 131 | expect(errorThrown).to.be(true); |
136 | 132 | }); |
| 133 | + |
| 134 | + it('handles scroll id could not be cleared', async () => { |
| 135 | + // Setup |
| 136 | + mockCallEndpoint.withArgs('clearScroll').rejects({ status: 404 }); |
| 137 | + |
| 138 | + // Begin |
| 139 | + const hitIterator = createHitIterator(mockLogger); |
| 140 | + const iterator = hitIterator( |
| 141 | + mockConfig, |
| 142 | + mockCallEndpoint, |
| 143 | + mockSearchRequest, |
| 144 | + realCancellationToken |
| 145 | + ); |
| 146 | + |
| 147 | + while (true) { |
| 148 | + const { done: iterationDone, value: hit } = await iterator.next(); |
| 149 | + if (iterationDone) { |
| 150 | + break; |
| 151 | + } |
| 152 | + expect(hit).to.be('you found me'); |
| 153 | + } |
| 154 | + |
| 155 | + expect(mockCallEndpoint.callCount).to.be(13); |
| 156 | + expect(warnLogStub.callCount).to.be(1); |
| 157 | + expect(errorLogStub.callCount).to.be(1); |
| 158 | + }); |
137 | 159 | }); |
0 commit comments