fix issue where api key generated duplicate keys
add tests for ApiKey, ApiKeyRepository