TGIMBA TypeScript API Tuneup – Step 2 – Local Dynamo Db Integration Tests

Git Hub Code

In this post, I am going to continue with another TGIMBANodeJSAPI post.  If you remember last time, I had added unit tests for the SQL Server and AWS Dynamo Db methods.  In that post, I specified that this would be the first time I had explored testing from a functional programming perspective.  Not being able to mock led me to separate as many methods as I could from the Tedious (SQL Server) and AWS access libraries so I could test them in isolation.  My hope was to test the ‘logic’ of my code without having to figure out a way to mock within a functional programming paradigm.  Then, have integration tests that test my use of the Tedious and AWS libraries.

Well, having completed the first half of the integration tests, it mostly worked.  Let me explain.

First, I had to create a localhost dynamo db that I could run the integration tests against.  The entire process is provided by AWS (reference #2).  For clarity:

  • Download the .zip option

Screen Shot 2017-11-26 at 8.21.02 PM

  • Unzip

Screen Shot 2017-11-26 at 8.22.42 PM

  • Open terminal to this location

Screen Shot 2017-11-26 at 8.24.14 PM

  • Run this command (the -port is not required, but I did this since I have other things running on 8000 which is the default)

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -port 8634

Screen Shot 2017-11-26 at 8.25.59 PM

  • Test with the shell

Screen Shot 2017-11-26 at 8.27.15 PM

Second, I had some issues using the AWS client code, so I chose to wrap everything in promises to make sure required synchronous calls stayed synchronous.  This required me to drop the ‘processResults(args)’ method that I had used to test the method results.  The complicating factor was figuring out how to mock the promise resolve/reject call.  So, I chose to address the result testing with integration tests.  Given how new I am to functional programming, this seemed like a fair trade off 🙂

  • Unit tests running

Screen Shot 2017-11-26 at 9.12.27 PM

  • Dynamo Db Integration tests running

NOTE: Reference #2 led me to understand that the accessKeyId, secretAccesskey, region and endpoint are required…but the endpoint is the only thing that has to be real to reach the local dynamo db instance.

Screen Shot 2017-11-26 at 8.39.27 PM

Screen Shot 2017-11-26 at 9.12.58 PM

I am going to add another blog post with the error and endpoint integration tests (the current ones are against the core code modules (a service layer of sorts)) and then with the SQL Server integration tests next (ish).

Stay tuned!

Reference

  1. http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
  2. https://github.com/aws/aws-sdk-java/issues/330
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s