memos/test/store/inbox_test.go

54 lines
1.3 KiB
Go
Raw Normal View History

2023-10-27 03:17:58 +03:00
package teststore
import (
"context"
"testing"
"github.com/stretchr/testify/require"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
func TestInboxStore(t *testing.T) {
ctx := context.Background()
ts := NewTestingStore(ctx, t)
user, err := createTestingHostUser(ctx, ts)
require.NoError(t, err)
const systemBotID int32 = 0
create := &store.Inbox{
SenderID: systemBotID,
ReceiverID: user.ID,
Status: store.UNREAD,
Message: &storepb.InboxMessage{
2023-10-27 18:17:17 +03:00
Type: storepb.InboxMessage_TYPE_MEMO_COMMENT,
2023-10-27 03:17:58 +03:00
},
}
inbox, err := ts.CreateInbox(ctx, create)
require.NoError(t, err)
require.NotNil(t, inbox)
require.Equal(t, create.Message, inbox.Message)
2023-10-27 19:08:42 +03:00
inboxes, err := ts.ListInboxes(ctx, &store.FindInbox{
2023-10-27 03:17:58 +03:00
ReceiverID: &user.ID,
})
require.NoError(t, err)
require.Equal(t, 1, len(inboxes))
require.Equal(t, inbox, inboxes[0])
updatedInbox, err := ts.UpdateInbox(ctx, &store.UpdateInbox{
ID: inbox.ID,
2023-10-27 21:49:35 +03:00
Status: store.ARCHIVED,
2023-10-27 03:17:58 +03:00
})
require.NoError(t, err)
require.NotNil(t, updatedInbox)
2023-10-27 21:49:35 +03:00
require.Equal(t, store.ARCHIVED, updatedInbox.Status)
2023-10-27 03:17:58 +03:00
err = ts.DeleteInbox(ctx, &store.DeleteInbox{
ID: inbox.ID,
})
require.NoError(t, err)
2023-10-27 19:08:42 +03:00
inboxes, err = ts.ListInboxes(ctx, &store.FindInbox{
2023-10-27 03:17:58 +03:00
ReceiverID: &user.ID,
})
require.NoError(t, err)
require.Equal(t, 0, len(inboxes))
}