Skip to content

Commit d48e679

Browse files
test(requests): improve coverage
1 parent aaa798d commit d48e679

File tree

6 files changed

+65
-23
lines changed

6 files changed

+65
-23
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Dynamo-Easy
22
[![Travis](https://img.shields.io/travis/shiftcode/dynamo-easy.svg)](https://travis-ci.org/shiftcode/dynamo-easy)
33
[![Coverage Status](https://img.shields.io/coveralls/jekyll/jekyll.svg)](https://coveralls.io/github/shiftcode/dynamo-easy?branch=master)
4+
[![Coverage Status](https://coveralls.io/repos/github/shiftcode/dynamo-easy/badge.svg?branch=master)](https://coveralls.io/github/shiftcode/dynamo-easy?branch=master)
45
[![Dev Dependencies](https://img.shields.io/david/expressjs/express.svg)](https://david-dm.org/michaelwittwer/dynamo-easy?type=dev)
56
[![Greenkeeper badge](https://badges.greenkeeper.io/alexjoverm/typescript-library-starter.svg)](https://greenkeeper.io/)
67
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1+
import { GetItemInput } from 'aws-sdk/clients/dynamodb'
12
import { getTableName } from '../../../../test/helper/get-table-name.function'
23
import { SimpleWithIdModel } from '../../../../test/models/simple-with-id.model'
34
import { GetRequest } from './get.request'
45

56
describe('get requst', () => {
7+
let request: GetRequest<SimpleWithIdModel>
8+
9+
beforeEach(() => {
10+
request = new GetRequest(null, SimpleWithIdModel, getTableName(SimpleWithIdModel), 'partitionKeyValue')
11+
})
12+
13+
it('default params', () => {
14+
const params: GetItemInput = request.params
15+
expect(params.TableName).toBe('simple-with-id-models')
16+
expect(params.Key).toEqual({ id: { S: 'partitionKeyValue' } })
17+
expect(Object.keys(params).length).toBe(2)
18+
})
19+
620
it('projection expression', () => {
7-
const r = new GetRequest(null, SimpleWithIdModel, getTableName(SimpleWithIdModel), 'partitionKeyValue')
8-
r.projectionExpression('name')
21+
request.projectionExpression('name')
922

10-
const params = r.params
23+
const params = request.params
1124
expect(params.ProjectionExpression).toBe('#name')
1225
expect(params.ExpressionAttributeNames).toEqual({ '#name': 'name' })
26+
expect(Object.keys(params).length).toBe(4)
1327
})
1428
})

src/dynamo/request/put/put.request.spec.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,37 @@ import { SimpleWithIdModel } from '../../../../test/models/simple-with-id.model'
44
import { PutRequest } from './put.request'
55

66
describe('put request', () => {
7+
it('default params', () => {
8+
const item: SimpleWithIdModel = { id: 'myId', age: 45 }
9+
const request = new PutRequest(null, SimpleWithIdModel, getTableName(SimpleWithIdModel), item)
10+
const params: PutItemInput = request.params
11+
12+
expect(params.TableName).toBe('simple-with-id-models')
13+
expect(params.Item).toEqual({ id: { S: 'myId' }, age: { N: '45' } })
14+
expect(Object.keys(params).length).toBe(2)
15+
})
16+
717
describe('if exists condition', () => {
818
it('simple', () => {
919
const item: SimpleWithIdModel = { id: 'myId', age: 45 }
1020
const request = new PutRequest(null, SimpleWithIdModel, getTableName(SimpleWithIdModel), item)
1121
request.ifNotExists()
1222

13-
expect((<PutItemInput>request.params).ConditionExpression).toBe('attribute_not_exists (#id)')
14-
expect((<PutItemInput>request.params).ExpressionAttributeNames).toEqual({ '#id': 'id' })
15-
expect((<PutItemInput>request.params).ExpressionAttributeValues).toBeUndefined()
23+
const params: PutItemInput = request.params
24+
expect(params.ConditionExpression).toBe('attribute_not_exists (#id)')
25+
expect(params.ExpressionAttributeNames).toEqual({ '#id': 'id' })
26+
expect(params.ExpressionAttributeValues).toBeUndefined()
1627
})
1728

1829
it('predicate', () => {
1930
const item: SimpleWithIdModel = { id: 'myId', age: 45 }
2031
const request = new PutRequest(null, SimpleWithIdModel, getTableName(SimpleWithIdModel), item)
2132
request.ifNotExists(25 + 20 === 40)
2233

23-
expect((<PutItemInput>request.params).ConditionExpression).toBeUndefined()
24-
expect((<PutItemInput>request.params).ExpressionAttributeNames).toBeUndefined()
25-
expect((<PutItemInput>request.params).ExpressionAttributeValues).toBeUndefined()
34+
const params: PutItemInput = request.params
35+
expect(params.ConditionExpression).toBeUndefined()
36+
expect(params.ExpressionAttributeNames).toBeUndefined()
37+
expect(params.ExpressionAttributeValues).toBeUndefined()
2638
})
2739
})
2840
})

src/dynamo/request/query/query.request.spec.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,11 @@ describe('query request', () => {
2727
it('defaults should be defined', () => {
2828
expect(request.params.TableName).toBe('complex_model')
2929
expect(request.params.Limit).toBe(QueryRequest.DEFAULT_LIMIT)
30-
expect(request.params.IndexName).toBeUndefined()
31-
expect(request.params.KeyConditions).toBeUndefined()
32-
expect(request.params.KeyConditionExpression).toBeUndefined()
33-
expect(request.params.ConditionalOperator).toBeUndefined()
34-
expect(request.params.AttributesToGet).toBeUndefined()
35-
expect(request.params.ConsistentRead).toBeUndefined()
36-
expect(request.params.ExclusiveStartKey).toBeUndefined()
37-
expect(request.params.ExpressionAttributeNames).toBeUndefined()
38-
expect(request.params.ExpressionAttributeValues).toBeUndefined()
30+
expect(Object.keys(request.params).length).toBe(2)
3931
})
4032

4133
it('Limit', () => {
4234
request.limit(5)
43-
expect(request.params).toBeDefined()
4435
expect(request.params.Limit).toBe(5)
4536
})
4637
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ScanInput, ScanOutput } from 'aws-sdk/clients/dynamodb'
2+
import { Observable } from 'rxjs/Observable'
3+
import { getTableName } from '../../../../test/helper/get-table-name.function'
4+
import { ComplexModel } from '../../../../test/models/complex.model'
5+
import { Request } from '../request.model'
6+
import { ScanRequest } from './scan.request'
7+
8+
class DynamoRxMock {
9+
scan(): Observable<ScanOutput> {
10+
return Observable.of({ Count: 10 })
11+
}
12+
}
13+
14+
describe('scan request', () => {
15+
const dynamoRxMock: DynamoRxMock = new DynamoRxMock()
16+
let scanRequest: ScanRequest<any>
17+
18+
beforeEach(() => {
19+
scanRequest = new ScanRequest(<any>dynamoRxMock, ComplexModel, getTableName(ComplexModel))
20+
})
21+
22+
it('default params', () => {
23+
const params: ScanInput = scanRequest.params
24+
expect(params.TableName).toBe('complex_model')
25+
expect(params.Limit).toBe(Request.DEFAULT_LIMIT)
26+
expect(Object.keys(params).length).toBe(2)
27+
})
28+
})

yarn.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@
4747
lodash "^4.17.4"
4848
pify "^3.0.0"
4949

50-
"@types/core-js@^0.9.43":
51-
version "0.9.43"
52-
resolved "https://registry.yarnpkg.com/@types/core-js/-/core-js-0.9.43.tgz#65d646c5e8c0cd1bdee37065799f9d3d48748253"
53-
5450
"@types/debug@^0.0.30":
5551
version "0.0.30"
5652
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.30.tgz#dc1e40f7af3b9c815013a7860e6252f6352a84df"

0 commit comments

Comments
 (0)