Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(typescript-v5) fixing decorator returntype for v5 #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
<br />
<div align="center">
<strong>A thin wrapping layer around the <a href="https://github.com/aws/aws-sdk-js" target="_blank">aws-sdk</a> package for clean <a href="https://github.com/nestjs">NestJS</a> dependency injection.</strong>
<strong>A thin wrapping layer around the <a href="https://github.com/aws/aws-sdk-js" target="_blank">aws-sdk</a> (AWS SDK v2) package for clean <a href="https://github.com/nestjs">NestJS</a> dependency injection.</strong>
</div>
<br />
<div align="center">
Expand All @@ -15,10 +15,10 @@

# Features

* Decorator for injecting AWS services.
* An AWS service factory for on-the-fly AWS client creation.
* A simple dependency injection model with AwsSdkModule.forRootAsync() and AwsSdkModule.forFeature().
* Helper test tools for creating mocked AWS clients.
- Decorator for injecting AWS services.
- An AWS service factory for on-the-fly AWS client creation.
- A simple dependency injection model with AwsSdkModule.forRootAsync() and AwsSdkModule.forFeature().
- Helper test tools for creating mocked AWS clients.

# How To Use

Expand Down Expand Up @@ -80,10 +80,7 @@ import { S3 } from 'aws-sdk';

@Injectable()
export class S3ManagerService {
constructor(
@InjectAwsService(S3) private readonly s3: S3,
) {
}
constructor(@InjectAwsService(S3) private readonly s3: S3) {}

async listBucketContents(bucket: string) {
const response = await this.s3.listObjectsV2({ Bucket: bucket }).promise();
Expand All @@ -96,7 +93,11 @@ export class S3ManagerService {
// s3-manager.service.spec.ts
import { Test, TestingModule } from '@nestjs/testing';
import { S3 } from 'aws-sdk';
import { createAwsServiceMock, createAwsServicePromisableSpy, getAwsServiceMock } from 'nest-aws-sdk/dist/testing';
import {
createAwsServiceMock,
createAwsServicePromisableSpy,
getAwsServiceMock,
} from 'nest-aws-sdk/dist/testing';
import { S3ManagerService } from './s3-manager.service';

describe('S3ManagerService', () => {
Expand All @@ -108,19 +109,19 @@ describe('S3ManagerService', () => {
createAwsServiceMock(S3, {
useValue: {
listObjectsV2: () => null,
}
},
}),
],
}).compile();

const service = module.get(S3ManagerService);

const listSpy = createAwsServicePromisableSpy(
getAwsServiceMock(module, S3),
'listObjectsV2',
'resolve',
{
Contents: [ { Key: 'myKey' } ],
Contents: [{ Key: 'myKey' }],
},
);

Expand All @@ -131,7 +132,7 @@ describe('S3ManagerService', () => {
expect(listSpy).toHaveBeenCalledTimes(1);
expect(listSpy).toHaveBeenCalledWith({ Bucket: 'myBucket' });
});
})
});
});
```

Expand All @@ -157,7 +158,7 @@ import { S3ManagerModule } from './s3-manager/s3-manager.module';
credentials: new SharedIniFileCredentials({
profile: 'my-profile',
}),
}
},
},
}),
],
Expand Down Expand Up @@ -211,8 +212,8 @@ import { CloudFront, S3, SharedIniFileCredentials } from 'aws-sdk';
credentials: new SharedIniFileCredentials({
profile: 'aws-nest-sdk',
}),
}
}
},
},
],
}),
],
Expand All @@ -237,10 +238,7 @@ import { AwsSdkModule } from 'nest-aws-sdk';
import { S3ManagerModule } from './s3-manager/s3-manager.module';

@Module({
imports: [
S3ManagerModule,
AwsSdkModule.forRootAsync(),
],
imports: [S3ManagerModule, AwsSdkModule.forRootAsync()],
providers: [],
exports: [],
})
Expand Down Expand Up @@ -269,7 +267,7 @@ import { S3ManagerModule } from './s3-manager/s3-manager.module';
credentials: new SharedIniFileCredentials({
profile: 'my-profile',
}),
}
},
},
}),
],
Expand Down Expand Up @@ -311,13 +309,13 @@ import { ConfigService, ConfigModule } from './config';

## AwsSdkModule.forFeatures()

`AwsSdkModule.forFeatures()` creates the providers for the AWS clients you wish to use at a module-specific level.
`AwsSdkModule.forFeatures()` creates the providers for the AWS clients you wish to use at a module-specific level.

**Note: forFeatures cannot be used in combination with root-level service registrations.**

### Basic usage

To provide clients to the module context, pass the client constructor symbol to the `AwsSdkModule.forFeatures()` method. Note, it is best to import the client directly from `aws-sdk` instead of from deeper paths - the deeper paths may produce unexpected behaviors.
To provide clients to the module context, pass the client constructor symbol to the `AwsSdkModule.forFeatures()` method. Note, it is best to import the client directly from `aws-sdk` instead of from deeper paths - the deeper paths may produce unexpected behaviors.

```ts
import { Module } from '@nestjs/common';
Expand Down Expand Up @@ -366,13 +364,12 @@ const module: TestingModule = await Test.createTestingModule({
createAwsServiceMock(S3, {
useValue: {
listObjectsV2: () => null,
}
},
}),
],
}).compile();
```


### getAwsServiceMock

To retrieve a mock from the test bed via the correct symbol, `getAwsServiceMock` is exported.
Expand All @@ -391,7 +388,7 @@ it('should call the list method and return the Content keys', async () => {
s3, // the mocked object to spy on
'listObjectsV2', // the method to spy on
'resolve', // 'resolve' or 'reject'
{ Contents: [ { Key: 'myKey' } ] }, // the value to resolve or reject
{ Contents: [{ Key: 'myKey' }] }, // the value to resolve or reject
);

const result = await service.listBucketContents('myBucket');
Expand All @@ -405,7 +402,7 @@ it('should call the list method and return the Content keys', async () => {

# Stay In Touch

* Author - [Kerry Ritter](https://twitter.com/kerryritter) and BeerMoneyDev
- Author - [Kerry Ritter](https://twitter.com/kerryritter) and BeerMoneyDev

## License

Expand Down
Loading