lamassu/lamassu-machine — pull request #42 by haxwell (2014-12-15 04:27:02+00:00)
Title: Canary replace literal strings with constant strings

So, I wanted to change to values in the STATIC_STATES array to constant values, and I needed to write a unit test to verify the change did not break any functionality. The first place that I saw STATIC_STATES used was in the Brain::run() method; a function passed to setInterval() will exit the lamassu-machine application if enough time passes while the Brain is in a state listed in STATIC_STATES. To test that functionality without also having to code testing language for the other methods called in Brain::run(), I needed to put the setInterval() related code in its own method.

I generalized the method, so that it checked for time passing while in a certain state, but didn't define what happened when a certain amount of time passed. Brain::run() now passes a function into this generalized method, which logs a message and exits, functionally the same as before the generalization. The test passes in a mock to be able to tell that its function is called after a certain amount of time passes.

Second, I created methods to set handlers on components like the Trader and BillValidator, etc. and tests to verify that the expected handlers have been set.

Finally, in refactoring the setInterval() functionality described above, it became apparent that overridden options were not always overriding previous values. So in configuration.js, I moved the merging of the overridden options to the last step, so they are always the last word on config options.

Formatting may not be 100%, but please let me know where its off, and I'll work on cleaning that up.