feat: implement AI schedule app with multi-device sync
- Qt 6 desktop client with day/month/year views, AI scheduling, and TOML settings\n- Go sync server with SQLite change stream, WebSocket notifications, and Docker deployment\n- Client outbox/LWW sync, offline retry, and dual-client integration tests\n- Linux fcitx5 setup, validation reports, and Windows MinGW preset
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/misaki/Schedule/server/internal/config"
|
||||
"github.com/misaki/Schedule/server/internal/model"
|
||||
"github.com/misaki/Schedule/server/internal/store"
|
||||
)
|
||||
|
||||
func testService(t *testing.T) *SyncService {
|
||||
t.Helper()
|
||||
st, err := store.Open(filepath.Join(t.TempDir(), "sync.db"))
|
||||
if err != nil {
|
||||
t.Fatalf("open store: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
return New(st, config.Config{MaxBatch: 100, TokenPepper: "pepper"})
|
||||
}
|
||||
|
||||
func TestRegisterAuthenticateAndPush(t *testing.T) {
|
||||
svc := testService(t)
|
||||
ctx := context.Background()
|
||||
device, token, latest, err := svc.RegisterDevice(ctx, "device-1", "Laptop")
|
||||
if err != nil {
|
||||
t.Fatalf("register: %v", err)
|
||||
}
|
||||
if device.ID != "device-1" || token == "" || latest != 0 {
|
||||
t.Fatalf("unexpected register result: %+v token=%q latest=%d", device, token, latest)
|
||||
}
|
||||
authenticated, err := svc.Authenticate(ctx, token)
|
||||
if err != nil || authenticated.ID != device.ID {
|
||||
t.Fatalf("authenticate: %+v %v", authenticated, err)
|
||||
}
|
||||
if _, err := svc.Authenticate(ctx, "wrong"); !errors.Is(err, ErrInvalidToken) {
|
||||
t.Fatalf("expected invalid token, got %v", err)
|
||||
}
|
||||
if _, err := svc.Push(ctx, device.ID, []model.ChangeInput{{EntityType: "task", EntityID: "x", Op: "upsert", UpdatedAt: "2026-10-26T10:00:00Z", Payload: json.RawMessage(`{"id":"x"}`)}}); err != nil {
|
||||
t.Fatalf("push: %v", err)
|
||||
}
|
||||
changes, latest, _, err := svc.Pull(ctx, 0, 10)
|
||||
if err != nil || len(changes) != 1 || latest != 1 {
|
||||
t.Fatalf("pull: changes=%d latest=%d err=%v", len(changes), latest, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user