-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from flocasts/feature/infra-4818-2
fixed main and types
- Loading branch information
Showing
12 changed files
with
114 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// jest.config.js | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
|
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 @@ | ||
export { SqsMessageHandler } from '@ssut/nestjs-sqs'; |
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 +1,3 @@ | ||
export { SqsMessageHandler } from '@ssut/nestjs-sqs'; | ||
import { SqsMessageHandler } from '@ssut/nestjs-sqs'; | ||
|
||
export type { SqsMessageHandler }; |
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,3 @@ | ||
export * from './decorators'; | ||
export * from './module'; | ||
export * from './sqs.service'; |
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,2 +1,3 @@ | ||
export * from './decorators'; | ||
export * from './module'; | ||
export * from './sqs.service'; |
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,8 @@ | ||
import { DynamicModule, LoggerService } from '@nestjs/common'; | ||
import { SqsConsumerOptions, SqsProducerOptions } from '@ssut/nestjs-sqs/dist/sqs.types'; | ||
export interface SQSOptions { | ||
consumers?: SqsConsumerOptions[]; | ||
producers?: SqsProducerOptions[]; | ||
logger?: LoggerService; | ||
} | ||
export declare function SQSModule(options: SQSOptions): DynamicModule; |
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,6 @@ | ||
export { Message } from '@aws-sdk/client-sqs'; | ||
export declare class SqsService { | ||
private static sqsClient; | ||
static Configure(region: string): void; | ||
static DeleteMessage(queueUrl: string, receiptHandle: string): Promise<void>; | ||
} |
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,47 @@ | ||
// libs/my-sqs-wrapper/src/lib/sqs.service.spec.ts | ||
|
||
import { SqsService } from './sqs.service'; | ||
import { SQS } from '@aws-sdk/client-sqs'; | ||
|
||
describe('SqsService', () => { | ||
beforeEach(() => { | ||
// Reset the configuration before each test | ||
SqsService['sqsClient'] = undefined; | ||
}); | ||
|
||
it('should configure the SQS client', () => { | ||
SqsService.Configure('test-region'); | ||
expect(SqsService['sqsClient']).toBeDefined(); | ||
}); | ||
|
||
it('should throw an error if DeleteMessage is called without configuring', async () => { | ||
const queueUrl = 'test-queue-url'; | ||
const receiptHandle = 'test-receipt-handle'; | ||
|
||
// Use async/await to handle the promise rejection | ||
await expect( | ||
SqsService.DeleteMessage(queueUrl, receiptHandle), | ||
).rejects.toThrowError( | ||
'SQS client not configured. Call configure method first.', | ||
); | ||
}); | ||
|
||
it('should delete a message when configured', async () => { | ||
SqsService.Configure('test-region'); | ||
const queueUrl = 'test-queue-url'; | ||
const receiptHandle = 'test-receipt-handle'; | ||
|
||
// Mock the SQS DeleteMessage method | ||
(SqsService['sqsClient'] as SQS).deleteMessage = jest | ||
.fn() | ||
.mockResolvedValue({}); | ||
|
||
await SqsService.DeleteMessage(queueUrl, receiptHandle); | ||
expect((SqsService['sqsClient'] as SQS).deleteMessage).toHaveBeenCalledWith( | ||
{ | ||
QueueUrl: queueUrl, | ||
ReceiptHandle: receiptHandle, | ||
}, | ||
); | ||
}); | ||
}); |
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,31 @@ | ||
import { SQS } from '@aws-sdk/client-sqs'; | ||
export { Message } from '@aws-sdk/client-sqs'; | ||
|
||
export class SqsService { | ||
private static sqsClient: SQS | undefined; | ||
|
||
static Configure(region: string): void { | ||
this.sqsClient = new SQS({ region }); | ||
} | ||
|
||
static async DeleteMessage( | ||
queueUrl: string, | ||
receiptHandle: string, | ||
): Promise<void> { | ||
try { | ||
await this.sqsClient.deleteMessage({ | ||
QueueUrl: queueUrl, | ||
ReceiptHandle: receiptHandle, | ||
}); | ||
} catch (error) { | ||
if (this.sqsClient === undefined) { | ||
throw new Error( | ||
'SQS client not configured. Call configure method first.', | ||
); | ||
} else { | ||
console.error('Error deleting message:', error); | ||
throw error; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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