inbox_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package teststore
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. storepb "github.com/usememos/memos/proto/gen/store"
  7. "github.com/usememos/memos/store"
  8. )
  9. func TestInboxStore(t *testing.T) {
  10. ctx := context.Background()
  11. ts := NewTestingStore(ctx, t)
  12. user, err := createTestingHostUser(ctx, ts)
  13. require.NoError(t, err)
  14. const systemBotID int32 = 0
  15. create := &store.Inbox{
  16. SenderID: systemBotID,
  17. ReceiverID: user.ID,
  18. Status: store.UNREAD,
  19. Message: &storepb.InboxMessage{
  20. Type: storepb.InboxMessage_MEMO_COMMENT,
  21. },
  22. }
  23. inbox, err := ts.CreateInbox(ctx, create)
  24. require.NoError(t, err)
  25. require.NotNil(t, inbox)
  26. require.Equal(t, create.Message, inbox.Message)
  27. inboxes, err := ts.ListInboxes(ctx, &store.FindInbox{
  28. ReceiverID: &user.ID,
  29. })
  30. require.NoError(t, err)
  31. require.Equal(t, 1, len(inboxes))
  32. require.Equal(t, inbox, inboxes[0])
  33. updatedInbox, err := ts.UpdateInbox(ctx, &store.UpdateInbox{
  34. ID: inbox.ID,
  35. Status: store.ARCHIVED,
  36. })
  37. require.NoError(t, err)
  38. require.NotNil(t, updatedInbox)
  39. require.Equal(t, store.ARCHIVED, updatedInbox.Status)
  40. err = ts.DeleteInbox(ctx, &store.DeleteInbox{
  41. ID: inbox.ID,
  42. })
  43. require.NoError(t, err)
  44. inboxes, err = ts.ListInboxes(ctx, &store.FindInbox{
  45. ReceiverID: &user.ID,
  46. })
  47. require.NoError(t, err)
  48. require.Equal(t, 0, len(inboxes))
  49. ts.Close()
  50. }