Skip to content

Commit

Permalink
Add tests for nextPage override.
Browse files Browse the repository at this point in the history
Fixes #711
  • Loading branch information
AdityaManohar committed Sep 29, 2015
1 parent ecf3184 commit 38c07f2
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/dynamodb/document_client.coffee
Expand Up @@ -581,3 +581,56 @@ describe 'AWS.DynamoDB.DocumentClient', ->
docClient.get {Key: foo: 1}, (err, data) ->
expect(data).to.eql(output)
done()

describe 'response.nextPage', ->

client = null; response = null; request = null

beforeEach ->
client = new AWS.DynamoDB.DocumentClient({paramValidation: false})
request = client.query({ExpressionAttributeValues: { foo: 'bar' }})
response = request.response

fill = (err, data) ->
request.emit('validate', [request])
response.error = err
response.data = data

it 'returns null if there are no more pages', ->
fill(null, {})
expect(response.nextPage()).to.equal(null)

it 'returns a request object with the next page marker filled in params', ->
fill(null, LastEvaluatedKey: { fizz: 'pop' })
req = response.nextPage()
expect(req.params.ExclusiveStartKey.fizz).to.equal('pop')
expect(req.operation).to.equal(response.request.operation)

it 'uses untranslated params', ->
fill(null, LastEvaluatedKey: 'baz')
req = response.nextPage()
expect(req.params.ExpressionAttributeValues.foo).to.equal('bar')

it 'throws error if response returned an error and there is no callback', ->
fill(new Error('error!'), null, true)
expect(-> response.nextPage()).to.throw('error!')

it 'sends the request if passed with a callback', (done) ->
helpers.mockHttpResponse 200, {}, ['']
fill(null, LastEvaluatedKey: 'baz')
response.nextPage (err, data) ->
expect(err).to.equal(null)
expect(data).to.eql({})
done()

it 'passes null to callback if there are no more pages', ->
fill(null, {})
response.nextPage (err, data) ->
expect(err).to.equal(null)
expect(data).to.equal(null)

it 'passes error through if original response returned an error', ->
fill('error!', null)
response.nextPage (err, data) ->
expect(err).to.equal('error!')
expect(data).to.equal(null)

0 comments on commit 38c07f2

Please sign in to comment.