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
- Open terminal to this location
- 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
- Test with the shell
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
- 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.
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).