server: add unit tests

Make test coverage >= 90%

#1019 
@unihorn can you explain what you are going to do in the other PR, I am still confused