Skip to content

Commit

Permalink
Merge pull request #3 from flocasts/feature/infra-4818-2
Browse files Browse the repository at this point in the history
fixed main and types
  • Loading branch information
mattchandler-caylent authored Nov 22, 2023
2 parents d41e510 + 1b98160 commit dd4eab0
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 4 deletions.
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

1 change: 1 addition & 0 deletions lib/decorators.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SqsMessageHandler } from '@ssut/nestjs-sqs';
4 changes: 3 additions & 1 deletion lib/decorators.ts
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 };
3 changes: 3 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './decorators';
export * from './module';
export * from './sqs.service';
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './decorators';
export * from './module';
export * from './sqs.service';
8 changes: 8 additions & 0 deletions lib/module.d.ts
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;
6 changes: 6 additions & 0 deletions lib/sqs.service.d.ts
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>;
}
47 changes: 47 additions & 0 deletions lib/sqs.service.spec.ts
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,
},
);
});
});
31 changes: 31 additions & 0 deletions lib/sqs.service.ts
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;
}
}
}
}
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
"name": "@flocasts/nestjs-aws-sqs-connector",
"version": "0.0.1",
"description": "",
"main": ".eslintrc.js",
"main": "dist/index.js",
"types": "dist/index.js.ts",
"engines": {
"node": ">=16.10 <=20"
},
"scripts": {
"build": "tsc -p tsconfig.json"
"build": "tsc -p tsconfig.json",
"test": "jest",
"package": "npm pack"
},
"repository": {
"type": "git",
Expand All @@ -21,6 +24,7 @@
},
"homepage": "https://github.com/flocasts/nestjs-aws-sqs-connector#readme",
"dependencies": {
"@aws-sdk/client-sqs": "^3.451.0",
"@ssut/nestjs-sqs": "^2.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"skipLibCheck": true,
"baseUrl": "./"
},
"include": ["lib", "e2e"],
"include": ["lib/**/*.ts"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}

0 comments on commit dd4eab0

Please sign in to comment.