fix: cassandra + mongo + arangodb issues with webhook
This commit is contained in:
@@ -24,7 +24,11 @@ func deleteWebhookTest(t *testing.T, s TestSetup) {
|
||||
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
|
||||
|
||||
// get all webhooks
|
||||
webhooks, err := db.Provider.ListWebhook(ctx, model.Pagination{})
|
||||
webhooks, err := db.Provider.ListWebhook(ctx, model.Pagination{
|
||||
Limit: 10,
|
||||
Page: 1,
|
||||
Offset: 0,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
for _, w := range webhooks.Webhooks {
|
||||
@@ -37,12 +41,17 @@ func deleteWebhookTest(t *testing.T, s TestSetup) {
|
||||
assert.NotEmpty(t, res.Message)
|
||||
}
|
||||
|
||||
webhooks, err = db.Provider.ListWebhook(ctx, model.Pagination{})
|
||||
webhooks, err = db.Provider.ListWebhook(ctx, model.Pagination{
|
||||
Limit: 10,
|
||||
Page: 1,
|
||||
Offset: 0,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, webhooks.Webhooks, 0)
|
||||
|
||||
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, model.Pagination{
|
||||
Limit: 10,
|
||||
Limit: 100,
|
||||
Page: 1,
|
||||
Offset: 0,
|
||||
}, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, webhookLogs.WebhookLogs, 0)
|
||||
|
@@ -2,8 +2,8 @@ package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db"
|
||||
@@ -13,31 +13,45 @@ import (
|
||||
|
||||
func TestResolvers(t *testing.T) {
|
||||
databases := map[string]string{
|
||||
constants.DbTypeSqlite: "../../data.db",
|
||||
// constants.DbTypeArangodb: "http://localhost:8529",
|
||||
// constants.DbTypeMongodb: "mongodb://localhost:27017",
|
||||
// constants.DbTypeCassandraDB: "127.0.0.1:9042",
|
||||
// constants.DbTypeSqlite: "../../data.db",
|
||||
// constants.DbTypeArangodb: "http://localhost:8529",
|
||||
// constants.DbTypeMongodb: "mongodb://localhost:27017",
|
||||
constants.DbTypeScyllaDB: "127.0.0.1:9042",
|
||||
}
|
||||
|
||||
testDb := "authorizer_test"
|
||||
s := testSetup()
|
||||
defer s.Server.Close()
|
||||
|
||||
for dbType, dbURL := range databases {
|
||||
s := testSetup()
|
||||
defer s.Server.Close()
|
||||
ctx := context.Background()
|
||||
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDatabaseURL, dbURL)
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDatabaseType, dbType)
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDatabaseName, testDb)
|
||||
os.Setenv(constants.EnvKeyDatabaseURL, dbURL)
|
||||
os.Setenv(constants.EnvKeyDatabaseType, dbType)
|
||||
os.Setenv(constants.EnvKeyDatabaseName, testDb)
|
||||
memorystore.InitRequiredEnv()
|
||||
|
||||
err := db.InitDB()
|
||||
if err != nil {
|
||||
t.Errorf("Error initializing database: %s", err)
|
||||
t.Errorf("Error initializing database: %s", err.Error())
|
||||
}
|
||||
|
||||
// clean the persisted config for test to use fresh config
|
||||
envData, err := db.Provider.GetEnv(ctx)
|
||||
if err == nil {
|
||||
envData.EnvData = ""
|
||||
db.Provider.UpdateEnv(ctx, envData)
|
||||
_, err = db.Provider.UpdateEnv(ctx, envData)
|
||||
if err != nil {
|
||||
t.Errorf("Error updating env: %s", err.Error())
|
||||
}
|
||||
}
|
||||
err = env.PersistEnv()
|
||||
if err != nil {
|
||||
t.Errorf("Error persisting env: %s", err.Error())
|
||||
}
|
||||
env.PersistEnv()
|
||||
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyEnv, "test")
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyIsProd, false)
|
||||
@@ -78,9 +92,8 @@ func TestResolvers(t *testing.T) {
|
||||
inviteUserTest(t, s)
|
||||
validateJwtTokenTest(t, s)
|
||||
|
||||
time.Sleep(5 * time.Second) // add sleep for webhooklogs to get generated as they are async
|
||||
webhookLogsTest(t, s) // get logs after above resolver tests are done
|
||||
deleteWebhookTest(t, s) // delete webhooks (admin resolver)
|
||||
webhookLogsTest(t, s) // get logs after above resolver tests are done
|
||||
deleteWebhookTest(t, s) // delete webhooks (admin resolver)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package test
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/crypto"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func webhookLogsTest(t *testing.T, s TestSetup) {
|
||||
time.Sleep(30 * time.Second) // add sleep for webhooklogs to get generated as they are async
|
||||
t.Helper()
|
||||
t.Run("should get webhook logs", func(t *testing.T) {
|
||||
req, ctx := createContext(s)
|
||||
@@ -23,23 +25,25 @@ func webhookLogsTest(t *testing.T, s TestSetup) {
|
||||
assert.NoError(t, err)
|
||||
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
|
||||
|
||||
webhooks, err := resolvers.WebhooksResolver(ctx, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, webhooks)
|
||||
|
||||
webhookLogs, err := resolvers.WebhookLogsResolver(ctx, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Greater(t, len(webhookLogs.WebhookLogs), 1)
|
||||
|
||||
webhooks, err := resolvers.WebhooksResolver(ctx, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, webhooks)
|
||||
|
||||
for _, w := range webhooks.Webhooks {
|
||||
webhookLogs, err := resolvers.WebhookLogsResolver(ctx, &model.ListWebhookLogRequest{
|
||||
WebhookID: &w.ID,
|
||||
t.Run(fmt.Sprintf("should get webhook for webhook_id:%s", w.ID), func(t *testing.T) {
|
||||
webhookLogs, err := resolvers.WebhookLogsResolver(ctx, &model.ListWebhookLogRequest{
|
||||
WebhookID: &w.ID,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, len(webhookLogs.WebhookLogs), 1)
|
||||
for _, wl := range webhookLogs.WebhookLogs {
|
||||
assert.Equal(t, utils.StringValue(wl.WebhookID), w.ID)
|
||||
}
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, len(webhookLogs.WebhookLogs), 1)
|
||||
for _, wl := range webhookLogs.WebhookLogs {
|
||||
assert.Equal(t, utils.StringValue(wl.WebhookID), w.ID)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user