server: add unit tests

Make test coverage >= 90%

#1019 
can you add a test for prevExist = true and prevIndex = 1