File tree Expand file tree Collapse file tree 4 files changed +22
-15
lines changed Expand file tree Collapse file tree 4 files changed +22
-15
lines changed Original file line number Diff line number Diff line change 1
1
// tslint:disable:no-empty
2
2
// tslint:disable:no-unnecessary-callback-wrapper
3
3
4
- import { Config , Credentials } from 'aws-sdk/global '
4
+ import * as DynamoDB from 'aws-sdk/clients/dynamodb '
5
5
import { resetDynamoEasyConfig } from '../../test/helper/resetDynamoEasyConfig.function'
6
6
import { updateDynamoEasyConfig } from '../config/update-config.function'
7
7
import { DynamoDbWrapper } from './dynamo-db-wrapper'
@@ -130,10 +130,12 @@ describe('dynamo rx', () => {
130
130
expect ( makeRequest . calls . mostRecent ( ) . args [ 0 ] ) . toEqual ( { ok : true } )
131
131
} )
132
132
133
- it ( 'should update the credentials' , ( ) => {
134
- const dynamoDBWrapper = new DynamoDbWrapper ( )
135
- const credentials = new Credentials ( { secretAccessKey : '' , sessionToken : '' , accessKeyId : '' } )
136
- dynamoDBWrapper . updateAwsConfigCredentials ( new Config ( { credentials } ) )
137
- expect ( dynamoDBWrapper . dynamoDB . config . credentials ) . toBe ( credentials )
133
+ it ( 'should use given dynamoDB client' , ( ) => {
134
+ const dynamoDB = new DynamoDB ( )
135
+ const dynamoDBWrapper = new DynamoDbWrapper ( dynamoDB )
136
+ expect ( dynamoDBWrapper . dynamoDB ) . toBe ( dynamoDB )
137
+
138
+ const dynamoDBWrapper2 = new DynamoDbWrapper ( )
139
+ expect ( dynamoDBWrapper2 . dynamoDB ) . not . toBe ( dynamoDB )
138
140
} )
139
141
} )
Original file line number Diff line number Diff line change 2
2
* @module dynamo-easy
3
3
*/
4
4
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
5
- import { Config } from 'aws-sdk/global'
6
5
import { dynamoEasyConfig } from '../config/dynamo-easy-config'
7
6
8
7
/**
@@ -13,13 +12,9 @@ import { dynamoEasyConfig } from '../config/dynamo-easy-config'
13
12
export class DynamoDbWrapper {
14
13
readonly dynamoDB : DynamoDB
15
14
16
- constructor ( ) {
15
+ constructor ( dynamoDB ?: DynamoDB ) {
17
16
// create the actual dynamoDB client
18
- this . dynamoDB = new DynamoDB ( )
19
- }
20
-
21
- updateAwsConfigCredentials ( newConfig : Config ) : void {
22
- this . dynamoDB . config . update ( { credentials : newConfig . credentials } )
17
+ this . dynamoDB = dynamoDB || new DynamoDB ( )
23
18
}
24
19
25
20
/*
Original file line number Diff line number Diff line change 1
1
// tslint:disable:max-classes-per-file
2
2
// tslint:disable:no-unnecessary-class
3
3
// tslint:disable:no-unused-expression
4
+ import * as DynamoDB from 'aws-sdk/clients/dynamodb'
4
5
import { resetDynamoEasyConfig } from '../../test/helper/resetDynamoEasyConfig.function'
5
6
import { SimpleWithPartitionKeyModel } from '../../test/models'
6
7
import { updateDynamoEasyConfig } from '../config/update-config.function'
@@ -95,4 +96,13 @@ describe('dynamo store', () => {
95
96
const store = new DynamoStore ( SimpleWithPartitionKeyModel )
96
97
expect ( store . dynamoDB ) . toBeDefined ( )
97
98
} )
99
+
100
+ describe ( 'use provided dynamoDB instance' , ( ) => {
101
+ const dynamoDB = new DynamoDB ( )
102
+ const store = new DynamoStore ( SimpleWithPartitionKeyModel , dynamoDB )
103
+ expect ( store . dynamoDB ) . toBe ( dynamoDB )
104
+
105
+ const store2 = new DynamoStore ( SimpleWithPartitionKeyModel )
106
+ expect ( store2 . dynamoDB ) . not . toBe ( dynamoDB )
107
+ } )
98
108
} )
Original file line number Diff line number Diff line change @@ -30,9 +30,9 @@ export class DynamoStore<T> {
30
30
private readonly logger : Logger
31
31
private readonly dynamoDBWrapper : DynamoDbWrapper
32
32
33
- constructor ( private modelClazz : ModelConstructor < T > ) {
33
+ constructor ( private modelClazz : ModelConstructor < T > , dynamoDB ?: DynamoDB ) {
34
34
this . logger = createLogger ( 'dynamo.DynamoStore' , modelClazz )
35
- this . dynamoDBWrapper = new DynamoDbWrapper ( )
35
+ this . dynamoDBWrapper = new DynamoDbWrapper ( dynamoDB )
36
36
this . tableName = getTableName ( modelClazz )
37
37
this . logger . debug ( 'instance created' )
38
38
}
You can’t perform that action at this time.
0 commit comments