webhook_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package teststore
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/usememos/memos/store"
  7. )
  8. func TestWebhookStore(t *testing.T) {
  9. ctx := context.Background()
  10. ts := NewTestingStore(ctx, t)
  11. user, err := createTestingHostUser(ctx, ts)
  12. require.NoError(t, err)
  13. webhook, err := ts.CreateWebhook(ctx, &store.Webhook{
  14. CreatorID: user.ID,
  15. Name: "test_webhook",
  16. URL: "https://example.com",
  17. })
  18. require.NoError(t, err)
  19. require.Equal(t, "test_webhook", webhook.Name)
  20. require.Equal(t, user.ID, webhook.CreatorID)
  21. webhooks, err := ts.ListWebhooks(ctx, &store.FindWebhook{
  22. CreatorID: &user.ID,
  23. })
  24. require.NoError(t, err)
  25. require.Equal(t, 1, len(webhooks))
  26. require.Equal(t, webhook, webhooks[0])
  27. newName := "test_webhook_new"
  28. updatedWebhook, err := ts.UpdateWebhook(ctx, &store.UpdateWebhook{
  29. ID: webhook.ID,
  30. Name: &newName,
  31. })
  32. require.NoError(t, err)
  33. require.Equal(t, newName, updatedWebhook.Name)
  34. require.Equal(t, webhook.CreatorID, updatedWebhook.CreatorID)
  35. err = ts.DeleteWebhook(ctx, &store.DeleteWebhook{
  36. ID: webhook.ID,
  37. })
  38. require.NoError(t, err)
  39. webhooks, err = ts.ListWebhooks(ctx, &store.FindWebhook{
  40. CreatorID: &user.ID,
  41. })
  42. require.NoError(t, err)
  43. require.Equal(t, 0, len(webhooks))
  44. ts.Close()
  45. }