memos/test/store/inbox_test.go

55 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{
2023-10-27 23:17:17 +08:00
Type: storepb.InboxMessage_TYPE_MEMO_COMMENT,
2023-10-27 08:17:58 +08:00
},
}
inbox, err := ts.CreateInbox(ctx, create)
require.NoError(t, err)
require.NotNil(t, inbox)
require.Equal(t, create.Message, inbox.Message)
2023-10-28 00:08:42 +08:00
inboxes, err := ts.ListInboxes(ctx, &store.FindInbox{
2023-10-27 08:17:58 +08: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-28 02:49:35 +08:00
Status: store.ARCHIVED,
2023-10-27 08:17:58 +08:00
})
require.NoError(t, err)
require.NotNil(t, updatedInbox)
2023-10-28 02:49:35 +08:00
require.Equal(t, store.ARCHIVED, updatedInbox.Status)
2023-10-27 08:17:58 +08:00
err = ts.DeleteInbox(ctx, &store.DeleteInbox{
ID: inbox.ID,
})
require.NoError(t, err)
2023-10-28 00:08:42 +08:00
inboxes, err = ts.ListInboxes(ctx, &store.FindInbox{
2023-10-27 08:17:58 +08:00
ReceiverID: &user.ID,
})
require.NoError(t, err)
require.Equal(t, 0, len(inboxes))
ts.Close()
2023-10-27 08:17:58 +08:00
}