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-27 08:36:43 +08:00
|
|
|
inboxes, err := ts.ListInbox(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,
|
|
|
|
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)
|
2023-10-27 08:36:43 +08:00
|
|
|
inboxes, err = ts.ListInbox(ctx, &store.FindInbox{
|
2023-10-27 08:17:58 +08:00
|
|
|
ReceiverID: &user.ID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 0, len(inboxes))
|
|
|
|
}
|