2022-07-11 14:10:54 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
|
|
|
"github.com/authorizerdev/authorizer/server/crypto"
|
|
|
|
"github.com/authorizerdev/authorizer/server/db"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
|
|
|
"github.com/authorizerdev/authorizer/server/memorystore"
|
2022-07-15 16:41:08 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/refs"
|
2022-07-11 14:10:54 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func webhookTest(t *testing.T, s TestSetup) {
|
|
|
|
t.Helper()
|
|
|
|
t.Run("should get webhook", func(t *testing.T) {
|
|
|
|
req, ctx := createContext(s)
|
|
|
|
adminSecret, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
h, err := crypto.EncryptPassword(adminSecret)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
|
|
|
|
|
|
|
|
// get webhook by event name
|
2023-03-26 01:50:45 +00:00
|
|
|
webhooks, err := db.Provider.GetWebhookByEventName(ctx, constants.UserCreatedWebhookEvent)
|
2022-07-11 14:10:54 +00:00
|
|
|
assert.NoError(t, err)
|
2023-03-26 01:50:45 +00:00
|
|
|
assert.NotNil(t, webhooks)
|
2023-03-29 01:36:33 +00:00
|
|
|
assert.Equal(t, 2, len(webhooks))
|
2023-03-26 01:50:45 +00:00
|
|
|
for _, webhook := range webhooks {
|
|
|
|
res, err := resolvers.WebhookResolver(ctx, model.WebhookRequest{
|
|
|
|
ID: webhook.ID,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, res.ID, webhook.ID)
|
|
|
|
assert.Equal(t, refs.StringValue(res.Endpoint), refs.StringValue(webhook.Endpoint))
|
2023-03-29 01:36:33 +00:00
|
|
|
// assert.Equal(t, refs.StringValue(res.EventName), refs.StringValue(webhook.EventName))
|
2023-03-26 01:50:45 +00:00
|
|
|
assert.Equal(t, refs.BoolValue(res.Enabled), refs.BoolValue(webhook.Enabled))
|
|
|
|
assert.Len(t, res.Headers, len(webhook.Headers))
|
|
|
|
}
|
2022-07-11 14:10:54 +00:00
|
|
|
})
|
|
|
|
}
|