fhqvst / avanza

A JavaScript client for the unofficial Avanza API
MIT License
229 stars 59 forks source link

Unit test hangs #22

Closed ausrasul closed 5 years ago

ausrasul commented 6 years ago

When running npm test the test get stuck on testing avanza.subscribe.

I think this is because the test ran after the market was closed.

Can you explain how the tests works? do they put actual orders that risk being fulfilled?

Should one run the tests during a market session or after?

fhqvst commented 6 years ago

So most of the tests are simply connecting to and endpoint, and pass after a successful connection. The socket tests are (as you said) subscribing to price updates. They pass if a quote event is received (which never occurs if the market is closed).

Lastly, there is the "full flow" test, which places an order, fetches it, edits it, and then finally deletes it. Clearly this is somewhat dangerous as in order to successfully place the order we must make sure that the limit price is in 15% range of the average price (more details here), but on the other hand we must also price it so that the order does not get filled.

This is the reason as to why Travis currently only performs linting and does not run the tests.

ausrasul commented 6 years ago

Thanks for explaining.

May I suggest testing the API (this repo) after market hours? see my argument:

So, can we consider changing socket test as mentioned above, and strictly run the test after market close?

Here is another argument (testing from my application's perspective):

Therefore my tests should run on market hours, while API tests should run after hours.

What do you think?