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

Mock DocumentClient #1

Open
pjarts opened this issue Oct 12, 2017 · 3 comments
Open

Mock DocumentClient #1

pjarts opened this issue Oct 12, 2017 · 3 comments

Comments

@pjarts
Copy link

pjarts commented Oct 12, 2017

Is it possible to use this package to mock a DocumentClient instance?

@damonmaria
Copy link
Member

I use the dynamodb-local script in this package and run a real DocumentClient against that (as per the README) which is a more accurate test of the code. I find it performant enough even for unit tests.

I haven't tried mocking DocumentClient using mockService. I'm not sure if there would be issues with it because it's not a top level server like DynamoDB is. Have you tried and it doesn't work?

@pjarts
Copy link
Author

pjarts commented Oct 13, 2017

mockService(AWS.DynamoDB.DocumentClient, ['query'])

TypeError {
  message: 'Cannot read property \'undefined\' of undefined',
}

Testing agains a local DynamoDB might be a better choice. It would require a bit of setup with out deployment pipeline though as I assume it requires Java?

I found one workaround is to use the DynamoDB client instead of the DocumentClient and import the marshall and unmarshall methods from 'aws-sdk/lib/dynamodb/converter' to convert JS objects into DynamoDB objects and vice versa.

@damonmaria
Copy link
Member

I've done some more investigation on DocumnetClient and underneath it's not treated as an 'service' by AWS. Which makes sense, since it's basically a wrapper around DynamoDB. As such there isn't a service API to load which would validate the requests you make while testing. And therefore you're basically back to just a plain sinon.spy().

So while it would be nice, I don't think there's a way to achieve anything of value. And especially when you can test against a local DynamoDB instance. But yes, this does require Java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants