Skip to content

Commit 5ab0c66

Browse files
Merge branch 'master' into #200-array-position-in-attribute-path
2 parents 9207355 + 2dd0428 commit 5ab0c66

File tree

8 files changed

+64
-8
lines changed

8 files changed

+64
-8
lines changed

src/dynamo/batchget/batch-get.request.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import { BatchGetRequest } from './batch-get.request'
1010
describe('batch get', () => {
1111
let request: BatchGetRequest
1212

13+
describe('constructor', () => {
14+
it('use provided DynamoDB instance', () => {
15+
const dynamoDB = new DynamoDB()
16+
const batchGetRequest = new BatchGetRequest(dynamoDB)
17+
expect(batchGetRequest.dynamoDB).toBe(dynamoDB)
18+
19+
const batchGetRequest2 = new BatchGetRequest()
20+
expect(batchGetRequest2.dynamoDB).not.toBe(dynamoDB)
21+
})
22+
})
23+
1324
describe('params', () => {
1425
beforeEach(() => (request = new BatchGetRequest()))
1526

src/dynamo/batchget/batch-get.request.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ import { BatchGetResponse } from './batch-get.response'
1818
* Request class for the BatchGetItem operation. Read multiple items from one or more tables.
1919
*/
2020
export class BatchGetRequest {
21+
get dynamoDB(): DynamoDB {
22+
return this.dynamoDBWrapper.dynamoDB
23+
}
24+
2125
readonly params: DynamoDB.BatchGetItemInput
2226
private readonly dynamoDBWrapper: DynamoDbWrapper
2327
private readonly tables: Map<string, ModelConstructor<any>> = new Map()
2428
private itemCounter = 0
2529

26-
constructor() {
27-
this.dynamoDBWrapper = new DynamoDbWrapper()
30+
constructor(dynamoDB?: DynamoDB) {
31+
this.dynamoDBWrapper = new DynamoDbWrapper(dynamoDB)
2832
this.params = {
2933
RequestItems: {},
3034
}

src/dynamo/batchwrite/batch-write.request.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
12
import { ComplexModel, SimpleWithPartitionKeyModel } from '../../../test/models'
23
import { getTableName } from '../get-table-name.function'
34
import { BatchWriteRequest } from './batch-write.request'
@@ -11,6 +12,15 @@ describe('batchWriteRequest', () => {
1112
expect(req.params.RequestItems).toBeDefined()
1213
expect(req.params.RequestItems).toEqual({})
1314
})
15+
16+
describe('use provided DynamoDB instance', () => {
17+
const dynamoDB = new DynamoDB()
18+
const batchWriteRequest = new BatchWriteRequest(dynamoDB)
19+
expect(batchWriteRequest.dynamoDB).toBe(dynamoDB)
20+
21+
const batchWriteRequest2 = new BatchWriteRequest()
22+
expect(batchWriteRequest2.dynamoDB).not.toBe(dynamoDB)
23+
})
1424
})
1525

1626
describe('returnConsumedCapacity', () => {

src/dynamo/batchwrite/batch-write.request.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ import { BATCH_WRITE_DEFAULT_TIME_SLOT, BATCH_WRITE_MAX_REQUEST_ITEM_COUNT } fro
1414
* Request class for the BatchWriteItem operation. Put or delete multiple items in one or more table.
1515
*/
1616
export class BatchWriteRequest {
17+
get dynamoDB(): DynamoDB {
18+
return this.dynamoDBWrapper.dynamoDB
19+
}
20+
1721
readonly params: DynamoDB.BatchWriteItemInput
1822
private readonly dynamoDBWrapper: DynamoDbWrapper
1923
private itemCount = 0
2024

21-
constructor() {
22-
this.dynamoDBWrapper = new DynamoDbWrapper()
25+
constructor(dynamoDB? : DynamoDB) {
26+
this.dynamoDBWrapper = new DynamoDbWrapper(dynamoDB)
2327
this.params = {
2428
RequestItems: {},
2529
}

src/dynamo/transactget/transact-get.request.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ describe('TransactGetRequest', () => {
1818
expect(req.params.TransactItems).toBeDefined()
1919
expect(req.params.TransactItems.length).toBe(0)
2020
})
21+
22+
it('use provided DynamoDB instance', () => {
23+
const dynamoDB = new DynamoDB()
24+
const transactGetRequest = new TransactGetRequest(dynamoDB)
25+
expect(transactGetRequest.dynamoDB).toBe(dynamoDB)
26+
27+
const transactGetRequest2 = new TransactGetRequest()
28+
expect(transactGetRequest2.dynamoDB).not.toBe(dynamoDB)
29+
})
2130
})
2231

2332
describe('returnConsumedCapacity', () => {

src/dynamo/transactget/transact-get.request.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ const MAX_REQUEST_ITEM_COUNT = 10
1919
* Request class for the TransactGetItems operation. Read up to 10 items from one or more tables in a transaction.
2020
*/
2121
export class TransactGetRequest {
22+
get dynamoDB(): DynamoDB {
23+
return this.dynamoDBWrapper.dynamoDB
24+
}
25+
2226
readonly params: DynamoDB.TransactGetItemsInput
2327
private readonly dynamoDBWrapper: DynamoDbWrapper
2428
private readonly tables: Array<ModelConstructor<any>> = []
2529

26-
constructor() {
27-
this.dynamoDBWrapper = new DynamoDbWrapper()
30+
constructor(dynamoDB?: DynamoDB) {
31+
this.dynamoDBWrapper = new DynamoDbWrapper(dynamoDB)
2832
this.params = {
2933
TransactItems: [],
3034
}

src/dynamo/transactwrite/transact-write.request.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// tslint:disable:no-non-null-assertion
2+
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
23
import { SimpleWithPartitionKeyModel } from '../../../test/models'
34
import { attribute } from '../expression/logical-operator/attribute.function'
45
import { update } from '../expression/logical-operator/update.function'
@@ -22,6 +23,15 @@ describe('TransactWriteRequest', () => {
2223
TransactItems: [],
2324
})
2425
})
26+
27+
it('use provided DynamoDB instance', () => {
28+
const dynamoDB = new DynamoDB()
29+
const transactWriteRequest = new TransactWriteRequest(dynamoDB)
30+
expect(transactWriteRequest.dynamoDB).toBe(dynamoDB)
31+
32+
const transactWriteRequest2 = new TransactWriteRequest()
33+
expect(transactWriteRequest2.dynamoDB).not.toBe(dynamoDB)
34+
})
2535
})
2636

2737
describe('transact', () => {

src/dynamo/transactwrite/transact-write.request.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import { TransactOperation } from './transact-operation.type'
99
* Request class for the TransactWriteItems operation. Write up to 10 items to one or many tables in a transaction.
1010
*/
1111
export class TransactWriteRequest {
12+
get dynamoDB(): DynamoDB {
13+
return this.dynamoDBWrapper.dynamoDB
14+
}
15+
1216
readonly params: DynamoDB.TransactWriteItemsInput
1317
private readonly dynamoDBWrapper: DynamoDbWrapper
1418

15-
constructor() {
16-
this.dynamoDBWrapper = new DynamoDbWrapper()
19+
constructor(dynamoDB?: DynamoDB) {
20+
this.dynamoDBWrapper = new DynamoDbWrapper(dynamoDB)
1721
this.params = {
1822
TransactItems: [],
1923
}

0 commit comments

Comments
 (0)