memos/test/store/inbox_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

2023-10-27 08:17:58 +08: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{
Title: "title",
Content: "content",
Link: "link",
},
}
inbox, err := ts.CreateInbox(ctx, create)
require.NoError(t, err)
require.NotNil(t, inbox)
require.Equal(t, create.Message, inbox.Message)
inboxes, err := ts.ListInboxes(ctx, &store.FindInbox{
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,
Status: store.READ,
})
require.NoError(t, err)
require.NotNil(t, updatedInbox)
require.Equal(t, store.READ, updatedInbox.Status)
err = ts.DeleteInbox(ctx, &store.DeleteInbox{
ID: inbox.ID,
})
require.NoError(t, err)
inboxes, err = ts.ListInboxes(ctx, &store.FindInbox{
ReceiverID: &user.ID,
})
require.NoError(t, err)
require.Equal(t, 0, len(inboxes))
}