|
8 | 8 | IdempotencyInconsistentStateError,
|
9 | 9 | IdempotencyItemAlreadyExistsError,
|
10 | 10 | IdempotencyPersistenceLayerError,
|
11 |
| -} from '../../src/Exceptions'; |
| 11 | +} from '../../src/errors'; |
12 | 12 | import { IdempotencyRecordStatus } from '../../src/types';
|
13 | 13 | import { BasePersistenceLayer, IdempotencyRecord } from '../../src/persistence';
|
14 | 14 | import { IdempotencyHandler } from '../../src/IdempotencyHandler';
|
@@ -165,16 +165,20 @@ describe('Class IdempotencyHandler', () => {
|
165 | 165 | });
|
166 | 166 |
|
167 | 167 | test('when persistences store throws any error, it wraps the error to IdempotencyPersistencesLayerError', async () => {
|
| 168 | + const innerError = new Error('Some error'); |
168 | 169 | const mockSaveInProgress = jest
|
169 | 170 | .spyOn(mockIdempotencyOptions.persistenceStore, 'saveInProgress')
|
170 |
| - .mockRejectedValue(new Error('Some error')); |
| 171 | + .mockRejectedValue(innerError); |
171 | 172 | const mockDetermineResultFromIdempotencyRecord = jest
|
172 | 173 | .spyOn(IdempotencyHandler, 'determineResultFromIdempotencyRecord')
|
173 | 174 | .mockImplementation(() => 'result');
|
174 |
| - |
175 | 175 | await expect(idempotentHandler.processIdempotency()).rejects.toThrow(
|
176 |
| - IdempotencyPersistenceLayerError |
| 176 | + new IdempotencyPersistenceLayerError( |
| 177 | + 'Failed to save record in progress', |
| 178 | + innerError |
| 179 | + ) |
177 | 180 | );
|
| 181 | + |
178 | 182 | expect(mockSaveInProgress).toHaveBeenCalledTimes(1);
|
179 | 183 | expect(mockDetermineResultFromIdempotencyRecord).toHaveBeenCalledTimes(0);
|
180 | 184 | });
|
@@ -323,7 +327,9 @@ describe('Class IdempotencyHandler', () => {
|
323 | 327 | .mockRejectedValue(new Error('Some error'));
|
324 | 328 |
|
325 | 329 | await expect(idempotentHandler.getFunctionResult()).rejects.toThrow(
|
326 |
| - IdempotencyPersistenceLayerError |
| 330 | + new IdempotencyPersistenceLayerError( |
| 331 | + 'Failed to delete record from idempotency store. This error was caused by: Some error.' |
| 332 | + ) |
327 | 333 | );
|
328 | 334 | expect(mockDeleteInProgress).toHaveBeenCalledTimes(1);
|
329 | 335 | });
|
|
0 commit comments