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
Problem writing tests using mocha with vogels #219
Comments
Option 1: Also use the create tables action in every start of the application. Since they are already created it wouldn't do anything. Option 2: Option 3: |
Thank you very much for the alternatives. Can you elaborate on Option 3? I have timestamps enabled. How do I delete the newest records? |
At the beginning of the tests get the current time as integer like
Then run your tests where you put your createdAt timestamps (integer again). But if you are creating a REST API and you are testing the create and update methods why are you not testing the delete methods? The best options is after you create some items, keep track of their IDs and use the same IDs for the update and delete methods. |
I think I am missing something very fundamental. I tried creating deleting and creating table outside. It worked. The part under beforeEach(for deleting and recreating) is not working though it does not show any error. Here is the code that worked:
I tried doing the very same in mocha. it does not run or throw any error(I know this because none of the messages in console log are printed). I was under the impression that mocha should be able to run any js code as long as I require the necessary files. Here is my test file:
|
I have no clue but the vogels commands are not working properly in the test files when run using mocha. |
Yes, you are creating an API. In that case you should not put vogels commands in your tests. You are writting test for your API methods. And when you are deleting and items you should rely on your delete API method. Basically do not put vogels commands in your tests... |
Firstly, thank you helping me out so much! Can you please elaborate on that? I was a rails developer and I never had problems writing tests in this way. I am not able to understand what restricts us from using Vogels commands in test files. There is something strange about vogels commands in test files. Sometimes they work and sometimes they dont work. For instance, I have seen that get command works well but destroy command does not work. |
It is just the way that javascript and mocha works. Mocha executes a given API call, after that it validates the data, http status, content type, etc., and then terminates the execution of the test, without waiting of the vogels operations to finish. |
I have seen people writing the way I wrote using mongoose without any problems. For instance, the following worked without a problem. Here is the code https://pastebin.com/vjVXkE9C here is the tutorial. https://scotch.io/tutorials/test-a-node-restful-api-with-mocha-and-chai |
Did you spot that Also did that tutorial mentions if those tests are running async? If so you are risking to delete that table in the middle of other test. |
@set-killer - Thank you very much. i am able to destroy-create the table before every test now :). In the very first reply you mentioned "run a delete expression where createdAt > startTime." In all the delete expressions I see in the examples there is a necessity to mention the hashKey to delete(https://github.com/ryanfitz/vogels#deleting). How will I be able to delete all items where createdAt > startTime without mentioning the hashkey? |
Create query like this or a scan like this. OR Keep tracking of the IDs of the items that you create and insert and after that delete them. Just put them in some kind of array and after that delete them one by one. The batchDelete functionality is not yet implemented. Keep traking of issue #85. |
Given that there is no delete_all option, I am not able to empty the table when I write tests. How are you guys handling tests when you use dynamodb?
The text was updated successfully, but these errors were encountered: