webhook_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. RowStatus: store.Normal,
  18. })
  19. require.NoError(t, err)
  20. require.Equal(t, "test_webhook", webhook.Name)
  21. require.Equal(t, user.ID, webhook.CreatorID)
  22. webhooks, err := ts.ListWebhooks(ctx, &store.FindWebhook{
  23. CreatorID: &user.ID,
  24. })
  25. require.NoError(t, err)
  26. require.Equal(t, 1, len(webhooks))
  27. require.Equal(t, webhook, webhooks[0])
  28. newName := "test_webhook_new"
  29. updatedWebhook, err := ts.UpdateWebhook(ctx, &store.UpdateWebhook{
  30. ID: webhook.ID,
  31. Name: &newName,
  32. })
  33. require.NoError(t, err)
  34. require.Equal(t, newName, updatedWebhook.Name)
  35. require.Equal(t, webhook.CreatorID, updatedWebhook.CreatorID)
  36. err = ts.DeleteWebhook(ctx, &store.DeleteWebhook{
  37. ID: webhook.ID,
  38. })
  39. require.NoError(t, err)
  40. webhooks, err = ts.ListWebhooks(ctx, &store.FindWebhook{
  41. CreatorID: &user.ID,
  42. })
  43. require.NoError(t, err)
  44. require.Equal(t, 0, len(webhooks))
  45. ts.Close()
  46. }