Fix jsDoc and refactor.
Add tests for invalidation endpoint.