|
|
@@ -115,3 +115,23 @@ func TestApiKeyDataAccess(t *testing.T) {
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+func TestApiKeyErrors(t *testing.T) {
|
|
|
+ mockTimeNow()
|
|
|
+ defer resetTimeNow()
|
|
|
+
|
|
|
+ t.Run("Testing API Duplicate Key Errors", func(t *testing.T) {
|
|
|
+ InitTestDB(t)
|
|
|
+ t.Run("Given saved api key", func(t *testing.T) {
|
|
|
+ cmd := models.AddApiKeyCommand{OrgId: 0, Name: "duplicate", Key: "asd"}
|
|
|
+ err := AddApiKey(&cmd)
|
|
|
+ assert.Nil(t, err)
|
|
|
+
|
|
|
+ t.Run("Add API Key with existing Org ID and Name", func(t *testing.T) {
|
|
|
+ cmd := models.AddApiKeyCommand{OrgId: 0, Name: "duplicate", Key: "asd"}
|
|
|
+ err = AddApiKey(&cmd)
|
|
|
+ assert.EqualError(t, err, models.ErrDuplicateApiKey.Error())
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|