-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(batch): add esmodule support (#1737)
- Loading branch information
1 parent
3ba9d43
commit 4ee57bd
Showing
21 changed files
with
230 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
export * from './constants'; | ||
export * from './errors'; | ||
export * from './types'; | ||
export * from './BasePartialProcessor'; | ||
export * from './BasePartialBatchProcessor'; | ||
export * from './BatchProcessorSync'; | ||
export * from './BatchProcessor'; | ||
export * from './processPartialResponseSync'; | ||
export * from './processPartialResponse'; | ||
export * from './SqsFifoPartialProcessor'; | ||
export { EventType } from './constants.js'; | ||
export { | ||
BatchProcessingError, | ||
FullBatchFailureError, | ||
SqsFifoShortCircuitError, | ||
UnexpectedBatchTypeError, | ||
} from './errors.js'; | ||
export { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js'; | ||
export { BatchProcessorSync } from './BatchProcessorSync.js'; | ||
export { BatchProcessor } from './BatchProcessor.js'; | ||
export { processPartialResponseSync } from './processPartialResponseSync.js'; | ||
export { processPartialResponse } from './processPartialResponse.js'; | ||
export { SqsFifoPartialProcessor } from './SqsFifoPartialProcessor.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Test BasePartialBatchProcessor class | ||
* | ||
* @group unit/batch/class/basepartialbatchprocessor | ||
*/ | ||
import { BasePartialBatchProcessor, EventType } from '../../src/index.js'; | ||
import type { | ||
BaseRecord, | ||
FailureResponse, | ||
SuccessResponse, | ||
} from '../../src/types.js'; | ||
import { sqsRecordFactory } from '../helpers/factories.js'; | ||
import { sqsRecordHandler } from '../helpers/handlers.js'; | ||
|
||
describe('Class: BasePartialBatchProcessor', () => { | ||
const ENVIRONMENT_VARIABLES = process.env; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.resetModules(); | ||
process.env = { ...ENVIRONMENT_VARIABLES }; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = ENVIRONMENT_VARIABLES; | ||
}); | ||
|
||
class MyPartialProcessor extends BasePartialBatchProcessor { | ||
public constructor() { | ||
super(EventType.SQS); | ||
} | ||
|
||
public async processRecord( | ||
_record: BaseRecord | ||
): Promise<SuccessResponse | FailureResponse> { | ||
throw new Error('Not implemented'); | ||
} | ||
|
||
public processRecordSync( | ||
record: BaseRecord | ||
): SuccessResponse | FailureResponse { | ||
console.log('Processing record'); | ||
|
||
return this.successHandler(record, 'success'); | ||
} | ||
} | ||
|
||
describe('create custom batch partial processor', () => { | ||
it('should create a custom batch partial processor', () => { | ||
// Act | ||
const processor = new MyPartialProcessor(); | ||
|
||
// Assess | ||
expect(processor).toBeInstanceOf(BasePartialBatchProcessor); | ||
}); | ||
|
||
it('should process a batch of records', () => { | ||
// Prepare | ||
const processor = new MyPartialProcessor(); | ||
const records = [sqsRecordFactory('success')]; | ||
const consoleSpy = jest.spyOn(console, 'log'); | ||
|
||
// Act | ||
processor.register(records, sqsRecordHandler); | ||
const processedMessages = processor.processSync(); | ||
|
||
// Assess | ||
expect(processedMessages).toStrictEqual([ | ||
['success', records[0].body, records[0]], | ||
]); | ||
expect(consoleSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.