46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package logic
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"spark-server/internal/infrastructure/id"
|
|
inboxmodel "spark-server/internal/module/inbox/model"
|
|
"spark-server/internal/module/sync/entity"
|
|
syncmodel "spark-server/internal/module/sync/model"
|
|
)
|
|
|
|
func TestSyncInboxIncremental(t *testing.T) {
|
|
ids, err := id.New(1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
inbox := inboxmodel.NewMemoryStore()
|
|
box := syncmodel.NewMemoryStore(ids)
|
|
svc := NewService(inbox, box)
|
|
ctx := t.Context()
|
|
if err := inbox.TouchUnread(ctx, 2, 9, 100); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := inbox.IncrUnread(ctx, 2, 9, 3); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := inbox.SetPreview(ctx, 9, []byte(`{"msg_id":100}`)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := svc.SyncInbox(ctx, entity.InboxRequest{UserID: 2, DeviceID: 7})
|
|
if err != nil || len(out.Dialogs) != 1 || out.Dialogs[0].Unread != 3 || out.DialogScore != 100 {
|
|
t.Fatalf("inbox %+v %v", out, err)
|
|
}
|
|
again, err := svc.SyncInbox(ctx, entity.InboxRequest{UserID: 2, DeviceID: 7, DialogScore: out.DialogScore, MailboxSeq: out.MailboxSeq})
|
|
if err != nil || len(again.Dialogs) != 0 {
|
|
t.Fatalf("no dialog delta %+v %v", again, err)
|
|
}
|
|
if err := box.Put(ctx, 2, entity.EventRecall, 9, []byte(`{"msg_id":100}`)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rec, err := svc.SyncInbox(ctx, entity.InboxRequest{UserID: 2, DeviceID: 7, DialogScore: out.DialogScore, MailboxSeq: out.MailboxSeq})
|
|
if err != nil || len(rec.Mailbox) != 1 || rec.Mailbox[0].EventType != entity.EventRecall {
|
|
t.Fatalf("mailbox %+v %v", rec, err)
|
|
}
|
|
}
|