2023-11-24 22:45:38 +08:00
|
|
|
package teststore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/usememos/memos/store"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWebhookStore(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
ts := NewTestingStore(ctx, t)
|
|
|
|
user, err := createTestingHostUser(ctx, ts)
|
|
|
|
require.NoError(t, err)
|
2024-04-13 11:54:37 +08:00
|
|
|
webhook, err := ts.CreateWebhook(ctx, &store.Webhook{
|
|
|
|
CreatorID: user.ID,
|
2023-11-24 22:45:38 +08:00
|
|
|
Name: "test_webhook",
|
2024-04-13 12:11:59 +08:00
|
|
|
URL: "https://example.com",
|
2024-04-13 11:54:37 +08:00
|
|
|
RowStatus: store.Normal,
|
2023-11-24 22:45:38 +08:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "test_webhook", webhook.Name)
|
2024-04-13 11:54:37 +08:00
|
|
|
require.Equal(t, user.ID, webhook.CreatorID)
|
2023-11-24 22:45:38 +08:00
|
|
|
webhooks, err := ts.ListWebhooks(ctx, &store.FindWebhook{
|
|
|
|
CreatorID: &user.ID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(webhooks))
|
|
|
|
require.Equal(t, webhook, webhooks[0])
|
|
|
|
newName := "test_webhook_new"
|
|
|
|
updatedWebhook, err := ts.UpdateWebhook(ctx, &store.UpdateWebhook{
|
2024-04-13 11:54:37 +08:00
|
|
|
ID: webhook.ID,
|
2023-11-24 22:45:38 +08:00
|
|
|
Name: &newName,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, newName, updatedWebhook.Name)
|
2024-04-13 11:54:37 +08:00
|
|
|
require.Equal(t, webhook.CreatorID, updatedWebhook.CreatorID)
|
2023-11-24 22:45:38 +08:00
|
|
|
err = ts.DeleteWebhook(ctx, &store.DeleteWebhook{
|
2024-04-13 11:54:37 +08:00
|
|
|
ID: webhook.ID,
|
2023-11-24 22:45:38 +08:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
webhooks, err = ts.ListWebhooks(ctx, &store.FindWebhook{
|
|
|
|
CreatorID: &user.ID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 0, len(webhooks))
|
2024-01-16 13:51:26 +08:00
|
|
|
ts.Close()
|
2023-11-24 22:45:38 +08:00
|
|
|
}
|